I'm trying to compile a project into a statically linked library with CMake. Here I'm checking if BFD
and Iberty
are availabe, and if they are I compile a modified backtrace-symbols.c
into an OBJECT
Library, and statically link that object into the project along with the BFD
, Iberty
, and DL
libraries it depends on. When I try to use the resultant static library in a project, I get errors on BFD
functions that are used in backtrace-symbols.c
saying they are undefined.
How can I ensure that BFD
, Iberty
, and DL
are also statically linked into this library so that the user won't have to worry about linking against them in their project?
cmake_minimum_required(VERSION 2.8)
project(simplog)
configure_file (
"SimpLogConfig.h.in"
"SimpLogConfig.h"
@ONLY
)
set( CMAKE_C_COMPILER "clang" )
find_library( BFD_LIBRARY bfd )
find_library( IBERTY_LIBRARY iberty )
find_path(
IBERTY_HEADER_PATH libiberty.h
PATHS
/usr/include/libiberty
/usr/local/include/libiberty.h
)
include_directories(
${IBERTY_HEADER_PATH}
${PROJECT_BINARY_DIR}
)
set( PACKAGE "SimpLog" )
set( PACKAGE_VERSION "0.0.1" )
if( BFD_LIBRARY AND IBERTY_LIBRARY )
option( BETTER_BACKTRACE "" ON )
add_library( backtrace-symbols OBJECT backtrace-symbols.c )
add_library( simplog STATIC simplog.c $<TARGET_OBJECTS:backtrace-symbols> )
target_link_libraries( simplog ${BFD_LIBRARY} ${IBERTY_LIBRARY} ${CMAKE_DL_LIBS} )
else()
option( BETTER_BACKTRACE "" OFF )
add_library( simplog STATIC simplog.c )
endif()