CMake:无法创建目标,因为已经存在另一个具有相同名称的目标

时间:2018-09-29 22:41:47

标签: cmake pthreads

我正在尝试使用cmake安装plexe-sumo。我遵循了plexe.car2x.org上的教程,结果如下:

-- CMAKE_BUILD_TYPE: Release
-- CMAKE_BINARY_DIR: /home/cc/src/plexe-sumo/build-release
-- CMAKE_SOURCE_DIR: /home/cc/src/plexe-sumo
-- 
-- Platform: 
--     Host: Linux4.15.0-34-genericx86_64
--     CMake: 3.12.2
--     CMake generator: Unix Makefiles
--     CMake build tool: /usr/bin/make
-- 
-- Found Proj: /usr/lib/x86_64-linux-gnu/libproj.so
CMake Error at /usr/local/share/cmake-3.12/Modules/UseSWIG.cmake:627 (add_custom_target):
  add_custom_target cannot create target "libsumo_swig_compilation" because
  another target with the same name already exists.  The existing target is a
  custom target created in source directory
  "/home/cc/src/plexe-sumo/src/libsumo".  See documentation for policy
  CMP0002 for more details.
Call Stack (most recent call first):
  src/libsumo/CMakeLists.txt:39 (SWIG_ADD_LIBRARY)


-- Enabled features: Linux-4.15.0-34-generic Proj GUI GDAL OSG GL2PS SWIG
-- Configuring incomplete, errors occurred!

“ / home / cc / src / plexe-sumo / src / libsumo”下没有名为“ libsumo_swig_compilation”的文件。

然后,我检查了错误日志文件,但显示的错误与pthread有关,即“未定义对pthread_creat的引用”和“找不到-lpthreads”。其实我的pthread库安装在'libc6:/lib/x86_64-linux-gnu/libpthread.so.0'。

所以我想知道这里的确切问题是什么以及如何解决。我正在使用带有ubuntu 16的虚拟机。感谢您的帮助!

以下是错误日志文件:

Determining if the pthread_create exist failed with the following output:
Change Dir: /home/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_050d5/fast"
/usr/bin/make -f CMakeFiles/cmTC_050d5.dir/build.make CMakeFiles/cmTC_050d5.dir/build
make[1]: Entering directory '/home/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_050d5.dir/CheckSymbolExists.c.o
/usr/bin/cc   -Wall -pedantic -Wextra    -o CMakeFiles/cmTC_050d5.dir/CheckSymbolExists.c.o   -c /home/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp/CheckSymbolExists.c
/home/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp/CheckSymbolExists.c: In function ‘main’:
/home/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp/CheckSymbolExists.c:8:11: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
   return ((int*)(&pthread_create))[argc];
           ^
Linking C executable cmTC_050d5
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_050d5.dir/link.txt --verbose=1
/usr/bin/cc  -Wall -pedantic -Wextra     -rdynamic CMakeFiles/cmTC_050d5.dir/CheckSymbolExists.c.o  -o cmTC_050d5 
CMakeFiles/cmTC_050d5.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x16): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_050d5.dir/build.make:86: recipe for target 'cmTC_050d5' failed
make[1]: *** [cmTC_050d5] Error 1
make[1]: Leaving directory '/home/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp'
Makefile:121: recipe for target 'cmTC_050d5/fast' failed
make: *** [cmTC_050d5/fast] Error 2

File /home/cc/src/plexe-sumo/build-release/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/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_9f654/fast"
/usr/bin/make -f CMakeFiles/cmTC_9f654.dir/build.make CMakeFiles/cmTC_9f654.dir/build
make[1]: Entering directory '/home/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_9f654.dir/CheckFunctionExists.c.o
/usr/bin/cc   -Wall -pedantic -Wextra -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTC_9f654.dir/CheckFunctionExists.c.o   -c /usr/local/share/cmake-3.12/Modules/CheckFunctionExists.c
Linking C executable cmTC_9f654
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_9f654.dir/link.txt --verbose=1
/usr/bin/cc  -Wall -pedantic -Wextra -DCHECK_FUNCTION_EXISTS=pthread_create    -rdynamic CMakeFiles/cmTC_9f654.dir/CheckFunctionExists.c.o  -o cmTC_9f654 -lpthreads 
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_9f654.dir/build.make:86: recipe for target 'cmTC_9f654' failed
make[1]: *** [cmTC_9f654] Error 1
make[1]: Leaving directory '/home/cc/src/plexe-sumo/build-release/CMakeFiles/CMakeTmp'
Makefile:121: recipe for target 'cmTC_9f654/fast' failed
make: *** [cmTC_9f654/fast] Error 2

1 个答案:

答案 0 :(得分:0)

我的假设是,这确实是只有新cmake才会显示的行为。您可以尝试在CMakeLists.txt的java部分中重命名所有对libsumo的引用,或在此处使用主行相扑的CMakeLists:https://github.com/eclipse/sumo/blob/master/src/libsumo/CMakeLists.txt