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.

13
  • How did you invoke the compiler? What switches/parameters? Commented Nov 3, 2014 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: fltk.org/doc-1.1/basics.html Commented Nov 3, 2014 at 23:25
  • 2
    Try adding this $(fltk-config --ldflags) Commented Nov 3, 2014 at 23:32
  • You can remove the $() and run that stand-alone to see what it gives for linker flags too. Commented Nov 3, 2014 at 23:36
  • @MarkSetchell This may work, but I get: -bash: fltk-config: command not found. Any suggestions? Commented Nov 3, 2014 at 23:53

3 Answers 3

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?

Sign up to request clarification or add additional context in comments.

6 Comments

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)
First thing: have you definitely run make all etc. etc. and built the libraries?
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).
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'
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
|
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 

Comments

0
  • Run:
brew install fltk 
  • To compile your file, type:
fltk-config --compile ./example_file.cpp 
  • Replace example_file.cpp with the file name you have.
  • To Run the executable generated, type:
./example_file 
  • Replace example_file with the file name you have.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.