ld cannot find `-lnsl` - linux

I am trying to compile a project that links the nsl lib but it seems to fail to link the library:
/bin/sh ../../libtool --tag=CXX --mode=link g++ -DNDEBUG -std=c++11 -L/usr/lib -R/usr/lib -L../../lib -all-static -lnsl -o Client client.o nettools.o -lgmm -lboost_program_options
libtool: link: g++ -DNDEBUG -std=c++11 -static -o Client client.o nettools.o -L/usr/lib -L../../lib -lnsl -lgmm -lboost_program_options -Wl,-rpath -Wl,/usr/lib
/bin/sh ../../libtool --tag=CXX --mode=link g++ -DNDEBUG -std=c++11 -L/usr/lib -R/usr/lib -L../../lib -all-static -lnsl -o Serveur serveur.o nettools.o -lgmm -lboost_program_options
/bin/ld: cannot find -lnsl
nettools.o: In function `creatSocketCom(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int)':
nettools.cc:(.text+0x30e): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status
Makefile:426: recipe for target 'Client' failed
make[2]: *** [Client] Error 1
make[2]: *** Waiting for unfinished jobs....
libtool: link: g++ -DNDEBUG -std=c++11 -static -o Serveur serveur.o nettools.o -L/usr/lib -L../../lib -lnsl -lgmm -lboost_program_options -Wl,-rpath -Wl,/usr/lib
/bin/ld: cannot find -lnsl
nettools.o: In function `creatSocketCom(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int)':
nettools.cc:(.text+0x30e): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status
I know this library doesn't need to be linked on Mac OS X but I'm running Arch Linux.
I have 2 questions:
Why does nsl fail to be linked even though λ ld --verbose -lnsl seems to show it's there?
attempt to open /usr/x86_64-unknown-linux-gnu/lib64/libnsl.so failed
attempt to open /usr/x86_64-unknown-linux-gnu/lib64/libnsl.a failed
attempt to open /usr/lib/libnsl.so succeeded
-lnsl (/usr/lib/libnsl.so)
libc.so.6 needed by /usr/lib/libnsl.so
found libc.so.6 at /usr/lib/libc.so.6
ld-linux-x86-64.so.2 needed by /usr/lib/libc.so.6
found ld-linux-x86-64.so.2 at /usr/lib/ld-linux-x86-64.so.2
ld: warning: cannot find entry symbol _start; not setting start address
What's the purest way to tell autoconf not to link nsl on systems where it's not needed?

The problem was with the -all-static option in the Makefile.am.
Arch Linux doesn't ship the static libraries (while debian's current stable release does).

Related

Use only local library with cross compiler

