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

5

12

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?

Fp answered 27/4, 2013 at 22:37 Comment(1)
Does your command line for the compiler/linker contain -pthread?Takahashi
L
19

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.

Leeland answered 28/4, 2013 at 4:50 Comment(0)
C
5

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.

Coranto answered 27/4, 2013 at 22:53 Comment(0)
A
5

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

Alamode answered 28/4, 2013 at 8:44 Comment(0)
Z
1

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

Zincography answered 5/6, 2016 at 14:56 Comment(0)
C
0

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'

Chlori answered 27/12, 2018 at 0:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.