4

我尝试在 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 中的所有文件。我只是无法弄清楚缺少什么以及为什么设置了变量..没有设置...没用?

非常感谢您的帮助。

4

1 回答 1

1

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

于 2013-08-12T18:17:18.207 回答