CMake unable to determine linker language with C++

后端 未结 10 1714
野趣味
野趣味 2020-11-28 06:41

I\'m attempting to run a cmake hello world program on Windows 7 x64 with both Visual Studio 2010 and Cygwin, but can\'t seem to get either to work. My directory structure is

10条回答
  •  星月不相逢
    2020-11-28 07:32

    I want to add another solution in case a library without any source files shall be build. Such libraries are also known as header only libraries. By default add_library expects at least one source file added or otherwise the mentioned error occurs. Since header only libraries are quite common, cmake has the INTERFACE keyword to build such libraries. The INTERFACE keyword is used as shown below and it eliminates the need for empty source files added to the library.

    add_library(myLibrary INTERFACE)
    target_include_directories(myLibrary INTERFACE {CMAKE_CURRENT_SOURCE_DIR})
    

    The example above would build a header only library including all header files in the same directory as the CMakeLists.txt. Replace {CMAKE_CURRENT_SOURCE_DIR} with a path in case your header files are in a different directory than the CMakeLists.txt file.

    Have a look at this blog post or the cmake documentation for further info regarding header only libraries and cmake.

提交回复
热议问题