CMake가 C ++로 링커 언어를 결정할 수 없습니다.
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".
그러나 내 파일 시스템에서 main.cpp의 확장자를 main.c로 변경하면 src/CMakeLists.txt모든 것이 예상대로 작동합니다. 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;
}
변경 시도
PROJECT(HelloWorld C)
으로
PROJECT(HelloWorld C CXX)
아니면 그냥
PROJECT(HelloWorld)
참조 : http://www.cmake.org/cmake/help/v2.8.8/cmake.html#command:project
또한 언급 한 오류가 있습니다.
CMake Error: CMake can not determine linker language for target:helloworld
CMake Error: Cannot determine link language for target "helloworld".
In my case this was due to having C++ files with the .cc extension.
If CMake is unable to determine the language of the code correctly you can use the following:
set_target_properties(hello PROPERTIES LINKER_LANGUAGE CXX)
The accepted answer that suggests appending the language to the project() statement simply adds more strict checking for what language is used (according to the documentation), but it wasn't helpful to me:
Optionally you can specify which languages your project supports. Example languages are CXX (i.e. C++), C, Fortran, etc. By default C and CXX are enabled. E.g. if you do not have a C++ compiler, you can disable the check for it by explicitly listing the languages you want to support, e.g. C. By using the special language "NONE" all checks for any language can be disabled. If a variable exists called CMAKE_PROJECT__INCLUDE_FILE, the file pointed to by that variable will be included as the last step of the project command.
In my case, it was just because there were no source file in the target. All of my library was template with source code in the header. Adding an empty file.cpp solved the problem.
Confusing as it might be, the error also happens when a cpp file included in the project does not exist.
If you list your source files in CMakeLists.txt and mistakenly type a file name then you get this error.
I also faced a similar error while compiling my C-based code. I fixed the issue by correcting the source file path in my cmake file. Please check the source file path of each source file mentioned in your cmake file. This might help you too.
By default the JNI Native folder is named as jni . Renaming it to cpp fixed the issue
A bit unrelated answer to OP but for people like me with a somewhat similar problem.
Use Case: Ubuntu (C, Clion, Auto-completion):
I had the same error,
CMake Error: Cannot determine link language for target "hello".
set_target_properties(hello PROPERTIES LINKER_LANGUAGE C) help fixes that problem but the headers aren't included to the project and the autocompletion wont work.
This is what i had
cmake_minimum_required(VERSION 3.5)
project(hello)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES ./)
add_executable(hello ${SOURCE_FILES})
set_target_properties(hello PROPERTIES LINKER_LANGUAGE C)
No errors but not what i needed, i realized including a single file as source will get me autocompletion as well as it will set the linker to C.
cmake_minimum_required(VERSION 3.5)
project(hello)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES ./1_helloworld.c)
add_executable(hello ${SOURCE_FILES})
I managed to solve mine, by changing
add_executable(file1.cpp)
to
add_executable(ProjectName file1.cpp)
In my case, implementing a member function of a class in a header file cause this error. Separating interface (in x.h file) and implementation (in x.cpp file) solves the problem.
참고URL : https://stackoverflow.com/questions/11801186/cmake-unable-to-determine-linker-language-with-c
'Nice programing' 카테고리의 다른 글
| Google 크롬에서 jsfiddle.net의 자바 스크립트 검사 (0) | 2020.11.12 |
|---|---|
| Mongoose / Node.js에서 여러 문서를 동시에 저장하려면 어떻게해야합니까? (0) | 2020.11.12 |
| Maven의 외부 라이브러리가있는 Android Studio에서 네임 스페이스 '앱'이 바인딩되지 않았습니다. (0) | 2020.11.12 |
| HH : MM : SS 형식의 시간을 초로 만 변환 하시겠습니까? (0) | 2020.11.12 |
| Spring이 존재하는 경우 Bean xml 구성 파일을 찾을 수 없습니다. (0) | 2020.11.12 |