CMake-使用错误的参数数量调用add_executable [英] CMake - add_executable called with incorrect number of arguments

查看:442
本文介绍了CMake-使用错误的参数数量调用add_executable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试组织一个C ++项目,该项目开始包含很多文件。我想创建两个使用Cmake共享某些源文件的可执行文件。我在这里找到了一个有趣的过程:

I am trying to organize a C++ project which starts to have a lot of files. I would like to create two executables which share some source file using Cmake. I have found an interesting procedure here:

如何在另一个文件夹中添加源文件

下面是我的版本

file(GLOB Common_sources RELATIVE "Common" "*cpp")
file(GLOB Mps_sources RELATIVE "Mps" "*.cpp")                 
file(GLOB Mss_sources RELATIVE "Mss" "*.cpp") 

add_executable(test_mss ${Common_sources} ${Mss_sources}) 
add_executable(test_mps ${Common_sources} ${Mps_sources})

但是CMake抱怨

CMake Error at src/CMakeLists.txt:44 (add_executable):
add_executable called with incorrect number of arguments

CMake Error at src/CMakeLists.txt:45 (add_executable):
add_executable called with incorrect number of arguments

它说要查看 CMakeOutput.log ,但是文件是真的太久了,我找不到有用的信息。

It says to look at CMakeOutput.log, but the file is really too long, I can not find useful information.

我检查了CMake文档,看来它可能需要第二个来源作为附加参数。 https://cmake.org/cmake/help/v3.0/ command / add_executable.html

I checked the CMake documentation, it seems that it can take a second source as an additional argument. https://cmake.org/cmake/help/v3.0/command/add_executable.html

我想找到此错误的来源。我感觉这里缺少明显的东西。

I would like to find the source of this bug. I have the feeling that I am missing something obvious here.

推荐答案

您收到的错误是因为将源列表传递给 add_executable 实际上是空的。

The error you get is because source list, passed to add_executable, is actually empty.

Common / 子目录是:

file(GLOB Common_sources "Common/*.cpp")






在命令文件(GLOB) RELATIVE 选项未指定搜索目录。相反,它只是告诉CMake生成相对路径而不是绝对路径:


In command file(GLOB) RELATIVE option doesn't specify search directory. Instead, it just tells CMake to generate relative paths instead of absolute:


如果指定了RELATIVE标志,则结果将作为给定路径的相对路径返回。

If RELATIVE flag is specified, the results will be returned as relative paths to the given path.

假设

file(GLOB Common_sources "Common/*.cpp")
# gets: /<path-to-source>/Common/my_source.cpp

然后(还请注意相对选项中的绝对路径

then (also note to absolute path in RELATIVE option)

file(GLOB Common_sources RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/Common" "Common/*.cpp")
# gets: my_source.cpp

和(当文件不在 RELATIVE 目录下时)

and (when files are not under RELATIVE directory)

file(GLOB Common_sources RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/Mps" "Common/*.cpp")
# gets: ../Common/my_source.cpp

这篇关于CMake-使用错误的参数数量调用add_executable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