0

I'm trying to learn FLTK for C++ and I'm working on a Macbook with the clang++ compiler. Whenever I try to link the library like this:

clang++ -L/usr/local/lib -lfltk

It gives me this error:

 clang: warning: argument unused during compilation: '-X11'
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've looked on a couple other forums to see how to fix this problem and haven't gotten any answers that worked. I also tried reinstalling Command Line Tools from Apple's Developer site.

DejanLekic
  • 18,787
  • 4
  • 46
  • 77
blockaj
  • 329
  • 4
  • 13
  • You don't link libraries just like that, in themselves (it doesn't make sense). You link them **to a program.** The thing that has `main()`, you know. –  Jan 11 '14 at 20:38
  • @H2CO3 Oh. Thanks. But how do I link them to a specific program? I'm 'cd'ed into the directory where my project is. – blockaj Jan 11 '14 at 20:40
  • Check output of the command: file . It seems the fltk library compiled for x86 platforms instead of x86_64. – vershov Jan 11 '14 at 20:42
  • I don't think it has a dylib file. Just a .a. I already checked the .a file using lipo -info instead of file and it says 'Non-fat file: /usr/local/lib/libfltk.a is architecture: x86_64' – blockaj Jan 11 '14 at 20:45
  • @blockaj I have tried to compile tabs-simple.cxx file from fltk package - all is OK. The compilation command is `g++ tabs-simple.cxx -I/usr/local/include/ -L/usr/local/lib -lfltk`, fltk was installed invoking `sudo port install fltk-devel` Could you please provide your source code for checking? – vershov Jan 11 '14 at 21:56
  • @vershov you link like this: `cc file1.cpp file2.cpp (etc.) -lLibraryOne -lLibraryTwo -o executable` –  Jan 11 '14 at 22:05
  • @H2CO3 Oh, I see what was wrong, tnx :-) – vershov Jan 11 '14 at 22:07

1 Answers1

0

You have to make sure you put the linker command (-L/usr/local/lib -lfltk) before doing filename.cpp -o Exectuable but still in the same line in the command line.

blockaj
  • 329
  • 4
  • 13