2

I am trying to compile an FLTK program (http://www.fltk.org/index.php) on Mac OSX Mavericks. All the .h packages compile just fine, but I receive the following error:

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I tried both g++ and clang++ -stdlib=libstdc++ to compile the program, but received the same error both times.

I would greatly appreciate any input on this issue to eliminate this error message.

warship
  • 2,924
  • 6
  • 39
  • 65
  • How did you invoke the compiler? What switches/parameters? – Mark Setchell Nov 03 '14 at 23:22
  • @Mark Setchell `g++ /path/to/file.cxx -I/path/to/fltk-1.3.2` and also tried `clang++ -stdlib=libstdc++ /path/to/file.cxx -I/path/to/fltk-1.3.2` both of which gave the same error. I used the -I flag as shown here under the "Compiling programs with standard compilers" section: http://www.fltk.org/doc-1.1/basics.html – warship Nov 03 '14 at 23:25
  • 2
    Try adding this `$(fltk-config --ldflags)` – Mark Setchell Nov 03 '14 at 23:32
  • You can remove the `$()` and run that stand-alone to see what it gives for linker flags too. – Mark Setchell Nov 03 '14 at 23:36
  • @MarkSetchell This may work, but I get: `-bash: fltk-config: command not found`. Any suggestions? – warship Nov 03 '14 at 23:53
  • You need to either add the directory containing the program `fltk-config` to the end of your PATH, or type in the full path to wherever you have installed it - so, something like `/usr/local/bin/fltk/fltk-1.3.2/fltk-config --ldflags` - then it will work. – Mark Setchell Nov 04 '14 at 07:36
  • If you really can't find `fltk-config` this command should find it for you though it will take quite a long time `find / -name "fltk-config" 2> /dev/null` – Mark Setchell Nov 04 '14 at 07:38
  • @MarkSetchell I downloaded the latest stable version of FLTK from their website, and in the folder I have a Unix executable file called `fltk-config.in` and a document file called `fltk-config.cmake.in`, you are referring to the first one of course, right? – warship Nov 04 '14 at 18:17
  • @MarkSetchell I also received the error `clang: error: unsupported option '--ldflags'` – warship Nov 04 '14 at 18:21
  • Have you read the `README.OSX.txt` and followed the instructions in the for XCode 4 and above? – Mark Setchell Nov 04 '14 at 19:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/64265/discussion-between-white-rabbit-and-mark-setchell). – warship Nov 04 '14 at 19:42
  • Did you see a message like this when you installed FLTK? /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /usr/local/lib/libfltk.a(utf8Wrap.o) has no symbols – Adam Mendoza Oct 02 '16 at 04:05

2 Answers2

3

You want to use the fltk-config script but it isn't clear how to use it generally form their documentation. This is a general form that I use and what it is actually doing:

From the command line you can compile like this (this assumes you need the image libraries, opengl libraries and wish to link statically [half the point of FLTK])

g++ file1.cpp file2.cpp `fltk-config --use-forms --use-gl --use-images --ldstaticflags --cxxflags` -o output

This is equivalent to

g++ file1.cpp file2.cpp -I/usr/local/include -I/usr/local/include/FL/images -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT /usr/local/lib/libfltk_images.a /usr/local/lib/libfltk_png.a -lz /usr/local/lib/libfltk_jpeg.a /usr/local/lib/libfltk_gl.a -framework AGL -framework OpenGL -framework ApplicationServices /usr/local/lib/libfltk_forms.a /usr/local/lib/libfltk.a -lpthread -framework Cocoa -o output

So if you make sure the libraries are in /usr/local/lib and the headers in /usr/local/include that should work...

fltk-config is just a script that comes in the fltk-1.3.2 (or whatever) folder. Building FLTK from the make file should add that to your path. If not copy it or direct it to wherever it is. It does make me wonder though: have you definitely built the libraries?

user3353819
  • 911
  • 2
  • 8
  • 21
  • What do I do to get the `-bash: fltk-config: command not found` working properly? The command that I'm using is `g++ /path/to/file.cxx -I/path/to/fltk-1.3.2 $(fltk-config --ldflags)` – warship Nov 04 '14 at 00:39
  • First thing: have you definitely run `make all` etc. etc. and built the libraries? – user3353819 Nov 04 '14 at 11:07
  • If so, `fltk-config` should be in `/usr/local/bin`, the FL/ and GL/ directories in `usr/local/include` and you should have libraries like `fltk.a` in `usr/local/lib`. IF not something has gone wrong with your build. Don't try to use the compiler link facility to reach fltk-config. Either copy it to your pwd or copy it to your path (or /usr/local/bin). – user3353819 Nov 04 '14 at 11:14
  • By using Mark Setchell's advice of `find / -name "fltk-config" 2> /dev/null` I came up with nothing, but when I do `find / -name "fltk-config.in" 2> /dev/null` I come up with the place where to find fltk-config.in, which is a Unix executable file. Then when I type: `g++ /path/to/fltk-1.3.3/file.cxx -I /path/to/fltk-1.3.3 /path/to/fltk-1.3.3/fltk-config.in --ldflags` I get the error `clang: error: unsupported option '--ldflags'` – warship Nov 04 '14 at 18:29
  • Please read what I am asking and answer. I am 90% sure you haven't built FLTK. You cannot just download FLTK and 'run it'. You download source code and then compile them into libraries which you link to. I suspect you haven't compiled it and that is why you have a link error. I think this is the case because fltk-config is generated when you build the libraries and you don't have it. You need to go to `fltk-1.3.2` type `./configure --enable-threads` with any other options you need (See documentation) then `sudo make install` – user3353819 Nov 05 '14 at 01:15
  • Even just look in `fltk-1.3.2/lib`. Is there anything in there other than a README? If not you haven't built FLTK. This should help http://www.fltk.org/doc-1.3/fltk.pdf – user3353819 Nov 05 '14 at 01:17
0

This is what worked for me:

#!/bin/bash
rm ./a.out
clang++ main.cpp -o a.out -std=c++17 -stdlib=libc++ \
                            -I/usr/include/fltk-1.3.8/FL \
                            -L/usr/local/lib \
                            $(fltk-config --ldflags) \
                            && ./a.out

shariqmaws
  • 8,152
  • 1
  • 16
  • 35