Numerous LD linking errors while linking against downloaded package - c++

I've been trying to compile an open-source C++ project Typesense, which has this list of dependencies:
Snappy
zlib
OpenSSL (>=1.0.2)
curl
ICU
brpc
braft
Host and target OS is Debian Linux. Compilation is handled via cmake->make sequence of commands. I was able to install some of dependencies through a package manager (I believe they reside in /usr/lib then), the last two I had to compile on my own, I put them in /usr/local/lib.
All the dependencies were successfully compiled, and the target project compiled too.
When it comes to linking stage, I get numerous errors like
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-easy.o): in function `global_init':
(.text+0x94): undefined reference to `libssh2_init'
...
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-http2.o): in function `on_header':
(.text+0x6c): undefined reference to `nghttp2_session_get_stream_user_data'
...
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-socks_gssapi.o): in function `check_gss_err.part.0':
(.text+0x57): undefined reference to `gss_release_buffer'
/usr/bin/ld: (.text+0x77): undefined reference to `gss_display_status'
/usr/bin/ld: (.text+0x9b): undefined reference to `gss_release_buffer'
/usr/bin/ld: (.text+0xcf): undefined reference to `gss_release_buffer'
/usr/bin/ld: (.text+0xef): undefined reference to `gss_display_status'
/usr/bin/ld: (.text+0x112): undefined reference to `gss_release_buffer'
/usr/bin/ld: (.text+0x17e): undefined reference to `gss_release_buffer'
...
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-curl_rtmp.o): in function `rtmp_connect':
(.text+0xd4): undefined reference to `RTMP_Connect1'
...
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcurl.a(libcurl_la-openldap.o): in function `ldap_connecting':
(.text+0x111): undefined reference to `ldap_result'
There is at least a hundred of such errors. I'm not at all proficient with Linux and complex building of projects. How do I possibly fix linking errors for libraries that I just downloaded through a package manager?
EDIT: Libraries, that cmake seems to link against at the end:
braft;
brpc;
/usr/lib/x86_64-linux-gnu/libleveldb.a;
glog;
h2o-evloop;
iconv;
/usr/lib/x86_64-linux-gnu/libcurl.a;
for;
/usr/lib/x86_64-linux-gnu/libicui18n.a;
/usr/lib/x86_64-linux-gnu/libicuuc.a;
/usr/lib/x86_64-linux-gnu/libicudata.a;
rocksdb;
/usr/lib/x86_64-linux-gnu/libsnappy.a;
/usr/lib/x86_64-linux-gnu/libz.a;
rt;
/usr/lib/x86_64-linux-gnu/libssl.a;
/usr/lib/x86_64-linux-gnu/libcrypto.a;
pthread;
dl;
-static-libgcc;
-static-libstdc++;
gflags_shared;
/usr/lib/x86_64-linux-gnu/libprotobuf.a;
-lpthread

Your dependency list is incomplete. It only includes immediate dependencies.
Your version of libcurl is built with ssh, gssapi, nghttp2, ldap, rtmp and possibly other goodies, none of which you are linking against. You are using static linking, and static libraries do not have a built in concept of dependencies. This means you have to manually include all the non-immediate dependencies in your build command. You can get the impression of how many more libraries you need to include by executing this command
ldd /path/to/your/libcurl.so
and observing the list of dependencies your libcurl has.
The same thing may be true about other libraries you use.
One way to resolve the issue is to use dynamic linking. This way you just link to immediate dependencies, and they know their dependencies.

Related

Can't link against static library with Mingw on Linux

