I am trying to build an ELF file using the ARM-M4 toolchain version 8.1.0. My C code files compile successfully, but I encounter the following error while linking the object files
<code>[100%] Linking C executable ../test/bin/my_App.elf
ld.lld: error: undefined symbol: time
>>> referenced by clock.c
>>> clock.c.o:(clock) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumb/vfpv4/hard/dp_d16/exceptlibdnk.a
>>> referenced by tzset.c
>>> tzset.c.o:(tzset) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumb/vfpv4/hard/dp_d16/exceptlibdnk.a
ld.lld: error: undefined symbol: __exidx_start
>>> referenced by libunwind.cpp
>>> libunwind.cpp.o:(__unw_init_local) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumblibunwind.a
>>> referenced by libunwind.cpp
>>> libunwind.cpp.o:(libunwind::UnwindCursor<libunwind::LocalAddressSpace, libunwind::Registers_arm>::setInfoBasedOnIPRegister(bool)) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumblibunwind.a
ld.lld: error: undefined symbol: gettimeofday(timeval*, timezone*)
>>> referenced by chrono.cpp
>>> chrono.cpp.o:(std::__1::chrono::system_clock::now()) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumb/vfpv4/hard/dp_d16/exceptlibc++.a
ld.lld: error: undefined symbol: getentropy
>>> referenced by random.cpp
>>> random.cpp.o:(std::__1::random_device::operator()()) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumb/vfpv4/hard/dp_d16/exceptlibc++.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<code>[100%] Linking C executable ../test/bin/my_App.elf
ld.lld: error: undefined symbol: time
>>> referenced by clock.c
>>> clock.c.o:(clock) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumb/vfpv4/hard/dp_d16/exceptlibdnk.a
>>> referenced by tzset.c
>>> tzset.c.o:(tzset) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumb/vfpv4/hard/dp_d16/exceptlibdnk.a
>>> did you mean: ctime
ld.lld: error: undefined symbol: __exidx_start
>>> referenced by libunwind.cpp
>>> libunwind.cpp.o:(__unw_init_local) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumblibunwind.a
>>> referenced by libunwind.cpp
>>> libunwind.cpp.o:(libunwind::UnwindCursor<libunwind::LocalAddressSpace, libunwind::Registers_arm>::setInfoBasedOnIPRegister(bool)) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumblibunwind.a
ld.lld: error: undefined symbol: gettimeofday(timeval*, timezone*)
>>> referenced by chrono.cpp
>>> chrono.cpp.o:(std::__1::chrono::system_clock::now()) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumb/vfpv4/hard/dp_d16/exceptlibc++.a
ld.lld: error: undefined symbol: getentropy
>>> referenced by random.cpp
>>> random.cpp.o:(std::__1::random_device::operator()()) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumb/vfpv4/hard/dp_d16/exceptlibc++.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)
</code>
[100%] Linking C executable ../test/bin/my_App.elf
ld.lld: error: undefined symbol: time
>>> referenced by clock.c
>>> clock.c.o:(clock) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumb/vfpv4/hard/dp_d16/exceptlibdnk.a
>>> referenced by tzset.c
>>> tzset.c.o:(tzset) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumb/vfpv4/hard/dp_d16/exceptlibdnk.a
>>> did you mean: ctime
ld.lld: error: undefined symbol: __exidx_start
>>> referenced by libunwind.cpp
>>> libunwind.cpp.o:(__unw_init_local) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumblibunwind.a
>>> referenced by libunwind.cpp
>>> libunwind.cpp.o:(libunwind::UnwindCursor<libunwind::LocalAddressSpace, libunwind::Registers_arm>::setInfoBasedOnIPRegister(bool)) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumblibunwind.a
ld.lld: error: undefined symbol: gettimeofday(timeval*, timezone*)
>>> referenced by chrono.cpp
>>> chrono.cpp.o:(std::__1::chrono::system_clock::now()) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumb/vfpv4/hard/dp_d16/exceptlibc++.a
ld.lld: error: undefined symbol: getentropy
>>> referenced by random.cpp
>>> random.cpp.o:(std::__1::random_device::operator()()) in archive C:compilertoolchainsarmv8.1.0armlib/v7-m/thumb/vfpv4/hard/dp_d16/exceptlibc++.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am using Arm M4
architecture and below are the my compiler flags
<code>TOOLCHAIN ==>> "C:compilertoolchainsarmv8.1.0arminclude"
--target=armv7m-none-eabi
target_compile_options(${TEST_EXECUTABLE} PUBLIC ${COMMON_CFLAGS})
-Wl,-Map,${TEST}/${TEST_EXECUTABLE}.map
--allow-multiple-definition
target_link_options(${TEST_EXECUTABLE} PUBLIC ${LOCAL_LDFLAGS})
<code>TOOLCHAIN ==>> "C:compilertoolchainsarmv8.1.0arminclude"
set(COMMON_CFLAGS
--target=armv7m-none-eabi
-march=armv7-m
-mcpu=cortex-m4
-mfpu=vfpv4-d16
-mlittle-endian
-std=gnu99
-g3
-Wextra
-Wall
-I${TOOLCHAIN}
-ffunction-sections
-fdata-sections
)
target_compile_options(${TEST_EXECUTABLE} PUBLIC ${COMMON_CFLAGS})
set(LOCAL_LDFLAGS
-T${MY_LINKER_FILE}
-Wl,-Map,${TEST}/${TEST_EXECUTABLE}.map
-Xlinker
--allow-multiple-definition
-Xlinker
-mfpu=vfpv4-d16
-march=armv7-m
-mfloat-abi=hard
-mthumb
)
target_link_options(${TEST_EXECUTABLE} PUBLIC ${LOCAL_LDFLAGS})
</code>
TOOLCHAIN ==>> "C:compilertoolchainsarmv8.1.0arminclude"
set(COMMON_CFLAGS
--target=armv7m-none-eabi
-march=armv7-m
-mcpu=cortex-m4
-mfpu=vfpv4-d16
-mlittle-endian
-std=gnu99
-g3
-Wextra
-Wall
-I${TOOLCHAIN}
-ffunction-sections
-fdata-sections
)
target_compile_options(${TEST_EXECUTABLE} PUBLIC ${COMMON_CFLAGS})
set(LOCAL_LDFLAGS
-T${MY_LINKER_FILE}
-Wl,-Map,${TEST}/${TEST_EXECUTABLE}.map
-Xlinker
--allow-multiple-definition
-Xlinker
-mfpu=vfpv4-d16
-march=armv7-m
-mfloat-abi=hard
-mthumb
)
target_link_options(${TEST_EXECUTABLE} PUBLIC ${LOCAL_LDFLAGS})
I don’t know why these errors are coming when we build .c files. I am new to cross compiling. Why
libc++.a required for linking .c files?
Initially I thought , I am missing .a
files during linkage. So I have added these files in the LD flags like below
<code>TOOLCHAIN_LIB ==> "C:compilertoolchainsarmv8.1.0armlibv7-mthumb"
-I${TOOLCHAIN_LIB}/vfpv4/hard/sp_d16/libclang_rt.builtins.a
-I${TOOLCHAIN_LIB}/vfpv4/hard/sp_d16/except/libdnk.a
-I${TOOLCHAIN_LIB}/libunwind.a
-I${TOOLCHAIN_LIB}/vfpv4/hard/sp_d16/except/libc++.a
-I${TOOLCHAIN_LIB}/vfpv4/hard/sp_d16/except/libc++abi.a
<code>TOOLCHAIN_LIB ==> "C:compilertoolchainsarmv8.1.0armlibv7-mthumb"
-mfloat-abi=hard
-mthumb
-I${TOOLCHAIN_LIB}/vfpv4/hard/sp_d16/libclang_rt.builtins.a
-I${TOOLCHAIN_LIB}/vfpv4/hard/sp_d16/except/libdnk.a
-I${TOOLCHAIN_LIB}/libunwind.a
-I${TOOLCHAIN_LIB}/vfpv4/hard/sp_d16/except/libc++.a
-I${TOOLCHAIN_LIB}/vfpv4/hard/sp_d16/except/libc++abi.a
</code>
TOOLCHAIN_LIB ==> "C:compilertoolchainsarmv8.1.0armlibv7-mthumb"
-mfloat-abi=hard
-mthumb
-I${TOOLCHAIN_LIB}/vfpv4/hard/sp_d16/libclang_rt.builtins.a
-I${TOOLCHAIN_LIB}/vfpv4/hard/sp_d16/except/libdnk.a
-I${TOOLCHAIN_LIB}/libunwind.a
-I${TOOLCHAIN_LIB}/vfpv4/hard/sp_d16/except/libc++.a
-I${TOOLCHAIN_LIB}/vfpv4/hard/sp_d16/except/libc++abi.a
I can also see .a
files in the toolchain folder like above. However, even after adding these files, I am still encountering the same error. Has anyone else faced similar issues, or is there a workaround to resolve these errors?