Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linker error: undefined reference to symbol 'pthread_rwlock_trywrlock@@GLIBC_2.2.5'

Tags:

c++

qt

gcc4.7

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?

like image 753
segfault Avatar asked Apr 27 '13 22:04

segfault


4 Answers

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.

like image 129
Ben Jackson Avatar answered Nov 02 '22 11:11

Ben Jackson


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

like image 24
cmannett85 Avatar answered Nov 02 '22 12:11

cmannett85


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.

like image 4
lmns Avatar answered Nov 02 '22 11:11

lmns


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

like image 1
George Moraitis Avatar answered Nov 02 '22 11:11

George Moraitis