qq_34731182
哈哈coding
采纳率60%
2019-11-22 16:37

一个简单的CMakeLists语法问题

5
已结题
cmake_minimum_required( VERSION 2.8 )
project ( code_test )

set( CMAKE_CXX_COMPILER "g++" )
set( CMAKE_BUILD_TYPE "Debug" )
set( CMAKE_CXX_FLAGS "-std=c++11 -O0" )

include_directories(
    /home/lihua/anaconda3/include/python3.7m
)

link_directories(
    /home/lihua/anaconda3/lib
)

target_link_libraries(code_test
    libpython3.7m.so
)

add_executable( run_test test.cpp )
target_link_libraries(run_test code_test)

编译的时候在target_link_libraries为什么会报下面这个错误:

Cannot specify link libraries for target "code_test" which is not built by
this project.

  • 点赞
  • 收藏
  • 复制链接分享

1条回答

  • bobhuang bobhuang 2年前

    target_link_libraries定义输出目标依赖哪些库。
    需要用add_library先告诉CMake有个目标是code_test。相应的,输出libcode_test.a或者libcode_test.so。

    add_library(<name> [STATIC | SHARED | MODULE]
                [EXCLUDE_FROM_ALL]
                [source1] [source2] [...])
    
    点赞 评论 复制链接分享

相关推荐