我正在尝试为我的项目创建一个cmake文件,以了解如何创建一个cmake文件。
我的目录结构。我收到一个错误:
square_and_add
|- src
| |- <Some source files>
|- libsrc
| |- include
| |- <library header files>
| |- src
| |- <library source files>
|- build
|- libs
|- <installed libraries>
cmake_minimum_required(VERSION 2.6)
project(SQUARE_AND_ADD)
set(CMAKE_CXX_FLAGS "-g -Wall")
include_directories(./libsrc/include)
include_directories(./libsrc/src)
include_directories(./build)
add_executable(no_lib_exec ./src/main.cc)
target_link_libraries(no_lib_exec ./libsrc/src/square.cc)
set_target_properties(no_lib_exec PROPERTIES PREFIX "" OUTPUT_NAME sqnadd_no_lib)
add_library(build_static_lib STATIC ./libsrc/src/square.cc)
set_target_properties(build_static_lib PROPERTIES PREFIX "" OUTPUT_NAME static_library)
add_executable(static_lib_exec ./src/main.cc)
target_link_libraries(static_lib_exec ./build/static_library.a)
set_target_properties(static_lib_exec PROPERTIES PREFIX "" OUTPUT_NAME sqnadd_stat_lib)
add_library(build_dynamic_lib SHARED ./libsrc/src/square.cc)
set_target_properties(build_dynamic_lib PROPERTIES PREFIX "" OUTPUT_NAME dynamic_library)
add_executable(dynamic_lib_exec ./src/main.cc)
target_link_libraries(dynamic_lib_exec ./build/dynamic_library.so)
set_target_properties(dynamic_lib_exec PROPERTIES PREFIX "" OUTPUT_NAME sqnadd_dyn_lib)
install(TARGETS dynamic_lib_exec static_lib_exec
RUNTIME DESTINATION ./libs CONFIGURATIONS debug)
我收到此错误
/ usr / bin / ld:找不到-l./build/dynamic_library collect2:错误:ld返回1退出状态 CMakeFiles / dynamic_lib_exec.dir / build.make:85:目标的配方&#39; sqnadd_dyn_lib&#39;失败