我正在尝试在Windows 7 x64上使用Visual Studio 2010和Cygwin运行一个cmake hello world程序,但似乎两者都无法正常工作。我的目录结构如下:
HelloWorld
-- CMakeLists.txt
-- src/
-- -- CMakeLists.txt
-- -- main.cpp
-- build/
我执行 cd build
命令,然后执行 cmake ..
命令,但是出现了以下错误:
CMake Error: CMake can not determine linker language for target:helloworld
CMake Error: Cannot determine link language for target "helloworld".
然而,如果我将main.cpp的扩展名更改为main.c,无论是在我的文件系统上还是在src / CMakeLists.txt中,一切都按预期工作。这适用于从Visual Studio命令提示符(Visual Studio解决方案生成器)和Cygwin终端(Unix Makefiles Generator)运行的情况。有任何想法为什么这段代码不起作用吗?
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)
源代码目录下的 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 })
主要代码/main.cpp
int main()
{
return 0;
}
PROJECT(HelloWorld C)
更改为PROJECT(HelloWorld CXX)
。C 和 C++ 是不同的编程语言。 - rustyx