CMake cannot determine linker language for target

前端 未结 2 1953
梦如初夏
梦如初夏 2020-12-01 18:45

To start off, I\'ve taken a look at this post and couldn\'t find a solution to my problem. I\'m attempting to set up a library in a folder using two header files and link wi

相关标签:
2条回答
  • 2020-12-01 19:45

    As this is the canonical answer for "CMake cannot determine linker language for target", I found that when trying to link C code to c++ code and having everything else seemingly be right, this random forum post was the answer:

    Try changing

    PROJECT(HelloWorld C)

    into

    PROJECT(HelloWorld C CXX)

    or just

    PROJECT(HelloWorld)

    (Source : https://exceptionshub.com/cmake-unable-to-determine-linker-language-with-c.html)

    I noticed you are already doing this in your code, but I wanted to leave this here in case others have this same error for a different reason

    0 讨论(0)
  • 2020-12-01 19:49

    You have added target for creating container library. That target contains only header files. See CMake documentation

    add_library: Add a library to the project using the specified source files.

    add_library( [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] source1 source2 ... sourceN)

    Adds a library target called to be built from the source files listed in the command invocation. The corresponds to the logical target name and must be globally unique within a project. The actual file name of the library built is constructed based on conventions of the native platform (such as lib.a or .lib).

    But you can not build library just from header files without any cpp file. That's why you got such error.

    0 讨论(0)
提交回复
热议问题