[英]segmentation fault using static libraries with std::jthread (g++-10)
[英]the ltbb flag in g++-10 compiler
我已經安裝了 tbb 庫: brew install tbb
。 但是當我試圖編譯一個程序時:
g++-10 hello.cpp -o hello --std=c++2a -Wall -ltbb -lpthread -O3
我收到錯誤:
ld: library not found for -ltbb
collect2: error: ld returned 1 exit status
所有其他標志都可以正常工作。
如果我使用-tbb
而不是ltbb
,我會得到
g++-10: error: unrecognized command-line option '-tbb'
我如何使這項工作?
出現此錯誤是因為鏈接器在您的 Mac 上找不到libtbb.dylib
。 它找不到它,因為 Homebrew 將 TBB 庫安裝在一個非標准文件夾中(默認情況下,不在您的DYLD_LIBRARY_PATH
環境變量中,這是ld
用來搜索.dylib
s的)。
我遇到了同樣的問題,發現libtbb.dylib
(以及所有其他用brew
安裝的庫的符號鏈接)在/opt/homebrew/lib
。 因此,您可以在運行g++
命令之前執行諸如export DYLD_LIBRARY_PATH=/opt/homebrew/lib:${DYLD_LIBRARY_PATH}
,或者如果您使用的是像 CMake 這樣的構建系統,則可以添加類似link_directories("/opt/homebrew/lib")
在你的CMakeLists.txt
)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.