Hello, i am new at using cmake for compiling and building c++ code.
here is my CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(example)
add_subdirectory(pybind11)
find_package( Threads REQUIRED )
#find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS})
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_executable(demo demo_python.cpp)
target_link_libraries(demo ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
target_link_libraries(demo pybind11::embed)# ${OpenCV_LIBS})
i have checked and ensured that my computer has the required library. and i am keep getting this error, which say that i haven’t linked pthread, ldl, and lutil.
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_tss_create':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:750: undefined reference to `pthread_key_create'
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_tss_delete':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:767: undefined reference to `pthread_key_delete'
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_start_new_thread':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:222: undefined reference to `pthread_create'
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:239: undefined reference to `pthread_detach'
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_acquire_lock_timed':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:372: undefined reference to `sem_wait'
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_start_new_thread':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:203: undefined reference to `pthread_attr_setstacksize'
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_tss_delete':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:767: undefined reference to `pthread_key_delete'
/usr/local/lib/libpython3.7m.a(thread.o): In function `_pythread_pthread_set_stacksize':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:640: undefined reference to `pthread_attr_setstacksize'
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_create_key':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:677: undefined reference to `pthread_key_create'
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:682: undefined reference to `pthread_key_delete'
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_set_key_value':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:712: undefined reference to `pthread_setspecific'
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_delete_key':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:696: undefined reference to `pthread_key_delete'
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_delete_key_value':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:704: undefined reference to `pthread_setspecific'
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_get_key_value':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:723: undefined reference to `pthread_getspecific'
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_allocate_lock':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:292: undefined reference to `sem_init'
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:292: undefined reference to `sem_init'
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_free_lock':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:317: undefined reference to `sem_destroy'
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_acquire_lock_timed':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:369: undefined reference to `sem_trywait'
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:369: undefined reference to `sem_trywait'
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:372: undefined reference to `sem_wait'
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:372: undefined reference to `sem_wait'
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:369: undefined reference to `sem_trywait'
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:372: undefined reference to `sem_wait'
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:369: undefined reference to `sem_trywait'
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:369: undefined reference to `sem_trywait'
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:369: undefined reference to `sem_trywait'
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:372: undefined reference to `sem_wait'
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:369: undefined reference to `sem_trywait'
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:366: undefined reference to `sem_timedwait'
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:372: undefined reference to `sem_wait'
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_release_lock':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:441: undefined reference to `sem_post'
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_tss_set':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:776: undefined reference to `pthread_setspecific'
/usr/local/lib/libpython3.7m.a(thread.o): In function `PyThread_tss_get':
/home/ion/Documents/Python-3.7.7/Python/thread_pthread.h:784: undefined reference to `pthread_getspecific'
/usr/local/lib/libpython3.7m.a(dynload_shlib.o): In function `_PyImport_FindSharedFuncptr':
/home/ion/Documents/Python-3.7.7/./Python/dynload_shlib.c:96: undefined reference to `dlopen'
/home/ion/Documents/Python-3.7.7/./Python/dynload_shlib.c:127: undefined reference to `dlsym'
/home/ion/Documents/Python-3.7.7/./Python/dynload_shlib.c:102: undefined reference to `dlerror'
/home/ion/Documents/Python-3.7.7/./Python/dynload_shlib.c:96: undefined reference to `dlopen'
/home/ion/Documents/Python-3.7.7/./Python/dynload_shlib.c:83: undefined reference to `dlsym'
/usr/local/lib/libpython3.7m.a(posixmodule.o): In function `os_forkpty_impl':
/home/ion/Documents/Python-3.7.7/./Modules/posixmodule.c:6048: undefined reference to `forkpty'
/usr/local/lib/libpython3.7m.a(posixmodule.o): In function `os_openpty_impl':
/home/ion/Documents/Python-3.7.7/./Modules/posixmodule.c:5954: undefined reference to `openpty'
/usr/local/lib/libpython3.7m.a(signalmodule.o): In function `signal_pthread_sigmask_impl':
/home/ion/Documents/Python-3.7.7/./Modules/signalmodule.c:855: undefined reference to `pthread_sigmask'
/usr/local/lib/libpython3.7m.a(signalmodule.o): In function `signal_pthread_kill_impl':
/home/ion/Documents/Python-3.7.7/./Modules/signalmodule.c:1124: undefined reference to `pthread_kill'
/usr/local/lib/libpython3.7m.a(timemodule.o): In function `time_pthread_getcpuclockid':
/home/ion/Documents/Python-3.7.7/./Modules/timemodule.c:342: undefined reference to `pthread_getcpuclockid'
/usr/local/lib/libpython3.7m.a(faulthandler.o): In function `faulthandler_thread':
/home/ion/Documents/Python-3.7.7/./Modules/faulthandler.c:564: undefined reference to `pthread_sigmask'
collect2: error: ld returned 1 exit status
CMakeFiles/demo.dir/build.make:84: recipe for target 'demo' failed
make[2]: *** [demo] Error 1
CMakeFiles/Makefile2:95: recipe for target 'CMakeFiles/demo.dir/all' failed
make[1]: *** [CMakeFiles/demo.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Please help me. I am very frustrated and tired because of this error. i have spent 2 days of ssearching and trying with no result.
thank you very much.
best regards,
Albert Christianto