有人可以解释为什么我的cmake文件无法构建cpp文件吗? [英] Can someone explain why my cmake file fails to build my cpp file?

查看:341
本文介绍了有人可以解释为什么我的cmake文件无法构建cpp文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有以下CMakeLists.txt文件尝试构建我的main.cpp文件。

So I've got the following CMakeLists.txt file to try and build my main.cpp file.

     project(shell)

     set(extra_flags = -std=c++11 -Werror -Wall -Wextra)
     set(CMAKE_CXX_FLAGS $(CMAKE_CXX_FLAGS) $(extra_flags))
     add_executable(shell main.cpp)

此时,我只是想用Hello World程序构建它只是为了确保一切正常。但是标志是我需要编写的其余程序的标志。调用 cmake的实际过程工作正常。但是,当我使用 make 时,出现以下错误:

At this point, I am just trying to build it with a Hello World program just to make sure everything works. But the flags are there for the rest of the program that I need to write. The actual process of calling cmake . works just fine, but when I use make I get the following error:

[100%] Building CXX object CMakeFiles/shell.dir/main.cpp.o
c++: fatal error: no input files
compilation terminated.
/bin/sh: 1: -o: not found 
CMakeFiles/shell.dir/build.make:54: recipe for target 'CMakeFiles/shell.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/shell.dir/main.cpp.o] Error 127
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/shell.dir/all' failed
make[1]: *** [CMakeFiles/shell.dir/all] Error 2
Makefile:72: recipe for target 'all' failed
make: *** [all] Error 2

我是Ubuntu和命令行的新手,所以任何帮助将不胜感激。 / p>

I'm new to Ubuntu and the command line, so any help would be greatly appreciated.

推荐答案


  • 确保使用大括号$ {}(上面的注释)

  • 如果要重置(上面的评论),请确保删除CMakeCache.txt

  • 我也养成了始终使用 set的习惯(CMAKE_CXX_FLGAS $ {CMAKE_CXX_FLAGS} $ {extra_flags})而不是 set(CMAKE_CXX_FLGAS $ {CMAKE_CXX_FLAGS} $ {extra_flags})减少我的任何应用程序的头痛。

  • 使用 make VERBOSE = 1 查看CMake实际运行的命令。然后,您可以直接弄乱该命令并查看其工作方式。

  • 如果只是 HelloWorld!,请尝试省略 -std = c ++ 11 标志(或其他任何标志,真的)并查看。

    • Make sure you use curly brackets ${} (comment above)
    • Make sure you delete your CMakeCache.txt if you want a "reset" (comment above)
    • I also developed the habit to always use set(CMAKE_CXX_FLGAS "${CMAKE_CXX_FLAGS} ${extra_flags}") instead of set(CMAKE_CXX_FLGAS ${CMAKE_CXX_FLAGS} ${extra_flags}) which proved to cause less headache in any of my applications. Try that as well.
    • Use make VERBOSE=1 to see which commands CMake actually runs. You then can mess with the command directly and see how you get it to work.
    • If it's just HelloWorld!, try leaving out the -std=c++11 flag (or any flags, really) and see.
    • 这篇关于有人可以解释为什么我的cmake文件无法构建cpp文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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