add_executable(test test.cpp)的第二个参数可以是地址吗
时间: 2024-03-09 21:49:41 浏览: 11
`add_executable`函数的第二个参数应该是一个源文件的名称,而不是一个地址。这个参数标识了编译器应该编译的源文件的名称。如果你想将源文件添加到你的项目中,你需要将源文件拷贝到你的项目目录中,并使用源文件的名称作为`add_executable`的第二个参数。例如,如果你有一个名为`test.cpp`的源文件,你可以将它拷贝到你的项目目录中,并使用以下命令将它添加到你的项目中:
```
add_executable(test test.cpp)
```
其中`test`是生成的可执行文件的名称,`test.cpp`是源文件的名称。
相关问题
CMake Error at plumbing_test/CMakeLists.txt:141 (add_executable): Cannot find source file: .cpp Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx CMake Error: CMake can not determine linker language for target: test04_param CMake Error: Cannot determine link language for target "test04_param". -- Generating done -- Build files have been written to: /home/melodic/demo03_ws/build Makefile:1216: recipe for target 'cmake_check_build_system' failed make: *** [cmake_check_build_system] Error 1 Invoking "make cmake_check_build_system" failed
这个错误是由于在CMakeLists.txt文件中找不到名为".cpp"的源文件引起的。CMake无法确定目标"test04_param"的链接语言。这可能是因为在CMakeLists.txt文件中没有正确指定源文件或链接语言的原因。请检查CMakeLists.txt文件,确保正确指定了源文件和链接语言。
add_executable cannot create target "openssl_test_qnx_aaa" because another target with the same name already exists. The existing target is an executable created in source directory "/home/docker/projects/TN_8540/code/dev/qnx_xdc/oss/openssl/test". See documentation for policy CMP0002 for more details.
这个错误的原因是因为你尝试创建一个名为 "openssl_test_qnx_aaa" 的可执行文件,但是 CMake 检测到已经有一个同名的可执行文件存在于源代码目录中 "/home/docker/projects/TN_8540/code/dev/qnx_xdc/oss/openssl/test"。这可能是因为你在 CMakeLists.txt 文件中多次定义了同一个目标,或者在不同的 CMakeLists.txt 文件中定义了同一个目标。
要解决这个问题,你需要确保在同一个 CMakeLists.txt 文件中只定义一次目标,并且确保每个目标都有唯一的名称。你还可以考虑使用不同的名称来避免与现有目标重复。你可以在 CMakeLists.txt 文件中使用以下命令来创建一个名为 "new_target_name" 的可执行文件:
```
add_executable(new_target_name source_file.cpp)
```
如果你仍然遇到问题,请查看文档 CMP0002,该文档提供了有关如何处理同名目标的更多信息。