添加选项-lc -lstdc ++或-specs = nosys.specs允许使用arm-none-eabi-gcc v4.9进行编译

时间:2019-04-18 19:59:42

标签: linux gcc cmake linker arm

我在项目中添加了一个在线modbus库:freemodbus,之后我发现它在链接阶段失败,并带有以下未定义的引用:

/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv7e-m/libc_nano.a(lib_a-signalr.o): In function `_kill_r':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build_nano/arm-none-eabi/armv7e-m/newlib/libc/reent/../../../../../../newlib/libc/reent/signalr.c:61: undefined reference to `_kill'
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv7e-m/libc_nano.a(lib_a-signalr.o): In function `_getpid_r':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build_nano/arm-none-eabi/armv7e-m/newlib/libc/reent/../../../../../../newlib/libc/reent/signalr.c:97: undefined reference to `_getpid'
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv7e-m/libc_nano.a(lib_a-fstatr.o): In function `_fstat_r':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build_nano/arm-none-eabi/armv7e-m/newlib/libc/reent/../../../../../../newlib/libc/reent/fstatr.c:62: undefined reference to `_fstat'
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/armv7e-m/libc_nano.a(lib_a-isattyr.o): In function `_isatty_r':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build_nano/arm-none-eabi/armv7e-m/newlib/libc/reent/../../../../../../newlib/libc/reent/isattyr.c:58: undefined reference to `_isatty'
collect2: error: ld returned 1 exit status

现在,在在线研究之后,我发现将以下EITHER添加到链接器选项标志可以解决此问题:

1. target_link_libraries(... -lc -lstdc++)
2. target_link_libraries(... -specs=nosys.specs)

我认为我与第一个选择有关的事实是,这些库的顺序很重要,因此,即使它们已经被特别是libc包括在内,它们也需要再次被包含或以仪式顺序被包含吗?

我只是不了解第二个:我知道它与syscalls有关?一些研究引起了他的注意: “似乎没有系统调用。您可以使用spec nosys.specs或    rdimon.specs;或使用自定义的系统调用。”

有人可以澄清这些假设是否正确吗?

谢谢

0 个答案:

没有答案