Now my CMakeList.txt looking like this.
cmake_minimum_required(VERSION 3.6)
project(RabbitMQClient)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
include_directories(src)
include_directories(dependentFile)
add_executable(RabbitMQClient ${SOURCE_FILES})
find_library(SimpleAmqpClient SimpleAmqpClient.2.lib PATHS ./SimpleAmqpClientLib/SimpleAmqpClient.2.lib)
set(IMPORTED_IMPLIB ./SimpleAmqpClientLib)
target_link_libraries(RabbitMQClient PUBLIC SimpleAmqpClient)
when Linking the RabbitMQClient it complains.
cannot find
-lSimpleAmqpClient
I want to use the SimpleAmqpClient
library in the project,however not quite familiar with cmake
not sure the find_library
,IMPORTED_IMPLIB
,PUBLIC
in target_link_libraries
was correctly used.Any help would be appreciate.
You have messed up with variables, targets and properties.
Proper usage of IMPORTED libraries for linking would be:
However, there some simplifications which could be done:
Normally,
find_library
is used when you don't know complete path to the library file. E.g., its directory may be different on different machines, or its prefix/extension may be different on different plaforms.If you know complete path to the library, just use this path directly (e.g., assign it to the variable).
Normally, property IMPORTED_LOCATION is used for specify library to link with. Property IMPORTED_LIB is specific for Windows
.dll
s, when linking requires not a library file (.dll
), but some other one (.lib
).However, CMake perfectly understands
.lib
file in IMPORTED_LOCATION property even for Windows.dll
s, so your code need not distinguish SHARED Windows libraries from others: just use IMPORTED_LOCATION property in all cases.Simplified version of the code: