I hope someone can help
I have a structure as follows:
Top_dir
--> CmakeLists.txt
-->include
----> defs.h (access the functions in static library)
----> moredefs.h (access the functions in static library)
----> myClass.h (Header file of my class - includes the defs.h and moredefs.h)
-->lib
---->src
------> functions.c (autogenerated - includes the defs.h and moredefs.h)
----> libsomelib.a (given to me with a compiler to make the auto generated headers)
-->src
----> main.cpp
----> myClass.cpp
my cmakelists is causing distress - I don't know how to compile to include the libsomelib.a and the c file into a library and add to the main executable.
project(myProject)
set(MODULE_NAME ${PROJECT_NAME})
set(LIB_NAME ${MODULE_NAME})
########### SETUP #####################
find_package(catkin REQUIRED COMPONENTS
roscpp
)
set(MAIN
src/main.cpp
)
set(SOURCES
src/myClass.cpp
)
set(HEADERS
include/myClass.h
include/defs.h
include/moredefs.h
)
############ LIB ########################
include_directories(
include
${catkin_INCLUDE_DIRS}
)
add_library(${LIB_NAME}
${SOURCES}
${HEADERS}
)
add_library(myAttemptLib
lib/src/functions.c
#include/defs.h
#include/moredefs.h
)
#add_library(myAttemptLib STATIC IMPORTED)
set_target_properties(myAttemptLib PROPERTIES IMPORTED_LOCATION lib/libsomelib.a)
target_link_libraries(${LIB_NAME}
${catkin_LIBRARIES}
)
############ EXE ########################
add_executable(${PROJECT_NAME}_node ${MAIN})
add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(${PROJECT_NAME}_node
${LIB_NAME}
${catkin_LIBRARIES}
myAttemptLib
)
This compiles and will run. I can add and use datatypes form the headers no problem, it will compile and the code runs, but as soon as I try to utilise a function which is contained inside the libsomelib.a
then the compile error undefined reference to the function and recipe for target failed.
In a make file in a small test area I can compile and make executable that runs independent.
I feel it is some way that I should be compiling the .a + .c with the main exe, but have searched a lot and not trying to reach out here. I hope someone can help.
Cheers
Steve