segfault
segfault

Reputation: 5939

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

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?

Upvotes: 12

Views: 31959

Answers (5)

denrad
denrad

Reputation: 3

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'

Upvotes: 0

George Moraitis
George Moraitis

Reputation: 103

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

Upvotes: 1

cmannett85
cmannett85

Reputation: 22366

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

Upvotes: 5

Ben Jackson
Ben Jackson

Reputation: 93860

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.

Upvotes: 19

lmns
lmns

Reputation: 51

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.

Upvotes: 5

Related Questions