我试图同时在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".
但是,如果我将filsystem和src/CMakeLists.txt
所有正常工作的main.cpp扩展名更改为main.c。从Visual Studio命令提示符(Visual Studio解决方案生成器)和Cygwin终端(Unix Makefiles生成器)运行都是这种情况。
知道为什么这段代码行不通吗?
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;
}