最佳答案
我试图用 Visual Studio 2010和 Cygwin 在 Windows 7 x64上运行 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".
但是,如果在我的文件系统和 src/CMakeLists.txt
中都将 main.cpp 的扩展名更改为 main.c,那么一切都会按预期运行。这是从 VisualStudio 命令提示符(VisualStudio 解决方案生成器)和 Cygwin 终端(UnixMakefile 生成器)运行的情况。
知道为什么这个代码不能用吗?
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
# 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
int main()
{
return 0;
}