linking clang lib allways undefined symbol - c++

I have created an some classes I want to use with swig in order to generate ruby binding.
Everything is ok when I generate the code or compile the ruby module. But when a script load this module, there is an error:
undefined symbol: _ZTVN5clang5LexerE
I understand that this means that the problem is for the clang::Lexer. But I know I have
set the lclangLex lib for this.
here is the command I use in order to link the objects files:
clang++ -shared -o parser.so parser.o Declarations.o -L. -L/usr/lib -L. -Wl,-O1,\
--sort-common,--as-needed,-z,relro -fstack-protector -rdynamic -Wl,-export-dynamic \
-L/usr/lib -lz -lpthread -lffi -lcurses -ldl -lm -lruby -lclangLex -lclangAST \
-lpthread -lgmp -ldl -lcrypt -lm -lc -lLLVMCppBackendCodeGen -lLLVMCppBackendInfo \
-lLLVMTarget -lLLVMCore -lLLVMMC -lLLVMObject -lLLVMSupport
any idea ?

The problem was the order of the libs given to the linker:
-lclangAST -lclangLex -lclangBasic
lclangAST must be given before lclangLex then I just had to add lclangBasic and everything works.

Related

Build error: cannot find libxml2

I am trying to build 32bit application on 64bit Debian 7 and something goes wrong:
/usr/bin/ld: cannot find -lxml2
locate~
/usr/lib/x86_64-linux-gnu/libxml2.a
/usr/lib/x86_64-linux-gnu/libxml2.so
/usr/lib/x86_64-linux-gnu/libxml2.so.2
/usr/lib/x86_64-linux-gnu/libxml2.so.2.8.0
Makefile:
CFLAGS=-I. -I/usr/include/libxml2 -I/usr/include/lua50 -I/usr/local/include
LIBLINK=-L/usr/lib64 -lxml2 -lz -lpthread -lm -llualib50 -llua50 -ldl -lboost_thread -lmysqlclient -Wl,-Map=otserv.map
ENDFLAGS=-m32 -Winvalid-pch -O2 -include "preheaders.h"

FLTK - Can't find headers even if I include the correct directory [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 5 years ago.
I am trying to compile a FLTK project from linux, using the output of the commands:
fltk-config --use-gl --use-images --ldflags
And:
fltk-config --use-gl --use-images --cxxflags
I am using this makefile to compile the project:
I installed the latest FLTK version by just downloading it from fltk.org, and then I compiled and installed it. I also installed X11 and OpenGL. But I still get these errors:
I checked the file system and these headers are in /usr/local/include/FL even if they are not recognized, although I included the directory (-I/usr/local/include) and then in the .cpp and .h files:
#include <FL/Fl_PNG_Image.H>
#include <FL/Fl_Box.H>
etc...
What could be the problem? do I need to install more libraries?
EDIT
I tried to change the makefile:
CXXFLAGS=-I/usr/local/include -I/usr/local/include/FL/images -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -I/home/ramy/boost_1_63_0 -std=c++11
LDFLAGS=-L/usr/local/lib -lfltk_images -lfltk_png -lz -lfltk_jpeg -lfltk_gl -lGLU -lGL -lfltk -lXrender -lXcursor -lXfixes -lXext -lXinerama -lpthread -ldl -lm -lX11 -L/home/ramy/boost_1_63_0/lib
SOURCES=Car.cpp Map.cpp CarState.cpp Utilities.cpp CarCollection.cpp TableView.cpp MapView.cpp
OBJECTS=Car.o Map.o CarState.o Utilities.o CarCollection.o TableView.o MapView.o
make:
g++ $(LDFLAGS) $(CXXFLAGS) -c $(SOURCES)
g++ $(LDFLAGS) $(CXXFLAGS) -o ../Evolution table-example.cpp $(OBJECTS)
clean:
rm -f $(OBJECTS) ../Evolution
But I still get the same errors.
Those errors don't mean that you are lacking headers, but libraries.
Here you can read the basis (go down to "Compiling Programs with Standard Compilers").
Basically add -L/usr/local/lib -lfltk -lXext -lX11 -lm to your app compiler command; or use fltk-config --cxxflags.

Linker error: Multiple definitions of 'ff_log2_tab'

