我試圖在Windows 7 x64上同時運行Visual Studio 2010和Cygwin上的cmake hello world程序,但似乎無法使其工作。我的目錄結構如下:CMake無法使用C++確定鏈接器語言
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擴展到主。 c在我的電子系統上和在src/CMakeLists.txt
中一切都按預期工作。從Visual Studio命令提示符(Visual Studio Solution Generator)和Cygwin Terminal(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)
的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;
}
「[...]如果我更改main.cpp的擴展名[...]」您將其更改爲什麼?名爲.cc? – JAB 2012-08-03 18:21:31
oops。遺漏了這個意外。我將它改爲'.c'。在原文中編輯。它幾乎讓我覺得沒有cpp編譯器或類似的東西,但是g ++被安裝了,Visual Studio也不應該有C++的問題。 – 2012-08-03 18:33:00