Ich habe 2 Bibliotheken und 1 ausführbare Datei in meiner CMakeList.txt. Ich möchte alles in die ausführbare Datei verlinkt haben.Wie kann ich eine Bibliothek in cmake mit meiner ausführbaren Datei verknüpfen?
cmake_minimum_required(VERSION 2.8)
# Mark the language as C so that CMake doesn't try to test the C++
# cross-compiler's ability to compile a simple program because that will fail
project(jsos C ASM)
set(CMAKE_EXECUTABLE_OUTPUT_PATH "./build/")
# We had to adjust the CMAKE_C_FLAGS variable in the toolchain file to make sure
# the compiler would work with CMake's simple program compilation test. So unset
# it explicitly before re-setting it correctly for our system
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostartfiles")
# Set the linker flags so that we use our "custom" linker script
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${PROJECT_SOURCE_DIR}/etc/linker.ld")
add_library(duktape STATIC
src/libs/duktape/duktape.c
)
add_library(fdlibm STATIC
src/libs/fdlibm/e_acos.c
src/libs/fdlibm/e_acosh.c
src/libs/fdlibm/e_asin.c
MORE FILES
)
add_executable(kernel
src/start.S
src/kernel.c
src/cstartup.c
src/cstubs.c
src/rpi-gpio.c
src/rpi-interrupts.c
src/rpi-armtimer.c
src/rpi-systimer.c
)
add_dependencies(kernel fdlibm duktape)
target_link_libraries(kernel fdlibm duktape)
add_custom_command(
TARGET kernel POST_BUILD
COMMAND ${CMAKE_OBJCOPY} ./kernel${CMAKE_EXECUTABLE_SUFFIX} -O binary ./kernel.img
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Convert the ELF output file to a binary image"
)
Im Moment, als ich verknüpfen diese zusammen ich ein paar Fehler wie bekommen:
[100%] Linking C executable kernel
libduktape.a(duktape.c.obj): In function `duk_double_trunc_towards_zero':
src/libs/duktape/duktape.c:12102: undefined reference to `fabs'
src/libs/duktape/duktape.c:12102: undefined reference to `floor'
Aber fabs
und floor
sind in fdlibm
. duk_double_trunc_towards_zero
ist in der duktape
Bibliothek, so dass die Verbindung schien OK. Was mache ich falsch?
Versuchen Sie, die Bibliotheksreihenfolge in 'target_link_libraries' aufzurufen. – arrowd
@arrowd eine Antwort, so kann es akzeptieren. Das ist richtig – Justin808