天天看點

cmake常見報錯

1. add_library cannot create target “XXXX“ because another target with the same name already exists.

CMake Error at CMakeLists.txt

add_library cannot create target “xxx” because another target with the same name already exists. The existing target is an executable created in source directory “/root/xxx/xxx”.See documentation for policy CMP0002 for more details.

答:

在使用cmake進行編譯時出現上述問題,最大的可能是編譯生成的應用程式名稱和生成的庫檔案名稱是一樣而導緻的錯誤。是以需要檢查add_executable内的程式名稱和add_library的庫檔案名稱。庫檔案的名稱一般來說不與應用程式名稱相同。修改後可能可解決上述問題。

2. C++編譯出現錯誤(.text+0x20): undefined reference to `main'

答:

很可能是add_executable()中沒加main()函數所在的cpp檔案。

cmake常見報錯
cmake常見報錯

3. cmakelists.txt undefined reference to symbol 'dlclose@@GLIBC_2.2.5'

答:可以通過在CmakeLists.txt中添加-ldl編譯選項解決 undefined reference to `xxxx'問題 。

cmake常見報錯
cmake常見報錯

4. 

繼續閱讀