114

VisualStudio2010とCygwinの両方を使用してWindows7x64でcmakehelloworldプログラムを実行しようとしていますが、どちらも機能しないようです。私のディレクトリ構造は次のとおりです。

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 Solution Generator)と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)

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;
}
4

10 に答える 10

89

私の場合は、ターゲットにソース ファイルがなかっただけです。私のコードはすべて、ヘッダー ファイルにソース コードを含むテンプレートでした。空の file.cpp を追加すると問題が解決しました。

于 2015-04-08T14:52:59.400 に答える
50

変更してみる

PROJECT(HelloWorld C)

の中へ

PROJECT(HelloWorld C CXX)

あるいは単に

PROJECT(HelloWorld)

参照: http://www.cmake.org/cmake/help/v2.8.8/cmake.html#command:project

于 2012-08-03T19:19:57.893 に答える