CMake unable to determine linker language with C++(CMake 无法使用 C++ 确定链接器语言)
问题描述
我正在尝试使用 Visual Studio 2010 和 Cygwin 在 Windows 7 x64 上运行 cmake hello world 程序,但似乎两者都无法工作.我的目录结构如下:
I'm attempting to run a cmake hello world program on Windows 7 x64 with both Visual Studio 2010 and Cygwin, but can't seem to get either to work. My directory structure is as follows:
HelloWorld
-- CMakeLists.txt
-- src/
-- -- CMakeLists.txt
-- -- main.cpp
-- build/
我做了一个 cd build
后跟一个 cmake ..
,然后得到一个错误说明
I do a cd build
followed by a cmake ..
, and get an error stating that
CMake Error: CMake can not determine linker language for target:helloworld
CMake Error: Cannot determine link language for target "helloworld".
但是,如果我在我的文件系统和 src/CMakeLists.txt
中将 main.cpp 的扩展名更改为 main.c,一切都会按预期进行.这是从 Visual Studio 命令提示符(Visual Studio 解决方案生成器)和 Cygwin 终端(Unix Makefiles 生成器)运行的情况.
However, if I change the extension of main.cpp to main.c both on my filsystem and in src/CMakeLists.txt
everything works as expected. This is the case running from both the Visual Studio Command Prompt (Visual Studio Solution Generator) and the Cygwin Terminal (Unix Makefiles Generator).
知道为什么这段代码不起作用吗?
Any idea why this code wouldn't work?
CMakeLists.txt
CMakeLists.txt
PROJECT(HelloWorld C)
cmake_minimum_required(VERSION 2.8)
# include the cmake modules directory
set(CMAKE_MODULE_PATH ${HelloWorld_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
add_subdirectory(src)
src/CMakeLists.txt
src/CMakeLists.txt
# Include the directory itself as a path to include directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Create a variable called helloworld_SOURCES containing all .cpp files:
set(HelloWorld_SOURCES main.cpp)
# Create an executable file called helloworld from sources:
add_executable(hello ${HelloWorld_SOURCES })
src/main.cpp
src/main.cpp
int main()
{
return 0;
}
推荐答案
尝试改变
PROJECT(HelloWorld C)
进入
PROJECT(HelloWorld C CXX)
或者只是
PROJECT(HelloWorld)
参见:http://www.cmake.org/cmake/help/v2.8.8/cmake.html#command:project
这篇关于CMake 无法使用 C++ 确定链接器语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CMake 无法使用 C++ 确定链接器语言


基础教程推荐
- 常量变量在标题中不起作用 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 我有静态或动态 boost 库吗? 2021-01-01