I'm trying to build one application with cross compiler on linux. Application is based on OpenEmbedded project. Compiler and all cross compiled libraries are located in build folder. But for one package build script is trying to use a library from my linux environment.
Command which is called from make script at the end:
/bin/sh ./arm-ABC-linux-gnueabi-libtool --tag=CXX --mode=link
arm-ABC-linux-gnueabi-g++ -march=armv7-a -mtune=cortex-a8
-mfpu=neon -mfloat-abi=softfp -g --std=c++0x -pthread -L/home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/opt/my/lib
-Wl,-rpath-link,/home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/opt/my/lib
-Wl,-O1 -Wl,--hash-style=gnu -L/opt/my/lib -o modbus_server_test modbus_server_test.o Serial.o SerialUtil.o Crc.o RtuFramer.o Pdu.o
SerialMaster.o
/home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/usr/local/apr/lib/libapr-2.la
-lcrypt -luuid -lrt -lcrypt -lpthread -ldl -lexpat -lstdc++
Most important from here that is use -lexpat flag for libexpat.so.1.5.2 library. This library is cross compiled and located in the build folder, and at the same time, we have one in my linux environment.
As result I recieve the next error:
| arm-ABC-linux-gnueabi-libtool: link:
arm-ABC-linux-gnueabi-g++ -march=armv7-a -mtune=cortex-a8
-mfpu=neon -mfloat-abi=softfp -g --std=c++0x -pthread -Wl,-rpath-link -Wl,/home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/opt/my/lib
-Wl,-O1 -Wl,--hash-style=gnu -o .libs/modbus_server_test modbus_server_test.o Serial.o SerialUtil.o Crc.o RtuFramer.o Pdu.o
SerialMaster.o
-L/home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/opt/my/lib
-L/opt/my/lib /usr/local/apr/lib/libapr-2.so -L/home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/usr/lib
/usr/lib/x86_64-linux-gnu/libexpat.so
/home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/usr/lib/libuuid.so
-lrt -lcrypt -lpthread -ldl /home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/usr/lib/libexpat.so
/home/ABC/build/build/sysroots/armv7a-ABC-linux-gnueabi/usr/lib/libstdc++.so
-lm -pthread -Wl,-rpath -Wl,/usr/local/apr/lib -Wl,-rpath -Wl,/home/ABC/build/sysroots/armv7a-ABC-linux-gnueabi/usr/lib
| /usr/lib/x86_64-linux-gnu/libexpat.so: file not recognized: File
format not recognized
| collect2: ld returned 1 exit status
| make[2]: *** [modbus_server_test] Error 1
From output I can see that it include two libraries: one from linux environment (/usr/lib/x86_64-linux-gnu/libexpat.so which is x86) and one from the build folder (build/sysroots/armv7a-ABC-linux-gnueabi/usr/lib/libexpat.so which is for ARM).At the end it complains about x86 type.
How can I exclude this library from searching in global environment? Why it even trying to use both of them?

Error compiling SOSlib C library

