Error in linking external libraries - c++

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.

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)?

Numerous LD linking errors while linking against downloaded package

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.

Linker errors in libqt5network.so

Hello dear stack overflow users,
lately I tried to compile a qt5 project on my suse machine.
It seems that my linker refuses to link the libqt5network.so against openssl.
And I fail to understand why:
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `TLSv1_1_server_method'
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `SSL_set_psk_client_callback'
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `TLSv1_1_client_method'
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `SSL_select_next_proto'
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `SSL_get0_next_proto_negotiated'
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `TLSv1_2_client_method'
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `SSL_CTX_set_next_proto_select_cb'
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `TLSv1_2_server_method'
/usr/lib64/libQt5Network.so:-1: error: undefined reference to `EC_curve_nist2nid'
This Method seems the culprit, which shall download some information of a book frome the worldcat book database by its public api:
void Worldcat::search(QString searchTerm){
if(book1!=NULL){
setIsbn(searchTerm);
QNetworkRequest request(apiUri+getIsbn()+QString("?method=getMetadata&format=json&fl=*"));
networkManager = new QNetworkAccessManager(this);
connect(networkManager,SIGNAL(finished(QNetworkReply*)),
this,SLOT(replyFinished(QNetworkReply*)));
networkManager->get(request);
}
}
qmake.pro file
http://pastebin.com/Qk83kLaQ
The Generated make file, it is huge therefore paste bin:
http://pastebin.com/KuF9Y0JS
I will answer it myself since I found the solution when my mongodb also refused to start, maybe it is usefeull to someone the following does help:
zypper in libopenssl-devel
rpm -e --nodeps libopenssl0_9_8
cd /usr/lib64/
ln -s libssl.so libssl.so.0.9.8
ln -s libcrypto.so libcrypto.so.0.9.8
Seems that tumble weed has a mess with its openssl librarys.
Where I found the solution:
https://stackoverflow.com/a/32406299/4958693
Original source:
https://jira.mongodb.org/browse/SERVER-20259

install a library so that c++ compiler can directly access it

I installed libmcrypt on my system by using the following commands:-
avinash#ak-pc:~/Documents/network_lab/tut7$ cd libmcrypt-2.5.8
avinash#ak-pc:~/Documents/network_lab/tut7/libmcrypt-2.5.8$ ./configure --prefix=/usr --disable-posix-threads
avinash#ak-pc:~/Documents/network_lab/tut7/libmcrypt-2.5.8$ make
avinash#ak-pc:~/Documents/network_lab/tut7/libmcrypt-2.5.8$ sudo make install
As a result headers went to /usr/include and the libraries to /usr/lib. Now, when I include < mcrypt.h> into a .cpp file and use functions provided by libmcrypt, the compiler announces
/tmp/ccCot4nH.o: In function `main':
q3.cpp:(.text+0x64): undefined reference to `mcrypt_module_open'
q3.cpp:(.text+0xb9): undefined reference to `mcrypt_generic_init'
q3.cpp:(.text+0xd6): undefined reference to `mcrypt_generic'
q3.cpp:(.text+0x110): undefined reference to `mdecrypt_generic'
q3.cpp:(.text+0x13a): undefined reference to `mcrypt_generic_deinit'
q3.cpp:(.text+0x147): undefined reference to `mcrypt_module_close'
collect2: ld returned 1 exit status
Can anybody tell me where the problem is? Was there something wrong with the installation procedure?
Including the header files of a library only provides declarations so that the compiler is aware of function signatures and global variable types, but you also need to indicate to the linker the library your program is to be dynamically linked with.
With most compilers, use the -l flag followed by the library's name, without the lib prefix. For example, your linking command may look something like this:
g++ -o myprogram obj1.o obj2.o ... obj.o -lmcrypt

waf cannot find an existing library

I'm trying to program a C++ module for node.js.
Node is using waf as builder.
I want to check on configure, if the library "sigar" exists.
What I'm trying to do so:
def configure(conf):
conf.check_cxx(lib='sigar')
When I run "node-waf configure", I get the following message:
Checking for library sigar : not found
But libsigar.so exists:
# whereis libsigar
libsigar: /lib64/libsigar.so
I also ran ldconfig after installing the "libsigar" library.
The node module compiles, links and works without errors.
Other libraries like libm, libboost_system and so on can be found on configure.
Can someone tell me what I am doing wrong?
Is there anything special to do for installing a library than only copying a *.so to the library path and running ldconfig?
Thanks for any help.
Solved it on my own.
Its pretty helpful to run configure with the -vvv option, for very verbose output.
20:31:48 runner system command -> ['/usr/bin/g++', 'Release/test_1.o', '-o', '/home/reeaal/workspace/hwmonitor/build/.conf_check_0/testbuild/Release/testprog', '-Wl,-Bdynamic', '-lsigar']
When I tried to recompile the programm, I got a linker error which really helped:
g++ test.cpp -Bdynamic -lsigar
/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64/libsigar.so: undefined reference to `dlsym'
/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64/libsigar.so: undefined reference to `dlopen'
/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64/libsigar.so: undefined reference to `dlclose'
collect2: ld returned 1 exit status
Adding a linker flag before checking for libsigar solved the problem:
conf.env.append_value('LINKFLAGS', '-ldl')