I have installed the GMP library and try to cross-compile with mingw-w64-posix.
My Library is in /usr/local/lib.
My compile command looks like the following:
x86_64-w64-mingw32-g++-posix src/factorial.cpp -o bin/factorial.win.o -I/usr/local/include -L/usr/local/lib -lgmp -lgmpxx
It throws an undefined reference error:
(I can remove the whole block from -L...., same error. Seems like the library doesnt link for some reason)
/usr/bin/x86_64-w64-mingw32-ld: /tmp/ccxY03WS.o:factorial.cpp:(.text$_ZN23__gmp_binary_multiplies4evalEP12__mpz_structPKS0_S3_[_ZN23__gmp_binary_multiplies4evalEP12__mpz_structPKS0_S3_]+0x27): undefined reference to `__gmpz_mul'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/ccxY03WS.o:factorial.cpp:(.text$_ZN23__gmp_binary_multiplies4evalEP12__mpz_structPKS0_l[_ZN23__gmp_binary_multiplies4evalEP12__mpz_structPKS0_l]+0x26): undefined reference to `__gmpz_mul_si'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/ccxY03WS.o:factorial.cpp:(.text$_ZN10__gmp_exprIA1_12__mpz_structS1_E7init_siEl[_ZN10__gmp_exprIA1_12__mpz_structS1_E7init_siEl]+0x1a): undefined reference to `__gmpz_init_set_si'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/ccxY03WS.o:factorial.cpp:(.text$_ZN10__gmp_exprIA1_12__mpz_structS1_EC1EOS2_[_ZN10__gmp_exprIA1_12__mpz_structS1_EC1EOS2_]+0x2e): undefined reference to `__gmpz_init'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/ccxY03WS.o:factorial.cpp:(.text$_ZN10__gmp_exprIA1_12__mpz_structS1_ED1Ev[_ZN10__gmp_exprIA1_12__mpz_structS1_ED1Ev]+0x14): undefined reference to `__gmpz_clear'
collect2: error: ld returned 1 exit status
However if i change my compiler to g++ instead everything works fine.
OK -
The link errors (__gmpz_init, __gmpz_clear, etc.) are GMP "internals". They're supposed to come from libgmp, the C-language base library.
The code that's referencing them (.text$ZN23__gmp_binary_multiplies4evalEP12__mpz_structPKS0_S3[ZN23__gmp_binary_multiplies4evalEP12__mpz_structPKS0_S3], etc.) is "name mangled" C++.
I suspect the problem is that your "gmpxx" library was built with a different C++ compiler, that has a different "name mangling" convention than MinGW.
SOLUTION:
Download the complete libGMP source (e.g. from https://gmplib.org/, and rebuild EVERYTHING (including libgmpxx) with your libmingw-w64-posix++ C++ cross-compiler.
ADDENDUM:
I downloaded gmp-6.2.1 source, and found __gmpz_clear here:
gmp-6.2.1\gmp-h.in
#define mpz_clear __gmpz_clear
__GMP_DECLSPEC void mpz_clear (mpz_ptr);
"gmp-h.in" is a template used by the project's "autoconf", to generate the libGMP source files for the specified target environment.
Which, in turn, means:
The project you started out with (in your original question) wasn't configured for MinGW
... and ...
You didn't run "configure" correctly when you tried building from source.
SUGGESTION:
Try building libGMP from source again. DELETE everything, re-extract from the libGMP tarball, and carefully follow the INSTALL instructions:
./configure
make
make check <= VERY IMPORTANT!!
make install
I'm curious about your build environment (Windows? Linux?), compiler (exact MinGW version) and target (if you're building on a Windows workstation, do you want to run your GMP app as a Windows .exe)?

Error => /usr/bin/ld: cannot find -lQt5::Core -lQt5::Gui -lQt5::Test -lQt5::Concurrent -lQt5::OpenGL

