[CMake] How to link a static library when I build another static library

Grégoire Badoual greglebad at gmail.com
Fri May 20 12:57:19 EDT 2011


Hi,

I'm trying to create some static libraries that i used in an android
application.

In a first part, I've created my A static library. This library is
functionnal.
I have trying to link this library A into the build of a second library, the
B static library,
with the command :

add_library(A STATIC IMPORTED)
set_target_properties(A PROPERTIES IMPORTED_LOCATION ${A_LIBRARY_PATH})

add_library(B STATIC ${source_files})
target_link_libraries(B A )

But I try another way to link the static library with a roof's
CMakeList.txt, who called the A's CMakeLists.txt and the B'CMakeLists.txt.

There is the code :

*ROOF'S CMAKELIST.TXT *

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

project(main)

INCLUDE_DIRECTORIES(A/src/A/lib)
INCLUDE_DIRECTORIES(B/src/ B/lib)

add_subdirectory(A/proj/eclipse/debug_android/cmake/ A/lib)
add_subdirectory(B/proj/eclipse/debug_android/cmake-B/ B/lib)

*A'S CMAKELIST.TXT *

cmake_minimum_required(VERSION 2.8)

project(A)

#notice the "recycling" of CMAKE_C_FLAGS
#this is necessary to pick up android flags
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic" )

include_directories(${AS_WORKSPACE}/pkg/extern/src/)
include_directories(${AS_WORKSPACE}/pkg/A/src/)
include_directories(${PROJECT_SOURCES})
file(
    GLOB_RECURSE
    source_files
    ${PROJECT_SOURCES}/*.cpp
    ${PROJECT_SOURCES}/*.h
)

add_library(A STATIC ${source_files} )

*B'S CMAKELIST.TXT *

cmake_minimum_required(VERSION 2.8)

project(B)

#notice the "recycling" of CMAKE_C_FLAGS
#this is necessary to pick up android flags
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic" )
set( JNI_INCLUDE_DIRS ${LIBRARY_OUTPUT_PATH_ROOT}/jni )

include_directories(${PROJECT_SOURCES}/../../pkg/extern/src/)
include_directories(${PROJECT_SOURCES}/../../A/src/)
include_directories(${PROJECT_SOURCES})
file(
    GLOB_RECURSE
    source_files
    ${PROJECT_SOURCES}/*.cpp
    ${PROJECT_SOURCES}/*.h
)

set(A_LIBRARY_PATH /home/gbadoual/Workspace//libA.a)

add_library(B STATIC ${source_files})
target_link_libraries(B A)


And the android-toolchain.cmake that i call to create theses libraries is
provided by http://code.google.com/p/android-cmake/, that i have changed for
my project.

I have no errors in the compilation
but when i launch my android application, he recognize my A library, and my
B library.
But the B library don't recognize the A library. This B library is not well
linked with A

I have with no doubt misunderstanding something, in this linking.
Anyone can help me to fix this problem ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110520/8a2a0af1/attachment.htm>


More information about the CMake mailing list