I compile a program in C ++ and get the following error message:
undefined reference to 'pthread_mutexattr_init'
undefined reference to 'dlopen'
undefined reference to 'dlerror'
undefined reference to 'dlsym'
undefined reference to 'dlclose'
To fix the error for pthread, I added the following linker flag to mine CMakeLists.txt.
if (UNIX)
set(CMAKE_CXX_FLAGS "-pthread")
endif (UNIX)
This resolved the error pthread. To fix the error libdl, I went ahead and changed it to the following.
if (UNIX)
set(CMAKE_CXX_FLAGS "-pthread -dl")
endif (UNIX)
It gave me a warning
unrecognized gcc debugging option: l
I changed it to the next
if (UNIX)
set(CMAKE_CXX_FLAGS "-pthread")
set(CMAKE_CXX_FLAGS "-dl")
endif (UNIX)
And returned all error messages along with
unrecognized gcc debugging option: l.
Don't know how to set linker flags in CMake? What am I doing wrong? I'm on Ubuntu 17.04 x64.
Amani source
share