I am getting these errors
`/usr/bin/ld: cannot find -lQt5::Core /usr/bin/ld:
cannot find -lQt5::Gui /usr/bin/ld:
cannot find -lQt5::Widgets /usr/bin/ld:
cannot find -lQt5::Test /usr/bin/ld:
cannot find -lQt5::Concurrent /usr/bin/ld:
cannot find -lQt5::OpenGL collect2: error: ld`
when i am makeing the project [https://github.com/estranho/facialSketchRecognition] .When i am making without ENABLE_SAMPLES i fotn get any error but when building Samples i m getting these errors.
https://github.com/estranho/facialSketchRecognition the project readme says cmake.. and make thats it but couldnt run any executable so building Samples is needed.
You must:
either install globally the Qt5 development library
define your LD_LIBRARY_PATH to allow the system to find the Qt5 library, when performing the linking step (which is exactly what /usr/bin/ld is trying to do)
Under Ubuntu the package is named qtdeclarative5-dev.

Failure to link Qhull C++ interface in ROS catkin project

I'm having some trouble getting the QHull C++ interface working in a catkin project. My project compiles fine and I've specified the library to be used by the linker, however it fails to link with the following error messages.
CMakeFiles/path_to/my_code.cpp.o: In function `main':
my_code.cpp:(.text+0x17ab): undefined reference to `orgQhull::RboxPoints::RboxPoints()'
my_code.cpp:(.text+0x182a): undefined reference to `orgQhull::PointCoordinates::appendPoints(std::istream&)'
my_code.cpp:(.text+0x1839): undefined reference to `orgQhull::Qhull::Qhull()'
my_code.cpp:(.text+0x1857): undefined reference to `orgQhull::Qhull::runQhull(orgQhull::RboxPoints const&, char const*)'
my_code.cpp:(.text+0x18aa): undefined reference to `orgQhull::Qhull::outputQhull(char const*)'
my_code.cpp:(.text+0x19d0): undefined reference to `orgQhull::Qhull::~Qhull()'
my_code.cpp:(.text+0x19ee): undefined reference to `orgQhull::RboxPoints::~RboxPoints()'
my_code.cpp:(.text+0x1c10): undefined reference to `orgQhull::Qhull::~Qhull()'
my_code.cpp:(.text+0x1c38): undefined reference to `orgQhull::RboxPoints::~RboxPoints()'
CMakeFiles/build_path/my_code.cpp.o: In function `orgQhull::Qhull::setOutputStream(std::ostream*)':
I've installed the following packages, to get the shared object and development files.
libqhull-dev
libqhull-doc
libqhull7
qhull-bin
I don't know if this is related to the problem, but looking into the libqhull.so shared object there are no symbols in it.
####:/usr/lib/x86_64-linux-gnu$ nm -g libqhull.so
nm: libqhull.so: no symbols
Has anyone got any experience getting this to work on linux? Any help would be appreciated.
I'm using ROS Indigo, this works for me:
SET(qhullDir path_to_qhull_code)
INCLUDE_DIRECTORIES(${qhullDir}/src/libqhullcpp)
INCLUDE_DIRECTORIES(${qhullDir}/src)
LINK_DIRECTORIES(${qhullDir}/build)
INCLUDE_DIRECTORIES(${qhullDir}/src/libqhullcpp)
INCLUDE_DIRECTORIES(include)
SET(qhullLibs qhullcpp qhull_r)
add_library(${PROJECT_NAME}_library
src/myClass.cpp)
add_executable(libExample
src/myrunnable.cpp)
target_link_libraries(libExample
${PROJECT_NAME}_library ${qhullLibs})
SET_TARGET_PROPERTIES(libExample PROPERTIES
COMPILE_DEFINITIONS "qh_QHpointer")
I'm compiling qhull from source with cmake.
Maybe this helps someone.

boost-1.55.0 undefined reference to `boost::thread::join() even after linking with the correct library

I get undefined symbol reference errors even after linking with the correct boost library:
undefined reference to `boost::thread::join()
undefined reference to `boost::thread::start_thread()
nm libboost_thread.so -Cg|grep boost::thread::join shows
000000000000ce00 T boost::thread::join_noexcept()
000000000000c1a0 T boost::thread::joinable() const
What happened to join() ?
boost::thread::join() is an inline function now.
Your build system probably does not maintain dependencies on system headers and ends up linking object files compiled against an older version of boost. Do a full rebuild.

Error in linking external libraries

I downloaded TripleBit's source code from http://grid.hust.edu.cn/triplebit/TripleBit.tar.gz.
It required me to install two libraries:
i) boost-1.39.0.tar.gz
ii) raptor-1.4.21.tar.gz
I installed them using :
sudo apt-get install libboost-dev
sudo apt-get install libraptor-dev
However, after I entered into TripleBit's directory and ran "make". I go the following errors:
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:38: undefined reference to `raptor_init'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:39: undefined reference to `raptor_new_parser'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:40: undefined reference to `raptor_set_statement_handler'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:42: undefined reference to `raptor_uri_filename_to_uri_string'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:43: undefined reference to `raptor_new_uri'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:44: undefined reference to `raptor_uri_copy'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:45: undefined reference to `raptor_parse_file'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:47: undefined reference to `raptor_free_parser'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:48: undefined reference to `raptor_free_uri'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:49: undefined reference to `raptor_free_uri'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:50: undefined reference to `raptor_free_memory'
/home/TripleBit/BuildTripleBitFromRDF/BuildTripleBit.cpp:52: undefined reference to `raptor_finish'
collect2: ld returned 1 exit status
make: *** [bin/lrelease/buildTripleBitFromRDF] Error 1
The library files which reside within /usr/local/lib are:
libboost_filesystem.so, libraptor.a, libraptor.la, libraptor.so, libraptor.so.1
and libraptor.so.1.2.0
Also the files which reside within /usr/lib are:
libraptor.a, libraptor.la, libraptor.so, libraptor.so.1, libraptor.so.1.2.0,
libraptor2.so.0, libraptor2.so.0.0.0, librasqal.so.3, librasqal.so.3.0.0, librdf.so.0,
librdf.so.0.0.0, librest-0.7.so.0, librest-0.7.so.0.0.0.
Can someone please help me in finding out the error.
I ran it on ubuntu 12.04
Look into TripleBit Makefile. You are missing -lraptor linker option. This entry should be returned by raptor-config --libs.
You can also run nm tool against libraptor.a file and check if it wasn't compiled with RAPTOR_DISABLE_V1 option.
Look into TripleBit Makefile, you can remove the "BuildTripleBitFromRDF" in line 82(modules := ..), so that you can escape the errors, but the "BuildTripleBitFromRDF" will not build into the executables. So when the dataset you download is a RDF dataset, You can use raptor to convert RDF dataset into N3 dataset, and then use the buildTripleBitFromN3 tool to go on.
The probable problem is the wrong installing in raptor.