I am looking at my problem for hours and I am stuck...
I have a library lib_1 with function getNumber()
.
Then I have a library lib_2 with function addNumbers()
.
addNumbers()
calls getNumber()
from lib_1.
My CMakeLists.txt:
add_library( lib_1 STATIC IMPORTED )
set_target_properties(lib_1 PROPERTIES IMPORTED_LOCATION path_to_lib_1)
add_library( lib_2 STATIC lib2.cpp )
target_link_libraries( lib_2 lib_1 )
target_include_directories(lib_2 PUBLIC include )
lib_2 compiles just fine, also the unit tests which use getNumber()
are working.
Then I want to link lib_2 to my application app.
add_library( lib_1 STATIC IMPORTED )
set_target_properties(lib_1 PROPERTIES IMPORTED_LOCATION path_to_lib_1)
add_library( lib_2 STATIC IMPORTED )
set_target_properties(lib_2 PROPERTIES IMPORTED_LOCATION path_to_lib_2)
add_executable(app my_source_files )
target_link_libraries(app lib_1 lib_2)
When I compile my app I get this well known error:
In function addNumbers()
from lib_2, undefined reference to getNumber()
I really don't get it, why its an undefined reference??
And btw do I really need to link against lib_1 in my application when already linking to lib_2 which itself is statically linking to lib_1?