CMake - using external libraries as APR

Kérdezösködő Indián :

I am quite new to this CMake.

I need to use APR from Apache 2 and I have a problem with this build system. The Apache 2 web server is installed under the C:\Apache24 folder, the APR related include files are located under C:\Apache24\include and the libraries under the C:\Apache24\lib folder.

cmake_minimum_required(VERSION 3.15)
project(json C)
set(CMAKE_C_STANDARD 90)
include_directories(
    C:\Apache24\include
)
link_directories(
    C:\Apache24\lib
)
target_link_libraries(
    json apr-1.lib
)
add_executable(larak larak.h larak.c main.c)

By build I get this error:

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

I've already read a lot of similar posts but most all of them are for Linux/Unix systems, not for Windows and not for APR/Apache.

squareskittles :

The target_link_libraries() command specifies libraries to link for a specific target. This target name must be provided as the first argument to the command, and must already be defined earlier in your CMake file. Since you only have one target, larak, defined in your CMake file, you probably want to do something like this:

cmake_minimum_required(VERSION 3.15)
project(json C)
set(CMAKE_C_STANDARD 90)
include_directories(
    C:/Apache24/include
)
link_directories(
    C:/Apache24/lib
)

add_executable(larak larak.h larak.c main.c)

target_link_libraries(larak PRIVATE
    apr-1.lib
)

Careful, CMake will probably complain about the backslash usage (\) you have. You should convert these to forward slashes.

Note, you may instead specify the full path to the library in the target_link_libraries() command, to avoid the use of the link_directories() command.

cmake_minimum_required(VERSION 3.15)
project(json C)
set(CMAKE_C_STANDARD 90)
include_directories(
    C:/Apache24/include
) 
add_executable(larak larak.h larak.c main.c)

target_link_libraries(larak PRIVATE
    C:/Apache24/lib/apr-1.lib
)

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=375940&siteId=1