Cmake add_executable使用不正确的参数数量调用
Cmake add_executable called with incorrect number of arguments
我正在尝试使用本教程在Linux(openSuse(上设置c ++开发环境 https://youtu.be/LKLuvoY6U0I?t=154
当我尝试构建CMake项目时,我得到了add_executable called with incorrect number of arguments
我的CMakeLists.txt:
cmake_minimum_required (VERSION 3.5)
project (CppEnvTest)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++17")
set (source_dir "${PROJECT_SOURCE_DIR}/src/")
file (GLOB source_files "${source_dir}/*.cpp")
add_executable (CppEnvTest ${source_files})
我 build.sh:
#!/bin/sh
cmake -G "CodeLite - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug
我的终端输出:
/Dev/CppEnvTest/src> ./build.sh
CMake Error at CMakeLists.txt:10 (add_executable):
add_executable called with incorrect number of arguments
-- Configuring incomplete, errors occurred!
要扩展@arrowd的答案(这是正确的(,您有几个选项可以列出源文件。file(GLOB ...)
,您的方法将只查找与当前目录中.cpp
匹配的源文件。如果您的项目结构使得您在${source_dir}
中嵌套了目录,则需要递归选项:
file (GLOB_RECURSE source_files "${source_dir}/*.cpp")
这将递归搜索,查找该目录和任何嵌套目录中的所有.cpp
文件。
您还可以使用set
执行暴力破解方法,这是 CMake 的最佳选择,方法是执行以下操作:
set(source_files
${source_dir}/mySrcs1/Class1.cpp
${source_dir}/mySrcs1/Class2.cpp
${source_dir}/mySrcs1/Class3.cpp
...
${source_dir}/mySrcs42/testClass1.cpp
${source_dir}/mySrcs42/testClass2.cpp
...
)
您的source_files
变量似乎为空。通过在CMakeLists.txt
中的某处添加message("source_files: ${source_files}")
来验证这一点。
相关文章:
- 在函数中使用 const int size 参数创建数组会在 Visual Studio 中抛出错误 C++:表达式的计
- 如何在模板函数中实例化其长度使用模板参数的数组
- 基于参数创建数组
- Pybind11 默认参数 numpy 数组或 None
- 有没有办法根据命令行参数定义数组大小?运行时与编译时实例化?
- 更改为参数的数组的值
- 根据 C++11 中的模板参数选择数组大小
- 是否可以使用C 函数中的const int参数创建数组
- 根据参数将数组分成 5 个不同的数组
- 你究竟如何通过函数的参数传递数组?
- 函数参数中数组大小未指定
- 数组作为函数参数查找数组长度时出错
- 如何使用函数参数设置数组大小
- 可变参数模板数组调用未定义的行为
- 提升 1.55,而 13 信号参数错误数
- 指向作为模板参数的数组的指针
- C++可变参数模板数组/访问元素
- 在 c++ 中没有参数的数组
- 具有双精度参数的数组
- 使用 C++11 的 begin() 和 end() 函数通过参数确定数组维度