i would like to compile a project using the apache portable runtime libraries (APR) and cmake. It all looks good when running along with linux (as there i can use the apr-1-config shell script). Nevertheless, in windows it looks like cmake
does not bind or link the included files correctly. I've tried some different methods, like importing the libapr-1.lib
as static library or just target_link_library
all stuff, yet nothing seems to work. I always get the
error LNK2019: unresolved external symbol
linker errors when compiling using visual studio. It does not matter which function i am calling, as an example i am calling apt_pool_create
, as it does not require any parameters.
I am still wondering as visual studio is finding the files with IntelliSense and showing me all documentations inline. Also the compiler does not fail to build when an apt_pool*
pointer object is defined and initialized with NULL.
Maybe anyone does know why there are these linker problems. Following are some snippets out of the CMakeLists.txt
files:
CMakeLists.txt (partial)
# Include unimrcp requirements (apr package)
IF(WIN32) # Search APR in windows
INCLUDE(${PROJECT_SOURCE_DIR}/cmake_modules/FindAPR_windows.cmake)
ELSE(WIN32) # Search APR in unix
INCLUDE(${PROJECT_SOURCE_DIR}/cmake_modules/FindAPR_unix.cmake)
ENDIF(WIN32)
# Set link libraries
SET(TARGET_LINK_LIBS
${APR_LIBRARIES}
${APRUTIL_LIBRARIES}
${PTHREADS}
)
SET(CLIENT_SOURCES ...)
SET(CLIENT_HEADERS ...)
# Include intermediary files
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${APR_INCLUDE_DIR}
${APRUTIL_INCLUDE_DIR}
)
# Add executable and link libraries
ADD_EXECUTABLE(${CLIENT_TARGET} src/main.cpp ${CLIENT_SOURCES} ${CLIENT_HEADERS})
TARGET_LINK_LIBRARIES(${CLIENT_TARGET} ${TARGET_LINK_LIBS})
The CLIENT_TARGET
is just a predefined target name for output.
[For windows i am using following FindAPR.cmake module (the FindAPR_windows.cmake file)]( https://svn.apache.org/repos/asf/incubator/celix/trunk/cmake/modules/FindAPR.cmake).
For linux i am using following FindAPR.cmake module (the FindAPR_unix.cmake file).
It searches for apr-1-config
and executes the shell script.
In linux my APR_LIBRARIES variable looks like this:
-L/usr/lib;-lapr-1
Windows is directly using the library with its path:
{path_to_lib}/libapr-1.lib
CMake does not announce any errors for linking, as mentioned above Visual Studio does give me the LNK2019 errors when calling for any apr function.
Maybe someone does have a hint for this problem?