我需要针对musl-libc编译一个C程序,以使其在嵌入式设备上运行。但是,我无法编译该程序。源代码取决于我传递给链接器的几个库,如下所示:/usr/local/musl/bin/musl-gcc app.c -o app -I../lib -lzlog -lfilter
这是我得到的输出:
/usr/local/musl/lib/libzlog.a(category.o): In function `strcpy':
/usr/include/x86_64-linux-gnu/bits/string3.h:110: undefined reference to `__memcpy_chk'
/usr/local/musl/lib/libzlog.a(conf.o): In function `strcpy':
/usr/include/x86_64-linux-gnu/bits/string3.h:110: undefined reference to `__strcpy_chk'
/usr/include/x86_64-linux-gnu/bits/string3.h:110: undefined reference to `__strcpy_chk'
/usr/include/x86_64-linux-gnu/bits/string3.h:110: undefined reference to `__strcpy_chk'
/usr/include/x86_64-linux-gnu/bits/string3.h:110: undefined reference to `__strcpy_chk'
/usr/local/musl/lib/libzlog.a(event.o): In function `sprintf':
/usr/include/x86_64-linux-gnu/bits/stdio2.h:33: undefined reference to `__sprintf_chk'
/usr/include/x86_64-linux-gnu/bits/stdio2.h:33: undefined reference to `__sprintf_chk'
/usr/local/musl/lib/libzlog.a(format.o): In function `memcpy':
/usr/include/x86_64-linux-gnu/bits/string3.h:53: undefined reference to `__memcpy_chk'
/usr/local/musl/lib/libzlog.a(record.o): In function `strcpy':
/usr/include/x86_64-linux-gnu/bits/string3.h:110: undefined reference to `__memcpy_chk'
/usr/local/musl/lib/libzlog.a(rotater.o): In function `snprintf':
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64: undefined reference to `__snprintf_chk'
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64: undefined reference to `__snprintf_chk'
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64: undefined reference to `__snprintf_chk'
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64: undefined reference to `__snprintf_chk'
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64: undefined reference to `__snprintf_chk'
/usr/local/musl/lib/libzlog.a(rule.o): In function `syslog':
/usr/include/x86_64-linux-gnu/bits/syslog.h:31: undefined reference to `__syslog_chk'
/usr/local/musl/lib/libzlog.a(rule.o): In function `strcpy':
/usr/include/x86_64-linux-gnu/bits/string3.h:110: undefined reference to `__strcpy_chk'
/usr/local/musl/lib/libzlog.a(rule.o): In function `memcpy':
/usr/include/x86_64-linux-gnu/bits/string3.h:53: undefined reference to `__memcpy_chk'
/usr/local/musl/lib/libzlog.a(spec.o): In function `sprintf':
/usr/include/x86_64-linux-gnu/bits/stdio2.h:33: undefined reference to `__sprintf_chk'
/usr/local/musl/lib/libzlog.a(zc_profile.o): In function `vfprintf':
/usr/include/x86_64-linux-gnu/bits/stdio2.h:127: undefined reference to `__vfprintf_chk'
/usr/local/musl/lib/libzlog.a(zc_profile.o): In function `fprintf':
/usr/include/x86_64-linux-gnu/bits/stdio2.h:97: undefined reference to `__fprintf_chk'
/usr/include/x86_64-linux-gnu/bits/stdio2.h:97: undefined reference to `__fprintf_chk'
/usr/local/musl/lib/libzlog.a(zc_util.o): In function `snprintf':
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64: undefined reference to `__snprintf_chk'
/usr/local/musl/lib/libzlog.a(buf.o): In function `strcpy':
/usr/include/x86_64-linux-gnu/bits/string3.h:110: undefined reference to `__memcpy_chk'
/usr/local/musl/lib/libzlog.a(buf.o): In function `vsnprintf':
/usr/include/x86_64-linux-gnu/bits/stdio2.h:77: undefined reference to `__vsnprintf_chk'
/usr/include/x86_64-linux-gnu/bits/stdio2.h:77: undefined reference to `__vsnprintf_chk'
/usr/include/x86_64-linux-gnu/bits/stdio2.h:77: undefined reference to `__vsnprintf_chk'
collect2: error: ld returned 1 exit status
与gcc相同的命令可以正常工作。
这些功能不是在Musl中实现的吗?
最佳答案
问题中的include路径都是glibc文件,因此您似乎要链接的库似乎是使用glibc构建的。有时可以使它起作用,但是有局限性。在您的情况下,它是使用_FORTIFY_SOURCE
的glibc版本构建的,该版本使用musl中目前不可用的glibc中的符号(通常在musl上使用的_FORTIFY_SOURCE
实现的工作方式有所不同)。长期以来,将这项工作列入长期议程,但不是优先事项;如果可以的话,最好针对musl重建库。
关于c - musl-gcc : undefined reference to __memcpy_chk,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55246192/