Linker error: Multiple definitions of 'ff_log2_tab' - c++

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

Related

C++ Shared library gives floating point exception when linked with C application

Background:
A C++ library for etcd client having APIs to communicate with etcd server, to use this library in C application, we wrote C++ wrappers over this library so that it can be called by C application.
Created a shared library using the below command:
g++-7 -ggdb -fPIC -shared -o libetcd_c++.so etcd_client_wrapper.cc etcd_client_txn_wrapper.cc etcd_client.cc etcd_client_txn.cc utils/string.cc pb/*.cc -std=c++1z -I ./pb/etcd -rdynamic -Wl,-call_shared -lglog -lprotobuf -lgrpc++ -lgrpc -Wl,-call_shared -lpthread -ldl -lc
placed this library to default library path /usr/local/lib and load the library with sudo ldconfig.
Now using this etcd_c++ library APIs, wrote a C code to insert simple key-value to etcd keyspace. Compiled using below command:
gcc -ggdb -o cwrap sample_wrapper.c -rdynamic -pthread -static-libstdc++ -Wl,-non_shared -lglog -lprotobuf -pthread -lz -lgrpc++ -lprotobuf -lgrpc -lz -lcares -lssl -lcrypto -lunwind -llzma -lgflags -Wl,-call_shared -lpthread -ldl -letcd_c++ -lstdc++
The compilation goes fine. But while executing the resulted binary, it gives floating point exception in grpc++ library.
Questions:
What floating point exception has to do with the library?
We thought it might be an issue with C to C++ transition, but when converted the same C code to C++ with same wrapper API. Gives the floating point exception.Now If we replace the wrapper API with direct grpc++ library API, in the C++ code, it works fine. Is it a linking issue?
Compiling a C++ application:
g++-7 -ggdb -o wrap example.cc -std=c++1z -rdynamic -pthread -static-libstdc++ -Wl,-non_shared -lglog -lprotobuf -pthread -lz -lgrpc++ -lprotobuf -lgrpc -lz -lcares -lssl -lcrypto -lunwind -llzma -lgflags -Wl,-call_shared -lpthread -ldl -letcd_c++
EDIT: Some findings, https://bugs.launchpad.net/ubuntu/+source/grpc/+bug/1797000
Though We are not using -Wl,-Bsymbolic-functions option, but the issue is somewhat similar to above.

An compiling error I met when I use ffmpeg to develop

I use this command to compile the file:
g++ rec.cpp -o rec -I /usr/local/include -L /usr/local/lib -lavformat -lavcodec -lavutil -lavdevice -lswscale -lasound -ldl -pthread -lz -lbz2 -lswresample -llzma -lva -lX11
After excute it I got the error:
/usr/bin/ld: /usr/local/lib/libavdevice.a(xcbgrab.o): undefined reference to symbol 'xcb_setup_pixmap_formats_length'//usr/lib/x86_64-linux-gnu/libxcb.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
How could I cope with this issue?
I found a way to deal with my issue. Since it's definitely a library problem so you can check how many libraries you need before compiling. For example:
pkg-config --libs libavcodec libavformat libswscale libavutil libavdevice
Then it'll tell you:
-L/usr/local/lib -lavdevice -lm -lxcb -lxcb-shm -lxcb -lxcb-shape -lxcb -lxcb-xfixes -lxcb-render -lxcb-shape -lxcb -lasound -lavfilter -pthread -lm -lva -ldl -lswscale -lm -lavformat -lm -lbz2 -lz -lavcodec -pthread -lm -llzma -lz -lva -ldl -lswresample -lm -lavutil -pthread -lva -lva-drm -lva -lva-x11 -lX11 -lm -lva -ldl
These libraries are what you need when you compile and then it's done.
You may also need pkg-config --cflags libavcodec libavformat libswscale libavutil libavdevice to add you CFLAGS or CXXFLAGS.

g++ finds -lXext but MinGW cannot find it with error: i586-mingw32msvc/bin/ld: cannot find -lXext

I can build a Linux executable with g++ like below without any problem:
g++ -I/usr/local/include -I/usr/local/include/FL/images -I/usr/include/freetype2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_THREAD_SAFE -D_REENTRANT -o '2016_02_06a_1st_Window' '2016_02_06a_1st_Window.cxx' /usr/local/lib/libfltk.a -lXext -lXft -lfontconfig -lpthread -ldl -lm -lX11
But When I try to build a MS Windows executable with MinGW like below and error happens:
i586-mingw32msvc-g++ -I/usr/local/include -I/usr/local/include/FL/images -I/usr/include/freetype2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_THREAD_SAFE -D_REENTRANT 2016_02_06a_1st_Window.cxx -L/usr/local/lib -lfltk -lXext -lXft -lfontconfig -lpthread -ldl -lm -lX11 -o 2016_02_06a_1st_Window.exe
The error of MinGW is:
Compiling and linking..
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/../../../../i586-mingw32msvc/bin/ld: cannot find -lXext
collect2: ld returned 1 exit status
I have installed all kinds of Xext libraries like these:
I have the following Xext libraries on my machine:
user#computer:~$ locate *Xext*
/usr/include/X11/extensions/Xext.h
/usr/lib/i386-linux-gnu/libXext.a
/usr/lib/i386-linux-gnu/libXext.so
/usr/lib/i386-linux-gnu/libXext.so.6
/usr/lib/i386-linux-gnu/libXext.so.6.4.0
I feel like g++ knows where Xext libraries are, but MinGW doesn't know. Any idea would be helpful.
you are running a cross compiler, which host is linux and target is windows, so when you link your target binaries, you should have target libraries. in your case, you should have libX for windows, and you listed are linux libraries, that's why your cross compiler cannot find libraries to link.

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?

linking clang lib allways undefined symbol

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.