Linker error: undefined reference to symbol 'pthread_rwlock_trywrlock##GLIBC_2.2.5' - c++

I've been developing with CentOS, Qt 4.7, and GCC 4.4
I've just installed Red Hat Developer Toolset 1.1 which includes GCC 4.7.2, and at the end of make, I get an error
/usr/bin/ld: ../../bin/Solo: undefined reference to symbol 'pthread_rwlock_trywrlock##GLIBC_2.2.5'
/usr/bin/ld: note: 'pthread_rwlock_trywrlock##GLIBC_2.2.5' is defined in DSO /lib64/libpthread.so.0 so try adding it to the linker command line
/lib64/libpthread.so.0: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
I'm guessing that Qt threads is referencing to that. How can I fix it?

You want to compile with -pthread which does more than just link with libpthread:
Adds support for multithreading with the pthreads library. This
option sets flags for both the preprocessor and linker.

You just need to add CONFIG += thread to your .pro file.

Read the note: try to add /lib64/libpthread.so.0 into Makefile (-lpthread after gcc command, or /lib64/libpthread.so.0 after ld (or after gcc -shared)), or something like LIB += -lpthread if there's such definition somewhere.
See also: Adding external library into Qt Creator project and http://www.qtcentre.org/threads/39144-How-to-add-a-lib-to-a-qt-project
Btw, post your Makefile, so somebody will be able to point to exact line.

In my little laptop Linux (where I have a mixed bag of libraries),
I just had to add
LDFLAGS=-lpthread
AT THE END of the configure command arguments.
After that, make did its job perfectly (With the existing libraries).

I received similar 'Linker error: undefined reference to symbol' errors attempting to compile and install Python-3.7.2 on FreeBSD 12.
/usr/bin/ld: error: undefined symbol: _Py_GetGlobalVariablesAsDict
/usr/bin/ld: error: undefined symbol: _PyCoreConfig_AsDict
/usr/bin/ld: error: undefined symbol: _PyMainInterpreterConfig_AsDict
Resolved by passing LDFLAGS=-lpthread directly to make of lang/python37 or by adding to /etc/make.conf.
If using portmaster to install/update use -m to pass the arguement to make e.g.portmaster -a -m 'LDFLAGS=-lpthread'

Related

__imp link errors using g++ running under mingw

I have a simple socket program that I'm trying to compile using g++ running in mingw (both the latest versions) on a Win8 system. I'm getting the common linker errors
undefined reference to `__imp_socket'
undefined reference to `__imp_gethostbyname'
I've tried adding -lws2_32 with no luck; i.e. it still can't find the references. Can someone suggest something else I might be missing?
Here's the full output:
G:\source\kak>g++ -o ./test_client -lws2_32 test_client.C
C:\Users\kenkahn\AppData\Local\Temp\ccDZTr9b.o:test_client.C:(.text+0x4f): undefined reference to `__imp_inet_addr'
C:\Users\kenkahn\AppData\Local\Temp\ccDZTr9b.o:test_client.C:(.text+0x6b): undefined reference to `__imp_socket'
C:\Users\kenkahn\AppData\Local\Temp\ccDZTr9b.o:test_client.C:(.text+0x8b): undefined reference to `__imp_connect'
d:/program files/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kenkahn\AppData\Local\Temp\ccDZTr9b.o: bad reloc address 0xc in section `.xdata'
collect2.exe: error: ld returned 1 exit status
Try putting the -lws2_32 after the test_client.C parameter. The linker of gcc (ld) is touchy about the order of linkable things, this is probably why it doesn't find your imported functions at link time.

Google RE2 library cannot compile with 'make testinstall' in ubuntu

