2

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?

Jules
  • 14,200
  • 13
  • 56
  • 101
Steve
  • 21
  • 2
  • Can you confirm that the full path to the libapr-1.lib file appears in the Property Pages of your `${CLIENT_TARGET}` exe in VS under Linker->Input->Additional Dependencies, and that this path is definitely correct? – Fraser Mar 29 '13 at 02:08
  • I can confirm that the dependencies list the libapr-1.lib file with the correct path. That's why i'm struggling... It should find the path and link it, also the full lib path is added as general linker library path to the executable. – Steve Apr 03 '13 at 11:41

0 Answers0