【发布时间】:2021-11-25 08:50:26
【问题描述】:
我正在尝试将 socket() 系统调用与我自己的自定义 __wrap_socket() 系统调用包装在 lighttpd(Web 服务器应用程序)中的 wrap.c 文件中。
Lighttpd 使用自动工具来构建,我正在尝试使用 musl 完全静态地构建它。
我传递的configure脚本如下:
CC="/home/riscv64-linux-musl-cross/bin/riscv64-linux-musl-gcc" CFLAGS="-g -Wl,--wrap=socket -static --static -static-libstdc++ -static-libgcc /home/lighttpd/wrap.c" LDFLAGS="-L/musl/lib/ -lcrypt -lc" ./configure --prefix=/lighttpd/install/ --enable-static --without-zlib --without-bzip2 --without-pcre
但是,由于 lighttpd 的构建脚本和由 autotools 生成的 Makefile,我收到以下错误(我只包含了许多错误中的一部分):
/home/riscv64-linux-musl-cross/bin/riscv64-linux-musl-gcc -DHAVE_CONFIG_H -DHAVE_VERSIONSTAMP_H -DLIBRARY_DIR="\"/home/lighttpd/install/lib\"" -DSBIN_DIR="\"/home/lighttpd/install/sbin\"" -I. -I.. -DDEBUG_PROC_OPEN -D_REENTRANT -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES -g -Wl,--wrap=socket -static --static -static-libstdc++ -static-libgcc /home/lighttpd/wrap.c -Wall -W -Wshadow -pedantic -MT proc_open-proc_open.o -MD -MP -MF .deps/proc_open-proc_open.Tpo -c -o proc_open-proc_open.o `test -f 'proc_open.c' || echo './'`proc_open.c
riscv64-linux-musl-gcc: fatal error: cannot specify ‘-o’ with ‘-c’, ‘-S’ or ‘-E’ with multiple files
但是,如果我没有在 CFLAGS 参数中包含 wrap.c 文件的路径,我会收到以下错误:
/home/riscv64-linux-musl-cross/bin/../lib/gcc/riscv64-linux-musl/10.2.1/../../../../riscv64-linux-musl/bin/ld: /home/musl/lib//libc.a(if_nametoindex.lo):/home/musl-1.1.23/src/network/if_nametoindex.c:13: more undefined references to `__wrap_socket' follow
和
/home/riscv64-linux-musl-cross/bin/../lib/gcc/riscv64-linux-musl/10.2.1/../../../../riscv64-linux-musl/bin/ld: /home/lighttpd/src/fdevent.c:491: undefined reference to `__wrap_socket'
我在文件 wrap.h 中有 wrap.c 函数 (__wrap_socket()),该文件已包含在 lighttpd 的主文件 (server.c) 中。任何帮助将不胜感激。
【问题讨论】:
标签: c linux gcc autotools lighttpd