Gurus!
I am using Ubuntu 13.10 64-bit to compile latest Google RE2 library, but 'make testinstall' failed to compile, here is the log:
kevin#ubuntu:~/re2$ make testinstall
cp testinstall.cc obj
(cd obj && g++ -I/usr/local/include -L/usr/local/lib testinstall.cc -lre2 -pthread -o testinstall)
/tmp/ccSsaSXS.o: In function main':
testinstall.cc:(.text+0xce): undefined reference tore2::FilteredRE2::FirstMatch(re2::StringPiece const&, std::vector > const&) const'
/usr/local/lib/libre2.so: undefined reference to pthread_rwlock_rdlock'
/usr/local/lib/libre2.so: undefined reference topthread_rwlock_wrlock'
/usr/local/lib/libre2.so: undefined reference to pthread_rwlock_destroy'
/usr/local/lib/libre2.so: undefined reference topthread_rwlock_init'
/usr/local/lib/libre2.so: undefined reference to `pthread_rwlock_unlock'
collect2: error: ld returned 1 exit status
make: * [testinstall] Error 1
I tried to replace -pthread with -lpthread, still failed, then I dumped libre2.so and found that pthread_xxx is in it.
Here is the issue tracking in RE2 forum: https://code.google.com/p/re2/issues/detail?id=100
Anyone here have ever complied RE2 successfully ? Thank you!
See this comment:
Adding -pthread to LDFLAGS seems to fix make test (all tests are
passing), but not make testinstall.
That will get you to the next error
Depending on what you build it for 'make testinstall' might not be necessary.
I just needed to get python re2 port working, and this can be installed after running make install.
I encounter this problem before. Modify the makefile and use -lpthread instead of -pthread.
So I tried looking for the lines in testinstall.cc that were causing the symbol errors and I found out that the only line was on line 18:
18 - f.firstMatch(:abbccc:, ids);
I commented this line out (so that the FullMatch function below is still called) and just ran g++ testinstall.cc -lre2 -pthread -o testinstall (basically what the Makefile does) and I was able to get a binary successfully. Although this might not really solve the problem, its good to know that we can still use the RE2::Fullmatch and partial match functions
If I were to guess, maybe there is a dependency somewhere inside the filtered_re2 module?
I had the same problem. But if you compile with -static everything goes well.
nm -C shows that the "missing" symbol exists in both .a and .so files.

linux shared library linking error

When Building an openframeworks application, I had the following linker error:
/usr/bin/ld: /[...]/openframeworks/addons/ofxOpenCv/libs/opencv/lib/linux64/libopencv_core.a(persistence.o): undefined reference to symbol 'gzclose'
/usr/bin/ld: note: 'gzclose' is defined in DSO /lib/x86_64-linux-gnu/libz.so.1 so try adding it to the linker command line
/lib/x86_64-linux-gnu/libz.so.1: could not read symbols: Invalid operation
So I added z to the cmake file and got a new error:
/usr/bin/ld: /[...]/openframeworks/addons/ofxOpenCv/libs/opencv/lib/linux64/libopencv_core.a(persistence.o): undefined reference to symbol 'gzclose'
/usr/bin/ld: note: 'gzclose' is defined in DSO /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libz.so so try adding it to the linker command line
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libz.so: could not read symbols: Invalid operation
It's like the linker is looking for a different place to NOT find gzclose.... Could someone perhaps explain what is happening, why, and how to fix it?
when I run $ ldconfig -v | grep libz
I get libz.so.1 -> libz.so.1.2.3.4
and there is a libz.so.1.2.3.4 in two places:
/lib/i386-linux-gnu/libz.so.1.2.3.4
/lib/x86_64-linux-gnu/libz.so.1.2.3.4
My LD_LIBRARY_PATH is:
:/usr/local/lib:/usr/lib:/lib/x86_64-linux-gnu:/usr/lib/gcc/x86_64-linux-gnu
I'm running 64 bit Ubuntu 12.04 LTS, 3.2.0-58-generic, gcc version 4.8.1 (Ubuntu 4.8.1-2ubuntu1~12.04)
Thanks!
B

undefined reference to MinFilter and MaxFilter in StereoMatch code

everyone
Recently, I'm working on stereo vision. And I download the StereoMatch code from middlebury website: http://vision.middlebury.edu/stereo/code/
I used Ubuntu 11.10 to run this code. After I run this code, I got the following error. There are 3 'undefined reference to ' error. But the code has already included the header file 'MinFilter.h'. And I get confused. Could someone help me? I would appreciate it.
errors:
StcAggregate.o: In function CStereoMatcher::AggrMin()':
StcAggregate.cpp:(.text+0x20f): undefined reference tovoid MinFilter(CImageOf&, CImageOf&, int, int)'
StcEvaluate.o: In function _ZL14PartialShuffle8CImageOfIhERS0_S1_f.constprop.2':
StcEvaluate.cpp:(.text+0x37): undefined reference tovoid MinFilter(CImageOf&, CImageOf&, int, int)'
StcEvaluate.cpp:(.text+0x5b): undefined reference to `void MaxFilter(CImageOf&, CImageOf&, int, int)'
collect2: ld returned 1 exit status
make: * [StereoMatch] Error 1
This is an error from the linker (and/or runtime environment) which cannot find some symbols (i.e. code) which the header files you've included promised to exist. In order for these symbols to be found, you must tell the linker to link against the library (or object file) containing them. This library may have come with the code pre-compiled or may have been made during installation. Have you not got a README file where it is explained how to use (i.e. link and run) the code?
I met exactly the same problem and solved it like this:
Open the Makefile and change the first line from
CPPFLAGS = -O2 -Wall
to
CPPFLAGS = -O -Wall
Then "make clean" and "make", it works for me. So I guess it is because param
"-O2" does more optimization than expected.

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