I am trying to build a shared library that links a static version of libav into it. I build the library with --enable-pic to make sure its usable for me. But upon linking with the following command:
g++ -shared -o libbrake.so -L./ -L./libs -Wl,-z,defs -Wl,--whole-archive -Wl,-Bsymbolic -lavcodec -lavfilter -lavformat -lavresample -lavutil -lswscale -lbluray -ldvdnav -ldvdread -lhandbrake -lvpx -ldl -lm -lpthread -lx264 -ltheoraenc -lvorbis -ljansson -la52 -lass -lbz2 -lz -lxml2 -lopus -lmp3lame -logg -lsamplerate -lfontconfig -ldca -lharfbuzz
The needed static libs of libav are in the ./libs directory as .a archives.
Upon linking I get the error:
./libs/libavformat.a(log2_tab.o):(.rodata+0x0): multiple definition of `ff_log2_tab'
Is there any way to resolve this?
Ive done it now this way: with ar d i delete the multiple object file. but i think this is pretty "dirty"
– Nidhoegger

Error compiling with Opencv

I'm trying to compile a program in C++ which uses OpenCV 2.4.10
But during compilation time it can't find the Imf symbol, and gives out a list of errors like
/usr/lib//libopencv_highgui.a(grfmt_exr.o): In function cv::ExrDecoder::readHeader()':
(.text._ZN2cv10ExrDecoder10readHeaderEv+0x12): undefined reference toImf::globalThreadCount()'
I'm compiling with
g++ -L/usr/local/lib/ -L/usr/lib/ -L/usr/lib/x86_64-linux-gnu/ -static -o "find_box_layout" ./src/find_box_layout.o -lopencv_imgproc -lopencv_highgui -lopencv_core -lm -ljasper -ljpeg -ltiff -lpng -lz -lpthread -lrt
Any help with this?

Proper Way to Link with clang++ and scons

I'm trying to adapt an existing scons build system to use clang++ instead of g++. When using -O0 or -O2 -- neither of which output llvm IR -- things work swimmingly, that is to say, the build complete without errors. When using -O4, which compiles to llvm bytecode to allow link-time-optimization, the build fails on the final link.
I've searched various places, but I am unclear on exactly how to fix this, either directly on the command line or, knowing that in my SConstruct file.
Note: Setting env['LINK'] = "/path/to/llvm-link" causes all of my dependency checks to fail.
Note: Adding -Xlinker "-plugin" -Xlinker "/usr/lib/LLVMgold.so" to the command works well. So, the question is how to add this conditioned upon the choice of clang in SConstruct.
$ /usr/sbin/distcc clang++ -o build/release/filex.o -c -std=c++11 -march=core-avx-i -W -Wall -O4 \
-DHAVE_LLVM=0x0303 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS \
-D__STDC_LIMIT_MACROS -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_CONFIG_H -D_X11 \
-DFIFODIR='"/var/run/dir"' -I. -Isrc -I/usr/include -I/usr/include/SDL src/filex.cpp
...
$ ar rc build/release/libfile2.a build/release/filea.o build/release/tools/fileb.o
$ ranlib build/release/libfile2.a
...
$ /usr/sbin/distcc clang++ -o mybinary -pthread build/release/file1.o \
build/release/libfile2.a ... -L/usr/lib -lLLVMBitWriter -lLLVMX86Disassembler \
-lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMMCParser \
-lLLVMX86Desc -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMJIT \
-lLLVMRuntimeDyld -lLLVMExecutionEngine -lLLVMCodeGen -lLLVMObjCARCOpts -lLLVMScalarOpts \
-lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMTarget -lLLVMMC \
-lLLVMObject -lLLVMCore -lLLVMSupport -lz -lffi -ldl -lm -lboost_iostreams -lSDL \
-lSDL_net -lpthread -lboost_system -lpangocairo-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 \
-lcairo -lfontconfig -lfreetype -lboost_program_options -lboost_regex -lSDL_ttf \
-lSDL_mixer -lvorbisfile -lSDL_image -lX11
/usr/sbin/ld.gold: error: build/release/file1.o:1:3: invalid character
/usr/sbin/ld.gold: error: build/release/file1.o:1:3: syntax error, unexpected $end
/usr/sbin/ld.gold: error: build/release/flie1.o: not an object or archive
The key is to append -Wl,-plugin,/path/to/LLVMgold.so to LINKFLAGS rather than the -Xlinker... syntax.