天天看点

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. 

继续阅读