CMake 编译失败

CMake fails compilation

本文关键字:失败 编译 CMake      更新时间:2023-10-16

我正在尝试在 openSUSE 13.2 上编译 cocos2d-x 3.5,.log文件中出现以下错误:

Determining if the pthread_create exist failed with the following output:
Change Dir: /home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/gmake" "cmTryCompileExec846787943/fast"
/usr/bin/gmake -f CMakeFiles/cmTryCompileExec846787943.dir/build.make CMakeFiles/cmTryCompileExec846787943.dir/build
gmake[1]: Entering directory '/home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec846787943.dir/CheckSymbolExists.c.o
/usr/bin/cc   -fno-exceptions -std=c99    -o CMakeFiles/cmTryCompileExec846787943.dir/CheckSymbolExists.c.o   -c /home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTryCompileExec846787943
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec846787943.dir/link.txt --verbose=1
/usr/bin/cc   -fno-exceptions -std=c99     CMakeFiles/cmTryCompileExec846787943.dir/CheckSymbolExists.c.o  -o cmTryCompileExec846787943 -rdynamic 
CMakeFiles/cmTryCompileExec846787943.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x16): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTryCompileExec846787943.dir/build.make:88: recipe for target 'cmTryCompileExec846787943' failed
gmake[1]: *** [cmTryCompileExec846787943] Error 1
gmake[1]: Leaving directory '/home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp'
Makefile:118: recipe for target 'cmTryCompileExec846787943/fast' failed
gmake: *** [cmTryCompileExec846787943/fast] Error 2
File /home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <pthread.h>
int main(int argc, char** argv)
{
  (void)argv;
#ifndef pthread_create
  return ((int*)(&pthread_create))[argc];
#else
  (void)argc;
  return 0;
#endif
}
Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/gmake" "cmTryCompileExec3838281423/fast"
/usr/bin/gmake -f CMakeFiles/cmTryCompileExec3838281423.dir/build.make CMakeFiles/cmTryCompileExec3838281423.dir/build
gmake[1]: Entering directory '/home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec3838281423.dir/CheckFunctionExists.c.o
/usr/bin/cc   -fno-exceptions -std=c99 -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTryCompileExec3838281423.dir/CheckFunctionExists.c.o   -c /usr/share/cmake/Modules/CheckFunctionExists.c
Linking C executable cmTryCompileExec3838281423
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec3838281423.dir/link.txt --verbose=1
/usr/bin/cc   -fno-exceptions -std=c99 -DCHECK_FUNCTION_EXISTS=pthread_create    CMakeFiles/cmTryCompileExec3838281423.dir/CheckFunctionExists.c.o  -o cmTryCompileExec3838281423 -rdynamic -lpthreads 
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTryCompileExec3838281423.dir/build.make:88: recipe for target 'cmTryCompileExec3838281423' failed
gmake[1]: *** [cmTryCompileExec3838281423] Error 1
gmake[1]: Leaving directory '/home/humman/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build/CMakeFiles/CMakeTmp'
Makefile:118: recipe for target 'cmTryCompileExec3838281423/fast' failed
gmake: *** [cmTryCompileExec3838281423/fast] Error 2

我手动安装了依赖项和库,但仍然收到此错误。有谁知道发生了什么?

注意:当我尝试编译时,前 2 行是:

~/android-dev/cocos2d-x-3.5/cocos2d-x-3.5/build/linux-build> cmake ../..
CMake Error at CMakeLists.txt:35 (cmake_policy):
  Policy "CMP0054" is not known to this version of CMake.

谢谢:D

已解决,我刚刚在 CMakeList.txt 文件中注释掉了这一行

#if(CMAKE_VERSION VERSION_GREATER 3)
    #cmake_policy(SET CMP0054 NEW)
#endif() 

但是现在,当我使用 make 命令(无论在哪里,使用 NetBeans 或终端)时,它以 98% 的此错误结束(大约 15 分钟编译后)

[ 98%] Built target cocos2d
[ 98%] Built target MyGame_CORE_PRE_BUILD
MyGame_PRE_BUILD ...
[ 98%] Built target MyGame_PRE_BUILD
Linking CXX executable bin/MyGame
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: lib/libcocos2d.a(CCSpriteFrameCache.cpp.o): undefined reference to symbol '_ZSt28_Rb_tree_rebalance_for_erasePSt18_Rb_tree_node_baseRS_@@GLIBCXX_3.4'
/usr/lib64/libstdc++.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/MyGame.dir/build.make:164: recipe for target 'bin/MyGame' failed
make[2]: *** [bin/MyGame] Error 1
CMakeFiles/Makefile2:64: recipe for target 'CMakeFiles/MyGame.dir/all' failed
make[1]: *** [CMakeFiles/MyGame.dir/all] Error 2
Makefile:76: recipe for target 'all' failed
make: *** [all] Error 2

知道吗??


解决了,如果有人有同样的问题,只需将 cmake 与参数 -pthread 一起使用,然后您就可以使用 make 进行构建。如果要使用 NetBeans 进行构建,则只需保留 -G "Unix..."参数并在 CMakefile 中添加.txt行:set(-pthread) - 我确实在顶部添加了它 - 仅此而已,它应该一切正常:D干杯!

似乎是一个长期存在的CMake错误。其他问题,CMake 感到困惑,并报告了这个虚假问题而不是真正的错误。

在CMakeLists.txt文件中查找"线程"并暂时删除它。