Open jiangchunyu opened 6 days ago
我在编译的时候报错:
Scanning dependencies of target echo
[ 38%] Building CXX object examples/echo/CMakeFiles/echo.dir/main.cpp.o
[ 40%] Linking CXX executable ../../bin/echo
/usr/bin/ld: CMakeFiles/echo.dir/main.cpp.o: in function std::thread::thread<std::function<void (unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)>&, unsigned long&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, void>(std::function<void (unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)>&, unsigned long&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)': main.cpp:(.text._ZNSt6threadC2IRSt8functionIFvmNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEJRmRS7_EvEEOT_DpOT0_[_ZNSt6threadC5IRSt8functionIFvmNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEJRmRS7_EvEEOT_DpOT0_]+0x43): undefined reference to
pthread_create'
/usr/bin/ld: ../../lib/liblibveigar.a(call_dispatcher.cpp.o): in function std::thread::thread<void (veigar::detail::CallDispatcher::*)(), veigar::detail::CallDispatcher*, void>(void (veigar::detail::CallDispatcher::*&&)(), veigar::detail::CallDispatcher*&&)': call_dispatcher.cpp:(.text._ZNSt6threadC2IMN6veigar6detail14CallDispatcherEFvvEJPS3_EvEEOT_DpOT0_[_ZNSt6threadC5IMN6veigar6detail14CallDispatcherEFvvEJPS3_EvEEOT_DpOT0_]+0x37): undefined reference to
pthread_create'
/usr/bin/ld: ../../lib/liblibveigar.a(semaphore.cpp.o): in function veigar::Semaphore::IsExist(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': semaphore.cpp:(.text+0x2a): undefined reference to
sem_open'
/usr/bin/ld: semaphore.cpp:(.text+0x48): undefined reference to sem_close' /usr/bin/ld: ../../lib/liblibveigar.a(semaphore.cpp.o): in function
veigar::Semaphore::open(std::__cxx11::basic_string<char, std::char_traitssem_init' /usr/bin/ld: semaphore.cpp:(.text+0x1c3): undefined reference to
sem_open'
/usr/bin/ld: ../../lib/liblibveigar.a(semaphore.cpp.o): in function veigar::Semaphore::close()': semaphore.cpp:(.text+0x284): undefined reference to
sem_close'
/usr/bin/ld: semaphore.cpp:(.text+0x2a9): undefined reference to sem_destroy' /usr/bin/ld: ../../lib/liblibveigar.a(semaphore.cpp.o): in function
veigar::Semaphore::wait()':
semaphore.cpp:(.text+0x328): undefined reference to sem_wait' /usr/bin/ld: semaphore.cpp:(.text+0x33e): undefined reference to
sem_wait'
/usr/bin/ld: ../../lib/liblibveigar.a(semaphore.cpp.o): in function veigar::Semaphore::wait(long const&)': semaphore.cpp:(.text+0x465): undefined reference to
sem_timedwait'
/usr/bin/ld: semaphore.cpp:(.text+0x497): undefined reference to sem_timedwait' /usr/bin/ld: ../../lib/liblibveigar.a(semaphore.cpp.o): in function
veigar::Semaphore::release()':
semaphore.cpp:(.text+0x500): undefined reference to sem_post' /usr/bin/ld: semaphore.cpp:(.text+0x516): undefined reference to
sem_post'
/usr/bin/ld: ../../lib/liblibveigar.a(shared_memory.cpp.o): in function veigar::SharedMemory::create()': shared_memory.cpp:(.text+0xf0): undefined reference to
shm_open'
/usr/bin/ld: shared_memory.cpp:(.text+0x1a4): undefined reference to shm_unlink' /usr/bin/ld: shared_memory.cpp:(.text+0x23e): undefined reference to
shm_unlink'
/usr/bin/ld: shared_memory.cpp:(.text+0x28b): undefined reference to shm_unlink' /usr/bin/ld: ../../lib/liblibveigar.a(shared_memory.cpp.o): in function
veigar::SharedMemory::open()':
shared_memory.cpp:(.text+0x2ea): undefined reference to shm_open' /usr/bin/ld: ../../lib/liblibveigar.a(shared_memory.cpp.o): in function
veigar::SharedMemory::close()':
shared_memory.cpp:(.text+0x4b4): undefined reference to shm_unlink' /usr/bin/ld: ../../lib/liblibveigar.a(resp_dispatcher.cpp.o): in function
std::thread::thread<void (veigar::RespDispatcher::)(), veigar::RespDispatcher, void>(void (veigar::RespDispatcher::&&)(), veigar::RespDispatcher&&)':
resp_dispatcher.cpp:(.text._ZNSt6threadC2IMN6veigar14RespDispatcherEFvvEJPS2_EvEEOTDpOT0[_ZNSt6threadC5IMN6veigar14RespDispatcherEFvvEJPS2_EvEEOTDpOT0]+0x37): undefined reference to pthread_create' /usr/bin/ld: ../../lib/liblibveigar.a(sender.cpp.o): in function
std::thread::thread<void (veigar::Sender::)(), veigar::Sender, void>(void (veigar::Sender::&&)(), veigar::Sender&&)':
sender.cpp:(.text._ZNSt6threadC2IMN6veigar6SenderEFvvEJPS2_EvEEOTDpOT0[_ZNSt6threadC5IMN6veigar6SenderEFvvEJPS2_EvEEOTDpOT0]+0x37): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
make[2]: [examples/echo/CMakeFiles/echo.dir/build.make:85: bin/echo] Error 1
make[1]: [CMakeFiles/Makefile2:184: examples/echo/CMakeFiles/echo.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
可能是没有链接pthread导致,已修改
在windows wsl ubuntu 子系统下面,我只编译静态文件可以编译,能够生成liblibveigar.a 但是我在代码中引入的时候也报错 调用find_package(veigar REQUIRED) 找不到。 并且导入readme中代码提示找不到库文件 [build] /usr/bin/ld: cannot find -lveigar [build] collect2: error: ld returned 1 exit status [build] make[3]: [CMakeFiles/MainServer.dir/build.make:103: MainServer] Error 1 [build] make[2]: [CMakeFiles/Makefile2:163: CMakeFiles/MainServer.dir/all] Error 2 [build] make[1]: [CMakeFiles/Makefile2:170: CMakeFiles/MainServer.dir/rule] Error 2 [build] make: [Makefile:157: MainServer] Error 2
CMake 使用上有些问题。
按照下面的方式试试:
下面是示例
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
project(veigar-test)
find_package(veigar REQUIRED)
message(STATUS "veigar_DIR = ${veigar_DIR}")
如果查找不到,可能就需要配置 CMAKE_PREFIX_PATH 了
你好 请问下一个新项目如何引入您的这个模块呢? 新手小白,请多指教