Getting a CMake Error: Cannot specify link libraries for target which is not built by the project

后端 未结 4 1400
萌比男神i
萌比男神i 2020-11-29 10:59

I am implementing CMake in my code but I\'m getting the error

\"Cannot specify link libraries for target \"Qt5::Widgets\" which is not built by the p

相关标签:
4条回答
  • 2020-11-29 11:21

    Set you_lib_name before setting target_link_libraries

    set(you_lib_name libname)
    target_link_libraries(you_lib_name Qt5::Widgets Qt5::Core) 
    
    0 讨论(0)
  • 2020-11-29 11:23

    In addition to the accepted answer: An important detail is to place target_link_libraries after the add_executable and find_package lines, so all linked components are known.

    0 讨论(0)
  • 2020-11-29 11:35

    The first argument of target_link_libraries is the target name:

    target_link_libraries(eCAD Qt5::Widgets Qt5::Core) 
    
    0 讨论(0)
  • 2020-11-29 11:42

    Also, do not confuse target name with the project name:

    • a command project specifies a project name, but
    • a target is the one created with add_executable, add_library or add_custom_target.

    The error message is about the target.

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