【问题标题】:Cmake very simple set failureCmake非常简单的设置失败
【发布时间】:2013-04-17 23:37:10
【问题描述】:

我尝试在 ubuntu 12.04、cmake 2.8.7 中使用最简单的 helloworld 示例开始使用 cmake。首先我尝试了来自:

http://www.elpauer.org/stuff/learning_cmake.pdf

project( helloworld )
set( SRCFILES helloWorld.cpp )
add_executable( helloWorld ${SRCFILES} )

我在 CMakeLists.txt 旁边只有一个名为“helloWorld.cpp”的源文件。我创建了一个名为“configure”的目录,进入内部并命名为“cmake ..”。我得到以下信息:

-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at CMakeLists.txt:3 (add_executable):
  add_executable called with incorrect number of arguments


-- Configuring incomplete, errors occurred!

试图找出问题所在,我得到了以下所有更改:

project( helloworld )
set( SRCFILES helloWorld.cpp )
message ( "src ${SRCFILES}" )
set(x helloWorld.cpp)
set(y 2)
message(${x}${y})
message(${x}${y})
message(${SRCFILES})

add_executable( helloWorld ${SRCFILES} )
add_executable( helloWorld ${x} )
add_executable( helloWorld helloWorld.cpp )

结果再次以:

结束
...
-- Detecting CXX compiler ABI info - done
src 
helloWorld.cpp2
helloWorld.cpp2
CMake Error at CMakeLists.txt:8 (message):
  message called with incorrect number of arguments


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


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


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


-- Configuring incomplete, errors occurred!

最后,琐碎的

project( helloworld )
add_executable( helloWorld helloWorld.cpp )

失败:

...
-- Detecting CXX compiler ABI info - done
CMake Error at CMakeLists.txt:2 (add_executable):
  add_executable called with incorrect number of arguments


-- Configuring incomplete, errors occurred!

在每次试用之前,我都会删除 compile 中的所有文件。我只是无法弄清楚缺少什么以及为什么设置了变量..没有设置...没用?

非常感谢您的帮助。

【问题讨论】:

  • 这一切对我来说都很好,并且可以在带有 CMake v2.8.10.2 的 Windows 上运行(尽管 3 个 add_executable 命令需要不同的 exe 名称)。您可以尝试在所有(s 之后删除所有空格以查看是否可以解决问题吗?看起来 set(x helloWorld.cpp) 有效,但 set( SRCFILES helloWorld.cpp ) 没有。
  • 删除空格不起作用:(。无论如何,set(x ...) 仅在 message 中有效,但在 add_executable 中使用时仍然出错。另一个问题是,我一直在配置很多带有 cmake 的源代码分发,它工作得很好,所以我真的不知道这里有什么问题。
  • 是的,但是add_executable 调用在大括号之后也都有空格 - 你是否也删除了那些(我真的很害怕我抓住稻草)。
  • 尝试添加project(helloworld C CXX)
  • 哇!我添加了C CXX,它开始工作了!奇怪的是,现在它在没有它的情况下也可以工作:S。好吧,我真的很感谢你的帮助,解决了!谢谢

标签: cmake


【解决方案1】:

您可能和我一样从网页中复制了相同的损坏文本。文本中必须有一些隐藏字符。手动重写该行也为我解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-27
    • 1970-01-01
    • 2013-01-13
    • 2016-11-23
    • 2014-01-30
    相关资源
    最近更新 更多