Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ CMake错误:目标名称“测试”已保留或无效_C++_Macos_Cmake - Fatal编程技术网

C++ CMake错误:目标名称“测试”已保留或无效

C++ CMake错误:目标名称“测试”已保留或无效,c++,macos,cmake,C++,Macos,Cmake,环境: MAC os:10.12.6 CMake版本:3.8 CMake Error at CMakeLists.txt:7 (add_executable): The target name "test" is reserved or not valid for certain CMake features, such as generator expressions, and may result in undefined behavior. 这是我的CMakeLists.txt: c

环境:

MAC os:10.12.6

CMake版本:3.8

CMake Error at CMakeLists.txt:7 (add_executable):
  The target name "test" is reserved or not valid for certain CMake features, such as generator expressions, and may result in undefined behavior.
这是我的CMakeLists.txt:

cmake_minimum_required(VERSION 3.8)
project(test)

# set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)
add_executable(test ${SOURCE_FILES})

我该怎么办?

CMake包含一些用于自动测试的功能。也就是说,有一个命令和相关的东西,所以名称测试是保留的。只需将测试重命名为其他内容。

这可能与CMakeLists.txt中的语法有关。 我在试验Android NDK时也遇到了类似的错误

在我的例子中,我在CMakeLists.txt中声明C++文件时出错。声明C++文件的正确方法如下:

add_library( 
           Your-library-name 

           # Sets the library as a shared library.
           SHARED

           # Provides a relative path to your source file(s).
           your-cpp-file1.cpp
           your-cpp-file2.cpp
           your-cpp-file3.cpp 
       )

我想不是这样的。我输入了一个完全任意的名称,但它失败了