Adding a library to the executable
Hi all, This might be a CMake rather than seL4 question, but bear with me because I'm new to CMake so still I don't understand how seL4 is being built. I don't know how to add and link a piece of new code (a static library) to the executable. I add the statements to the CMakeList.txt: add_library(chrises_lib STATIC ${sources}) target_link_libraries(chrises_lib ...) and I can see libchrises_lib.a being built. By examining build.ninja, I can see the whole bunch of libraries (.a files) being pulled in by the linker, but there is no chrises_lib.a in the long list of .a files. And the result is obviously 'undefined reference to' all symbols that are im[lemented in chrises_lib.a. What am I missing? What do I have to add to the series of CMakeList.txt and where I need to add (besides add_library and target_link_libraries that I'm already using per above), in order for my chrises_lib.a be included in the list at static libs below? ############################################# # Link the executable apps/sel4test-driver/sel4test-driver build apps/sel4test-driver/sel4test-driver: C_EXECUTABLE_LINKER__sel4test-driver apps/sel4test-driver/archive.o apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/arch/arm/arch.c.obj apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/main.c.obj apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/tests/interrupt.c.obj apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/tests/syscall.c.obj apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/tests/timer.c.obj apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/testtypes.c.obj apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/timer.c.obj | libsel4/libsel4.a apps/sel4test-driver/sel4runtime/libsel4runtime.a apps/sel4test-driver/seL4_libs/libsel4allocman/libsel4allocman.a apps/sel4test-driver/seL4_libs/libsel4vka/libsel4vka.a apps/sel4test-driver/seL4_libs/libsel4utils/libsel4utils.a apps/sel4test-driver/sel4_projects_libs/libsel4rpc/libsel4rpc.a apps/sel4test-driver/seL4_libs/libsel4test/libsel4test.a apps/sel4test-driver/seL4_libs/libsel4platsupport/libsel4platsupport.a apps/sel4test-driver/seL4_libs/libsel4muslcsys/libsel4muslcsys.a apps/sel4test-driver/libsel4testsupport/libsel4testsupport.a apps/sel4test-driver/seL4_libs/libsel4test/libsel4test.a apps/sel4test-driver/sel4_projects_libs/libsel4rpc/libsel4rpc.a apps/sel4test-driver/sel4_projects_libs/libsel4nanopb/libsel4nanopb.a apps/sel4test-driver/sel4_projects_libs/libsel4nanopb/libnanopb.a apps/sel4test-driver/seL4_libs/libsel4sync/libsel4sync.a apps/sel4test-driver/seL4_libs/libsel4serialserver/libsel4serialserver.a apps/sel4test-driver/seL4_libs/libsel4utils/libsel4utils.a apps/sel4test-driver/util_libs/libelf/libelf.a apps/sel4test-driver/util_libs/libcpio/libcpio.a apps/sel4test-driver/seL4_libs/libsel4platsupport/libsel4platsupport.a apps/sel4test-driver/sel4runtime/libsel4runtime.a apps/sel4test-driver/util_libs/libplatsupport/libplatsupport.a apps/sel4test-driver/util_libs/libfdt/libfdt.a apps/sel4test-driver/seL4_libs/libsel4simple-default/libsel4simple-default.a apps/sel4test-driver/seL4_libs/libsel4debug/libsel4debug.a apps/sel4test-driver/seL4_libs/libsel4vspace/libsel4vspace.a apps/sel4test-driver/seL4_libs/libsel4simple/libsel4simple.a apps/sel4test-driver/seL4_libs/libsel4vka/libsel4vka.a libsel4/libsel4.a apps/sel4test-driver/util_libs/libutils/libutils.a apps/sel4test-driver/musllibc/build-temp/stage/lib/libc.a || apps/sel4test-driver/libsel4testsupport/libsel4testsupport.a apps/sel4test-driver/musllibc/muslc_gen apps/sel4test-driver/seL4_libs/libsel4allocman/libsel4allocman.a apps/sel4test-driver/seL4_libs/libsel4debug/libsel4debug.a apps/sel4test-driver/seL4_libs/libsel4debug/sel4debug_Gen apps/sel4test-driver/seL4_libs/libsel4muslcsys/libsel4muslcsys.a apps/sel4test-driver/seL4_libs/libsel4muslcsys/sel4muslcsys_Gen apps/sel4test-driver/seL4_libs/libsel4platsupport/libsel4platsupport.a apps/sel4test-driver/seL4_libs/libsel4platsupport/sel4platsupport_Gen apps/sel4test-driver/seL4_libs/libsel4serialserver/libsel4serialserver.a apps/sel4test-driver/seL4_libs/libsel4serialserver/sel4serialserver_Gen apps/sel4test-driver/seL4_libs/libsel4simple-default/libsel4simple-default.a apps/sel4test-driver/seL4_libs/libsel4simple/libsel4simple.a apps/sel4test-driver/seL4_libs/libsel4sync/libsel4sync.a apps/sel4test-driver/seL4_libs/libsel4test/libsel4test.a apps/sel4test-driver/seL4_libs/libsel4test/sel4test_Gen apps/sel4test-driver/seL4_libs/libsel4utils/libsel4utils.a apps/sel4test-driver/seL4_libs/libsel4utils/sel4utils_Gen apps/sel4test-driver/seL4_libs/libsel4vka/libsel4vka.a apps/sel4test-driver/seL4_libs/libsel4vka/sel4vka_Gen apps/sel4test-driver/seL4_libs/libsel4vspace/libsel4vspace.a apps/sel4test-driver/sel4_projects_libs/libsel4nanopb/libnanopb.a apps/sel4test-driver/sel4_projects_libs/libsel4nanopb/libsel4nanopb.a apps/sel4test-driver/sel4_projects_libs/libsel4rpc/libsel4rpc.a apps/sel4test-driver/sel4runtime/libsel4runtime.a apps/sel4test-driver/sel4runtime/sel4runtime_Gen apps/sel4test-driver/sel4test-driver_Gen apps/sel4test-driver/sel4test-tests/sel4test-tests apps/sel4test-driver/util_libs/libcpio/libcpio.a apps/sel4test-driver/util_libs/libelf/libelf.a apps/sel4test-driver/util_libs/libfdt/libfdt.a apps/sel4test-driver/util_libs/libplatsupport/libplatsupport.a apps/sel4test-driver/util_libs/libplatsupport/platsupport_Gen apps/sel4test-driver/util_libs/libutils/libutils.a apps/sel4test-driver/util_libs/libutils/utils_Gen kernel/kernel_Gen libsel4/libsel4.a libsel4/sel4_Gen libsel4/sel4_autoconf_Gen
On Wed, Oct 21, 2020 at 3:46 PM Chris Koziarz
Hi all, This might be a CMake rather than seL4 question, but bear with me because I'm new to CMake so still I don't understand how seL4 is being built. I don't know how to add and link a piece of new code (a static library) to the executable. I add the statements to the CMakeList.txt: add_library(chrises_lib STATIC ${sources}) target_link_libraries(chrises_lib ...) and I can see libchrises_lib.a being built. By examining build.ninja, I can see the whole bunch of libraries (.a files) being pulled in by the linker, but there is no chrises_lib.a in the long list of .a files. And the result is obviously 'undefined reference to' all symbols that are im[lemented in chrises_lib.a. What am I missing? What do I have to add to the series of CMakeList.txt and where I need to add (besides add_library and target_link_libraries that I'm already using per above), in order for my chrises_lib.a be included in the list at static libs below?
Hi Chris, You also need to add your library as a dependency on the sel4test-driver executable: target_link_libraries( sel4test-driver PUBLIC sel4_autoconf muslc sel4 sel4runtime sel4allocman sel4vka sel4utils sel4rpc sel4test sel4platsupport sel4muslcsys sel4testsupport chrises_lib PRIVATE sel4test-driver_Config ) Alternatively adding it as a dependency for any of the libraries that sel4test-driver already depends on should also cause it to link.
############################################# # Link the executable apps/sel4test-driver/sel4test-driver
build apps/sel4test-driver/sel4test-driver: C_EXECUTABLE_LINKER__sel4test-driver apps/sel4test-driver/archive.o apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/arch/arm/arch.c.obj apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/main.c.obj apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/tests/interrupt.c.obj apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/tests/syscall.c.obj apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/tests/timer.c.obj apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/testtypes.c.obj apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/timer.c.obj | libsel4/libsel4.a apps/sel4test-driver/sel4runtime/libsel4runtime.a apps/sel4test-driver/seL4_libs/libsel4allocman/libsel4allocman.a apps/sel4test-driver/seL4_libs/libsel4vka/libsel4vka.a apps/sel4test-driver/seL4_libs/libsel4utils/libsel4utils.a apps/sel4test-driver/sel4_projects_libs/libsel4rpc/libsel4rpc.a apps/sel4test-driver/seL4_libs/libsel4test/libsel4test.a apps/sel4test-driver/seL4_libs/libsel4platsupport/libsel4platsupport.a apps/sel4test-driver/seL4_libs/libsel4muslcsys/libsel4muslcsys.a apps/sel4test-driver/libsel4testsupport/libsel4testsupport.a apps/sel4test-driver/seL4_libs/libsel4test/libsel4test.a apps/sel4test-driver/sel4_projects_libs/libsel4rpc/libsel4rpc.a apps/sel4test-driver/sel4_projects_libs/libsel4nanopb/libsel4nanopb.a apps/sel4test-driver/sel4_projects_libs/libsel4nanopb/libnanopb.a apps/sel4test-driver/seL4_libs/libsel4sync/libsel4sync.a apps/sel4test-driver/seL4_libs/libsel4serialserver/libsel4serialserver.a apps/sel4test-driver/seL4_libs/libsel4utils/libsel4utils.a apps/sel4test-driver/util_libs/libelf/libelf.a apps/sel4test-driver/util_libs/libcpio/libcpio.a apps/sel4test-driver/seL4_libs/libsel4platsupport/libsel4platsupport.a apps/sel4test-driver/sel4runtime/libsel4runtime.a apps/sel4test-driver/util_libs/libplatsupport/libplatsupport.a apps/sel4test-driver/util_libs/libfdt/libfdt.a apps/sel4test-driver/seL4_libs/libsel4simple-default/libsel4simple-default.a apps/sel4test-driver/seL4_libs/libsel4debug/libsel4debug.a apps/sel4test-driver/seL4_libs/libsel4vspace/libsel4vspace.a apps/sel4test-driver/seL4_libs/libsel4simple/libsel4simple.a apps/sel4test-driver/seL4_libs/libsel4vka/libsel4vka.a libsel4/libsel4.a apps/sel4test-driver/util_libs/libutils/libutils.a apps/sel4test-driver/musllibc/build-temp/stage/lib/libc.a || apps/sel4test-driver/libsel4testsupport/libsel4testsupport.a apps/sel4test-driver/musllibc/muslc_gen apps/sel4test-driver/seL4_libs/libsel4allocman/libsel4allocman.a apps/sel4test-driver/seL4_libs/libsel4debug/libsel4debug.a apps/sel4test-driver/seL4_libs/libsel4debug/sel4debug_Gen apps/sel4test-driver/seL4_libs/libsel4muslcsys/libsel4muslcsys.a apps/sel4test-driver/seL4_libs/libsel4muslcsys/sel4muslcsys_Gen apps/sel4test-driver/seL4_libs/libsel4platsupport/libsel4platsupport.a apps/sel4test-driver/seL4_libs/libsel4platsupport/sel4platsupport_Gen apps/sel4test-driver/seL4_libs/libsel4serialserver/libsel4serialserver.a apps/sel4test-driver/seL4_libs/libsel4serialserver/sel4serialserver_Gen apps/sel4test-driver/seL4_libs/libsel4simple-default/libsel4simple-default.a apps/sel4test-driver/seL4_libs/libsel4simple/libsel4simple.a apps/sel4test-driver/seL4_libs/libsel4sync/libsel4sync.a apps/sel4test-driver/seL4_libs/libsel4test/libsel4test.a apps/sel4test-driver/seL4_libs/libsel4test/sel4test_Gen apps/sel4test-driver/seL4_libs/libsel4utils/libsel4utils.a apps/sel4test-driver/seL4_libs/libsel4utils/sel4utils_Gen apps/sel4test-driver/seL4_libs/libsel4vka/libsel4vka.a apps/sel4test-driver/seL4_libs/libsel4vka/sel4vka_Gen apps/sel4test-driver/seL4_libs/libsel4vspace/libsel4vspace.a apps/sel4test-driver/sel4_projects_libs/libsel4nanopb/libnanopb.a apps/sel4test-driver/sel4_projects_libs/libsel4nanopb/libsel4nanopb.a apps/sel4test-driver/sel4_projects_libs/libsel4rpc/libsel4rpc.a apps/sel4test-driver/sel4runtime/libsel4runtime.a apps/sel4test-driver/sel4runtime/sel4runtime_Gen apps/sel4test-driver/sel4test-driver_Gen apps/sel4test-driver/sel4test-tests/sel4test-tests apps/sel4test-driver/util_libs/libcpio/libcpio.a apps/sel4test-driver/util_libs/libelf/libelf.a apps/sel4test-driver/util_libs/libfdt/libfdt.a apps/sel4test-driver/util_libs/libplatsupport/libplatsupport.a apps/sel4test-driver/util_libs/libplatsupport/platsupport_Gen apps/sel4test-driver/util_libs/libutils/libutils.a apps/sel4test-driver/util_libs/libutils/utils_Gen kernel/kernel_Gen libsel4/libsel4.a libsel4/sel4_Gen libsel4/sel4_autoconf_Gen _______________________________________________ Devel mailing list Devel@sel4.systems https://sel4.systems/lists/listinfo/devel
Thanks, Kent!
Your both suggestions make a lot of sense and both worked!
Chris
On Wed, Oct 21, 2020 at 5:44 PM Kent Mcleod
On Wed, Oct 21, 2020 at 3:46 PM Chris Koziarz
wrote: Hi all, This might be a CMake rather than seL4 question, but bear with me because I'm new to CMake so still I don't understand how seL4 is being built. I don't know how to add and link a piece of new code (a static library)
the executable. I add the statements to the CMakeList.txt: add_library(chrises_lib STATIC ${sources}) target_link_libraries(chrises_lib ...) and I can see libchrises_lib.a being built. By examining build.ninja, I can see the whole bunch of libraries (.a files) being pulled in by the linker, but there is no chrises_lib.a in the long list of .a files. And the result is obviously 'undefined reference to' all symbols that are im[lemented in chrises_lib.a. What am I missing? What do I have to add to the series of CMakeList.txt and where I need to add (besides add_library and target_link_libraries
to that
I'm already using per above), in order for my chrises_lib.a be included in the list at static libs below?
Hi Chris,
You also need to add your library as a dependency on the sel4test-driver executable:
target_link_libraries( sel4test-driver PUBLIC sel4_autoconf muslc sel4 sel4runtime sel4allocman sel4vka sel4utils sel4rpc sel4test sel4platsupport sel4muslcsys sel4testsupport chrises_lib PRIVATE sel4test-driver_Config )
Alternatively adding it as a dependency for any of the libraries that sel4test-driver already depends on should also cause it to link.
############################################# # Link the executable apps/sel4test-driver/sel4test-driver
build apps/sel4test-driver/sel4test-driver: C_EXECUTABLE_LINKER__sel4test-driver apps/sel4test-driver/archive.o
apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/arch/arm/arch.c.obj
apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/main.c.obj
apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/tests/interrupt.c.obj
apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/tests/syscall.c.obj
apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/tests/timer.c.obj apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/testtypes.c.obj apps/sel4test-driver/CMakeFiles/sel4test-driver.dir/src/timer.c.obj | libsel4/libsel4.a apps/sel4test-driver/sel4runtime/libsel4runtime.a apps/sel4test-driver/seL4_libs/libsel4allocman/libsel4allocman.a apps/sel4test-driver/seL4_libs/libsel4vka/libsel4vka.a apps/sel4test-driver/seL4_libs/libsel4utils/libsel4utils.a apps/sel4test-driver/sel4_projects_libs/libsel4rpc/libsel4rpc.a apps/sel4test-driver/seL4_libs/libsel4test/libsel4test.a apps/sel4test-driver/seL4_libs/libsel4platsupport/libsel4platsupport.a apps/sel4test-driver/seL4_libs/libsel4muslcsys/libsel4muslcsys.a apps/sel4test-driver/libsel4testsupport/libsel4testsupport.a apps/sel4test-driver/seL4_libs/libsel4test/libsel4test.a apps/sel4test-driver/sel4_projects_libs/libsel4rpc/libsel4rpc.a apps/sel4test-driver/sel4_projects_libs/libsel4nanopb/libsel4nanopb.a apps/sel4test-driver/sel4_projects_libs/libsel4nanopb/libnanopb.a apps/sel4test-driver/seL4_libs/libsel4sync/libsel4sync.a apps/sel4test-driver/seL4_libs/libsel4serialserver/libsel4serialserver.a apps/sel4test-driver/seL4_libs/libsel4utils/libsel4utils.a apps/sel4test-driver/util_libs/libelf/libelf.a apps/sel4test-driver/util_libs/libcpio/libcpio.a apps/sel4test-driver/seL4_libs/libsel4platsupport/libsel4platsupport.a apps/sel4test-driver/sel4runtime/libsel4runtime.a apps/sel4test-driver/util_libs/libplatsupport/libplatsupport.a apps/sel4test-driver/util_libs/libfdt/libfdt.a
apps/sel4test-driver/seL4_libs/libsel4simple-default/libsel4simple-default.a
apps/sel4test-driver/seL4_libs/libsel4debug/libsel4debug.a apps/sel4test-driver/seL4_libs/libsel4vspace/libsel4vspace.a apps/sel4test-driver/seL4_libs/libsel4simple/libsel4simple.a apps/sel4test-driver/seL4_libs/libsel4vka/libsel4vka.a libsel4/libsel4.a apps/sel4test-driver/util_libs/libutils/libutils.a apps/sel4test-driver/musllibc/build-temp/stage/lib/libc.a || apps/sel4test-driver/libsel4testsupport/libsel4testsupport.a apps/sel4test-driver/musllibc/muslc_gen apps/sel4test-driver/seL4_libs/libsel4allocman/libsel4allocman.a apps/sel4test-driver/seL4_libs/libsel4debug/libsel4debug.a apps/sel4test-driver/seL4_libs/libsel4debug/sel4debug_Gen apps/sel4test-driver/seL4_libs/libsel4muslcsys/libsel4muslcsys.a apps/sel4test-driver/seL4_libs/libsel4muslcsys/sel4muslcsys_Gen apps/sel4test-driver/seL4_libs/libsel4platsupport/libsel4platsupport.a apps/sel4test-driver/seL4_libs/libsel4platsupport/sel4platsupport_Gen apps/sel4test-driver/seL4_libs/libsel4serialserver/libsel4serialserver.a apps/sel4test-driver/seL4_libs/libsel4serialserver/sel4serialserver_Gen
apps/sel4test-driver/seL4_libs/libsel4simple-default/libsel4simple-default.a
apps/sel4test-driver/seL4_libs/libsel4simple/libsel4simple.a apps/sel4test-driver/seL4_libs/libsel4sync/libsel4sync.a apps/sel4test-driver/seL4_libs/libsel4test/libsel4test.a apps/sel4test-driver/seL4_libs/libsel4test/sel4test_Gen apps/sel4test-driver/seL4_libs/libsel4utils/libsel4utils.a apps/sel4test-driver/seL4_libs/libsel4utils/sel4utils_Gen apps/sel4test-driver/seL4_libs/libsel4vka/libsel4vka.a apps/sel4test-driver/seL4_libs/libsel4vka/sel4vka_Gen apps/sel4test-driver/seL4_libs/libsel4vspace/libsel4vspace.a apps/sel4test-driver/sel4_projects_libs/libsel4nanopb/libnanopb.a apps/sel4test-driver/sel4_projects_libs/libsel4nanopb/libsel4nanopb.a apps/sel4test-driver/sel4_projects_libs/libsel4rpc/libsel4rpc.a apps/sel4test-driver/sel4runtime/libsel4runtime.a apps/sel4test-driver/sel4runtime/sel4runtime_Gen apps/sel4test-driver/sel4test-driver_Gen apps/sel4test-driver/sel4test-tests/sel4test-tests apps/sel4test-driver/util_libs/libcpio/libcpio.a apps/sel4test-driver/util_libs/libelf/libelf.a apps/sel4test-driver/util_libs/libfdt/libfdt.a apps/sel4test-driver/util_libs/libplatsupport/libplatsupport.a apps/sel4test-driver/util_libs/libplatsupport/platsupport_Gen apps/sel4test-driver/util_libs/libutils/libutils.a apps/sel4test-driver/util_libs/libutils/utils_Gen kernel/kernel_Gen libsel4/libsel4.a libsel4/sel4_Gen libsel4/sel4_autoconf_Gen _______________________________________________ Devel mailing list Devel@sel4.systems https://sel4.systems/lists/listinfo/devel
participants (2)
-
Chris Koziarz
-
Kent Mcleod