我正从ubuntu的默认armhf交叉编译工具链迁移到bootlin.com的预编译工具链,以更好地控制项目的glibc版本。具体来说,我正在使用glibc 2.26和gcc 6.4.0
但是,我无法成功链接该项目。 链接时出现错误
/opt/glibc/arm-buildroot-linux-gnueabihf/bin/ld: ./src/foo.o: undefined reference to symbol 'socket@@GLIBC_2.4'
/opt/glibc/lib/gcc/arm-buildroot-linux-gnueabihf/sysroot/lib/libc.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
我的编译命令如下:
"/opt/glibc/bin/arm-buildroot-linux-gnueabihf-g++" -std=c++03 \
-nostdinc -nostdinc++ \
"-I"/opt/glibc/arm-buildroot-linux-gnueabihf/include/c++/6.4.0/"" \
"-I"/opt/glibc/arm-buildroot-linux-gnueabihf/include/c++/6.4.0/"/arm-linux-gnueabihf" \
"-I"/opt/glibc/arm-buildroot-linux-gnueabihf/include/c++/6.4.0/"/backward" \
"-I"/opt/glibc/arm-buildroot-linux-gnueabihf/include/c++/6.4.0/"/arm-buildroot-linux-gnueabihf" \
"-I"/opt/glibc/lib/gcc/arm-buildroot-linux-gnueabihf/6.4.0"/include" \
"-I"/opt/glibc/lib/gcc/arm-buildroot-linux-gnueabihf/6.4.0"/include-fixed" \
"-I"/opt/glibc/arm-buildroot-linux-gnueabihf/sysroot"/usr/include"" \
-I/opt/glibc/bin/../arm-buildroot-linux-gnueabihf/sysroot/usr/include/json-c -I/opt/glibc/bin/../arm-buildroot-linux-gnueabihf/sysroot/usr/include -I../3rdparty \
-O3 -Wall -Wextra -pedantic -c -fmessage-length=0 -MMD -MP -MF"src/foo.d" -MT"src/foo.d" -o "src/foo.o" "../src/foo.cpp"
我的链接命令如下:
"/opt/glibc/bin/arm-buildroot-linux-gnueabihf-g++" -v -o "out" \
-nostdlib -nostartfiles \
""/opt/glibc/arm-buildroot-linux-gnueabihf/sysroot"/usr/lib/crti.o" "/opt/glibc//lib/gcc/arm-buildroot-linux-gnueabihf/6.4.0"/crtbegin.o \
./src/foo.o ./src/bar.o \
-Wl,-Bstatic -L/opt/glibc/bin/../arm-buildroot-linux-gnueabihf/sysroot/usr/lib -ljson-c \
-Wl,-Bdynamic "-L"/opt/glibc/arm-buildroot-linux-gnueabihf/sysroot"/lib" "-L"/opt/glibc/arm-buildroot-linux-gnueabihf/sysroot"/usr/lib" "-L/opt/glibc/lib" -lrt -pthread -L/opt/glibc/bin/../arm-buildroot-linux-gnueabihf/sysroot/usr/lib -lbluetooth \
"/opt/glibc/lib/gcc/arm-buildroot-linux-gnueabihf/6.4.0"/crtend.o ""/opt/glibc/arm-buildroot-linux-gnueabihf/sysroot"/usr/lib/crtn.o"
我已经为此工作了好几个小时,没有任何进展。任何帮助表示赞赏。
答案 0 :(得分:2)
您与-nostdlib
链接。这意味着您必须显式链接到C库。但是您的链接器命令未提及-lc
或libc.so
。