I am attempting to compile a library,
http://www.tbi.univie.ac.at/~raim/odeSolver/
this one specifically, I have gotten the necessary libraries for this.
However whenever i attempt to compile it with "make", I get the following error.
Making all in src
make[1]: Entering directory `/home/user/SOSLib/buildSOSlib/src'
/usr/bin/make all-am
make[2]: Entering directory `/home/user/SOSLib/buildSOSlib/src'
/bin/bash ../libtool --tag=CC --mode=link /usr/bin/gcc-4.8 -Wno-unknown-pragmas -Wall -Wextra -ansi -std=iso9899:1990 -g3 -gdwarf-2 -no-undefined -L/usr/lib64 -L/usr/local/lib -o libODES.la -rpath /usr/local/lib ASTIndexNameNode.lo arithmeticCompiler.lo charBuffer.lo compiler.lo cvodeData.lo cvodeSolver.lo daeSolver.lo drawGraph.lo evaluateAST.lo integratorInstance.lo integratorSettings.lo interpol.lo modelSimplify.lo nullSolver.lo odeConstruct.lo odeModel.lo odeSolver.lo processAST.lo sbml.lo sbmlResults.lo sensSolver.lo solverError.lo util.lo data.lo error.lo -lsbml -lxml2 -lsundials_ida -lsundials_kinsol -lsundials_cvodes -lsundials_nvecserial -lm -lm -ldl
libtool: link: /usr/bin/gcc-4.8 -shared -fPIC -DPIC .libs/ASTIndexNameNode.o .libs/arithmeticCompiler.o .libs/charBuffer.o .libs/compiler.o .libs/cvodeData.o .libs/cvodeSolver.o .libs/daeSolver.o .libs/drawGraph.o .libs/evaluateAST.o .libs/integratorInstance.o .libs/integratorSettings.o .libs/interpol.o .libs/modelSimplify.o .libs/nullSolver.o .libs/odeConstruct.o .libs/odeModel.o .libs/odeSolver.o .libs/processAST.o .libs/sbml.o .libs/sbmlResults.o .libs/sensSolver.o .libs/solverError.o .libs/util.o .libs/data.o .libs/error.o -L/usr/lib64 -L/usr/local/lib -lsbml -lxml2 /usr/local/lib/libsundials_ida.a /usr/local/lib/libsundials_kinsol.a /usr/local/lib/libsundials_cvodes.a /usr/local/lib/libsundials_nvecserial.a -lm -ldl -Wl,-soname -Wl,libODES.so.0 -o .libs/libODES.so.0.0.0
/usr/bin/ld: /usr/local/lib/libsundials_ida.a(ida.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libsundials_ida.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [libODES.la] Error 1
make[2]: Leaving directory `/home/user/SOSLib/buildSOSlib/src'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/user/SOSLib/buildSOSlib/src'
make: *** [all-recursive] Error 1
What is happening here?
You are trying to build a shared library, and shared libraries must be built as position-independent code so they an be loaded and run anywhere in memory. This is achieved passing the -fPIC flag to GCC. It seems that one of the libraries (libsundials_ida.a) was not built with it.

Encountering 'undefined reference' and 'error adding symbols' when compiling OpenEXR [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 7 years ago.
I am installing OpenEXR_Viewers on Ubuntu 14.04. When running the makefile, I encounter the following error:
/usr/bin/ld: ImageView.o: undefined reference to symbol 'glOrtho'
//usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: error adding symbols: DSO
missing from command line collect2: error: ld returned 1 exit status
Is it likely that my lib tool invocation is not calling GL? If this is the case, how do I set my libtool to build with GL? (Edit the makefile to see OpenGl)
Making all in playexr
make[1]: Entering directory `/home/user/Documents/source/openexr/OpenEXR_Viewers/playexr'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/user/Documents/source/openexr/OpenEXR_Viewers/playexr'
Making all in exrdisplay
make[1]: Entering directory `/home/user/Documents/source/openexr/OpenEXR_Viewers/exrdisplay'
/bin/bash ../libtool --tag=CXX --mode=link g++ -pipe -g -O2 -o exrdisplay main.o ImageView.o loadImage.o scaleImage.o applyCtl.o GlWindow3d.o -L/usr/local/lib -pthread -L/usr/local/lib -lIlmImf -lImath-2_2 -lIexMath-2_2 -lHalf -lIex-2_2 -lIlmThread-2_2 -DHAVE_CTL_INTERPRETER=0 -L/usr/local/lib -DHAVE_CTL_INTERPRETER=0 -pthread -L/usr/local/lib -lIlmImf -lImath-2_2 -lIexMath-2_2 -lHalf -lIex-2_2 -lIlmThread-2_2 -Wl,-Bsymbolic-functions -lfltk_gl -lfltk -lX11
*** Warning: Linking the executable exrdisplay against the loadable module
*** libImath-2_2.so is not portable!
*** Warning: Linking the executable exrdisplay against the loadable module
*** libIexMath-2_2.so is not portable!
*** Warning: Linking the executable exrdisplay against the loadable module
*** libHalf.so is not portable!
*** Warning: Linking the executable exrdisplay against the loadable module
*** libIex-2_2.so is not portable!
*** Warning: Linking the executable exrdisplay against the loadable module
*** libIlmThread-2_2.so is not portable!
libtool: link: g++ -pipe -g -O2 -o exrdisplay main.o ImageView.o loadImage.o scaleImage.o applyCtl.o GlWindow3d.o -pthread -DHAVE_CTL_INTERPRETER=0 -DHAVE_CTL_INTERPRETER=0 -pthread -Wl,-Bsymbolic-functions -L/usr/local/lib /usr/local/lib/libIlmImf.so /usr/local/lib/libImath-2_2.so /usr/local/lib/libIexMath-2_2.so /usr/local/lib/libHalf.so /usr/local/lib/libIex-2_2.so /usr/local/lib/libIlmThread-2_2.so -lfltk_gl -lfltk -lX11 -pthread
/usr/bin/ld: ImageView.o: undefined reference to symbol 'glOrtho'
//usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[1]: *** [exrdisplay] Error 1
make[1]: Leaving directory `/home/user/Documents/source/openexr/OpenEXR_Viewers/exrdisplay'
make: *** [all-recursive] Error 1
Try adding -lglut -lGL (and probably -lGLU) to you linker command.
(g++ linker: /usr/lib/libGL.so.1: could not read symbols: Invalid operation)
UPDATE:
Append it to:
FLTK_LDFLAGS = -Wl,-Bsymbolic-functions -lfltk_gl -lfltk -lX11
like
FLTK_LDFLAGS = -Wl,-Bsymbolic-functions -lfltk_gl -lfltk -lX11 -lglut -lGL

build alljoyn sample chat failed on android

I want to use the NDK to build the sample application chat (cpp version) of alljoyn on android. But I got the error undefined reference to 'typeinfo for ajn::BusObject'. And I have checked the alljoyn library path and I could find the libajdaemon.a and liballjoyn.a. The NDK version is r9c. The alljoyn android SDK version is 3.4.6. Can someone help me? Thanks!
The detail information is following:
/Volumes/MacintoshHD/Users/wshu_cn/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++ -Wl,-soname,libChat.so -shared --sysroot=/Volumes/MacintoshHD/Users/wshu_cn/android-ndk-r9c/platforms/android-17/arch-arm ./obj/local/armeabi/objs-debug/Chat/Chat_jni.o ./obj/local/armeabi/libstdc++.a -lgcc -no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -L/Volumes/MacintoshHD/Users/wshu_cn/android-ndk-r9c/platforms/android-17/arch-arm/usr/lib -L/Volumes/MacintoshHD/Users/wshu_cn/android-ndk-r9c/platforms/android-8/arch-arm/usr/lib -L../..//lib -L/Volumes/MacintoshHD/Users/wshu_cn/android-ndk-r9c/sources/cxx-stl/gnu-libstdc++/libs/armeabi -L/Volumes/MacintoshHD/Users/wshu_cn/android-ndk-r9c/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi -L./libs ../..//lib/BundledDaemon.o -lajdaemon -lalljoyn -llog -lz -ldl -lssl -lcrypto -lm -lc -lstdc++ -lgcc -lgnustl_static -lstdc++ -lc -lm -o ./obj/local/armeabi/libChat.so
/Volumes/MacintoshHD/Users/wshu_cn/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs-debug/Chat/Chat_jni.o: in function typeinfo for ChatObject:Chat_jni.cpp(.data.rel.ro._ZTI10ChatObject+0x8): error: undefined reference to 'typeinfo for ajn::BusObject'
collect2: ld returned 1 exit status

ld skipping incompatible library when g++ compiling with either -m32 or -m64

I'm on 64-bit Ubuntu and I'm trying to build with "libasmlibrary.so" with Eclipse. However, it kept telling me that the library is incompatible, either with "-m32" or "-m64". This is what is shown when I don't add either of the two options.
17:25:54 ** Incremental Build of configuration Debug for project ASM_TEST **
make all
Building target: ASM_TEST
Invoking: GCC C++ Linker
g++ -L/usr/local/lib -L/home/leon/asmlibrary/linux -o "ASM_TEST" ./src/demo_fit.o ./src/video_camera.o ./src/vjfacedetect.o -lopencv_core -lasmlibrary -lopencv_highgui -lopencv_imgproc -lopencv_ml -lopencv_video -lopencv_objdetect
/usr/bin/ld: skipping incompatible /home/leon/asmlibrary/linux/libasmlibrary.so when searching for -lasmlibrary
/usr/bin/ld: cannot find -lasmlibrary
collect2: ld returned 1 exit status
make: * [ASM_TEST] Error 1
17:25:54 Build Finished (took 111ms)

Resources