我需要针对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中实现的吗?
答案 0 :(得分:5)
问题中的包含路径都是glibc文件,因此您似乎要链接的库似乎是使用glibc构建的。有时可以使它起作用,但是有局限性。在您的情况下,它是使用_FORTIFY_SOURCE
的glibc版本构建的,它使用了glibc中的符号,这些符号目前在musl中不可用(通常在musl上使用的_FORTIFY_SOURCE
实现方式有所不同)。长期以来,将这项工作列入长期议程,但不是优先事项;如果可以的话,最好针对musl重建库。
答案 1 :(得分:1)
也许这与您的情况无关,但我在 linux 下使用 MinGW 进行交叉编译时遇到了同样的 __memcpy_chk
问题。
通过向链接器添加 -lssp
标志修复了这个未定义的引用。如果你有 configure
那么你可以做 LDFLAGS="-lssp" ./configure ...