I downloaded the source to the latest wx and managed to compile it without any issues.
Configured with:
../configure --enable-optimise --enable-stl --enable-unicode --enable-threads --enable-static --disable-shared --prefix=/usr/local
When I try to compile this example with:
g++-4.8 `wx-config --libs` `wx-config --cxxflags` test.cpp
I get alot of undefined refferences ( full list here )
How can I make this work?
When using static libraries, as you do (because of --disable-shared in configure command line), the libraries must come after the object file that references them (this is a general rule with all Unix-ish linkers and definitely with GNU ld). So the correct command line would be
g++-4.8 `wx-config --cxxflags` test.cpp `wx-config --libs`
or, just to keep it short, and because it does not matter where do the compilation flags appear:
g++-4.8 test.cpp `wx-config --cxxflags --libs`
You need to specify the wx libraries so the linker can resolve the references.
Related
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.
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?
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
I'm trying to write an autoconf test for a C++ library. I followed http://nerdland.net/2009/07/detecting-c-libraries-with-autotools/ . My check looks like this:
SAVED_LDFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS -lMyLib"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <mylibheader.hpp>],
[MyLibNamespace::SomeObject obj()])],
[TEST_LIBS="$TEST_LIBS -lMyLib"] [HAVE_MYLIB=1],
[AC_MSG_ERROR([libMyLib is not installed.])])
LDFLAGS=$SAVED_LDFLAGS
The test fails. If i check config.log the problem seems to be with the generated compilation command given by autoconf for the check:
g++ -o conftest -g -O2 -lMyLib conftest.cpp
As you can see, the -l params aren't at the end, after all inputs and outpus. If i copy&paste the conftest.cpp code from config.log i can make it compile with:
g++ -o conftest -g -O2 conftest.cpp -lMyLib
How can autoconf be wrong? How may i fix this?
The problem is that you're adding -lMyLib to LDFLAGS instead of adding to LIBS. In other words, do this instead:
SAVED_LIBS=$LIBS
LIBS="-lMyLib $LIBS"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <mylibheader.hpp>],
[MyLibNamespace::SomeObject obj()])],
[TEST_LIBS="$TEST_LIBS -lMyLib"] [HAVE_MYLIB=1],
[AC_MSG_ERROR([libMyLib is not installed.])])
LIBS=$SAVED_LIBS
Edit: link order of libraries is important, so I've updated the LIBS= line to link MyLib before the other libraries, if any, with the assumption that MyLib may depend on other libraries.
I am using Linux Mint 15 Olivia, and I installed the clang compiler and libclang-dev packages available in the repositories, they are version 3.2.
I am trying to compile and link the example from clang repository http://llvm.org/svn/llvm-project/cfe/tags/RELEASE_32/final/examples/clang-interpreter/main.cpp as you can see it's from clang version 3.2.
When I compiled it with the command:
$> clang++ `llvm-config --cflags` -c main.cpp
I got the file main.o which contains some undefined symbols to clang/llvm libraries. I made sure it contains the symbols by using the nm command:
$> nm main.o
A symbol from clang would be
_ZN5clang16CompilerInstanceC1Ev
Until now everything worked fine, until I tried to link the 'main.o' file with clang/llvm libraries. When I issue the command:
$> clang++ `llvm-config --ldflags` main.o `llvm-config --libs`
It fails with the following output (I just put the first error to not clutter this post):
main.o: In function `main':
main.cpp:74: undefined reference to `clang::TextDiagnosticPrinter::TextDiagnosticPrinter(llvm::raw_ostream&, clang::DiagnosticOptions*, bool)'
Basically I get a whole bunch of undefined references to clang libraries. I've tried researching on this and all I've found is that this has to do with the order you put the libraries flags on the command line. In addition to this, I also tried some other things:
I tried a bunch of compiler flags, changing the order in which the linker flags appear, they never worked.
I downloaded and compiled the LLVM and clang source code version 3.2, and 3.4, same result: compiling works, linking fails. It's worth mentioning to say that for each version reordering the linker flags always gave different link errors (this is of course due to the way the link searches for libraries).
I ran out of ideas, and already spent 2 hours trying to compile a simple example from clang's repository, any help would be appreciated.
Thank you
The answer is easy - llvm-config will not give you clang libraries. You need to link them separately. Check clang/tools/driver/Makefile as an example of a library list.
The answer to this problem is as Anton Korobeynik suggested, I was missing the clang libraries (which are not part of the llvm build as I was expecting from the command 'llvm-config --libs').
In the end the final command turned out to be:
clang++ `llvm-config --ldflags` main.o -lclangFrontendTool -lclangFrontend -lclangDriver -lclangSerialization -lclangCodeGen -lclangParse -lclangSema -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangAnalysis -lclangARCMigrate -lclangRewriteFrontend -lclangRewriteCore -lclangEdit -lclangAST -lclangLex -lclangBasic `llvm-config --libs`
If compiling any clang tool or example, make sure you check the Makefiles under clang/tools folder :)
This is a very basic question, I only post because I've spent already some time into it. This is what I've done so far:
Downloaded and compiled the boost library:
sudo ./bootstrap.sh and sudo ./bjam install
This way it was installed into /usr/local/lib.
In my source code I've added only:
#include <boost/asio.hpp>
using boost::asio::ip::tcp
I compile it with:
g++ -I/usr/lib/jvm/java-6-openjdk/include -L/usr/local/lib -fPIC -lboost_system -shared -o libagent.so agent.cpp
However, ldd -d ./libagent.so gives me:
libboost_system.so.1.46.1 => not found
But there is no error thrown, when using the -lboost_system and ls /usr/local/lib gets me among other things:
libboost_system.so
libboost_system.a
What am I missing?
Did the ./bjam install tool also run the ldconfig(8) tool? ldconfig(8) needs to be run after new libraries are installed to update the caches used by ld.so(8) at program execution time.
You should compile it with:
g++ -I/usr/lib/jvm/java-6-openjdk/include -L/usr/local/lib -Wl,-rpath,/usr/local/lib -fPIC -lboost_system -shared -o libagent.so agent.cpp
This makes it look for the boost library in /usr/local/lib at runtime, the -L option only makes it look in /usr/local/lib at compile time.
I have a C-code which I have not managed to run
http://dl.getdropbox.com/u/175564/problem-sdl.png
The problem is in OpenGL or SDL.
I do not have SDL.h at /usr/local/SDL/SDL.h, so gcc cannot find it.
I have SDL.h installed by MacPorts at /opt/local/include/SDL/SDL.h.
I tried to copy it to /Masi/local/SDL/SDL.h unsuccessfully at the folder by
cp /opt/local/include/SDL/SDL.h /
and by
cp /opt/local/include/SDL/SDL.h /Masi/local/SDL/
I tried to solve the problem by creationg a symlink by
$ln -s /opt/local/include/SDL/SDL.h /Masi/local/SDL/SDL.h
the simplest way to get all the compiler flags for SDL is by using sdl-config:
gcc sdl_gl_1.c $(sdl-config --cflags --libs) -lGL -lGLU
No, Ubuntu does not have them by default (at least the development versions). For my own little program I just installed libsdl1.2-dev and mesa-common-dev (OpenGL).
For the build process I use scons which produces the following commands:
gcc -o src/geom.o -c -Wall -ansi src/geom.c
gcc -o src/main.o -c -Wall -ansi src/main.c
gcc -o test src/main.o src/geom.o -lSDL -lGL
If you install the libraries in some non-standard location, you might have to specify your own include (-I) and library (-L) paths.