Reputation: 2701
I have a dependency problem in my cmake configuration.
When I start building from root directory of the project, it always gives an error. When I disable add_subdirectory(application)
where I use LibCalcBin
, it builds the library
successfully. Then, I can build the application
.
Why cmake don't build the library
first then the application
as I have specified in the order of add_subdirectory commands. Is there any way to resolve this issue? Thanks.
Please set them or make sure they are set and tested correctly in the CMake files:
LibCalcBin
linked by target "run" in directory ...
cmake_minimum_required(VERSION 3.3)
project(DLLAbstract)
# specify where to put executable
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# specify where to put binaries
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# compile and build library
add_subdirectory(library)
# compile and build application
add_subdirectory(application)
set(src LibCalc.cpp Calculator.cpp)
add_definitions(-DDLL_EXPORT)
add_library(LibCalc SHARED ${src})
set(Src main.cpp)
find_path(LibCalcHeader
NAMES
LibCalc.hpp
PATHS
${PROJECT_SOURCE_DIR}/library
)
find_library(LibCalcBin
NAMES
LibCalc
PATHS
${PROJECT_SOURCE_DIR}/bin/Debug
${PROJECT_SOURCE_DIR}/bin/Release
${PROJECT_SOURCE_DIR}/bin
)
include_directories(${LibCalcHeader})
add_executable(run ${Src})
target_link_libraries(run ${LibCalcBin})
Upvotes: 0
Views: 2913
Reputation: 34401
The find_library
command is used to locate libraries, which aren't part of your project. For libraries created by add_library
command no special treatment is needed and you can use target name in target_link_libraries
call:
target_link_libraries(run LibCalc)
Upvotes: 1