【问题标题】:arm-linux-gnueabihf-ld: unrecognized option '-Wl,--gc-sections'arm-linux-gnueabihf-ld:无法识别的选项'-Wl,--gc-sections'
【发布时间】:2018-01-29 00:39:31
【问题描述】:

我正在使用link 为树莓派交叉编译 Qt,但我遇到了一些问题。在执行sudo make 时,我得到以下信息:

~/rpi-xtools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-ld -Wl,--gc-sections -Wl,-O1 -fuse-ld=gold -o ../../../bin/moc .obj/moc.o .obj/preprocessor.o .obj/generator.o .obj/parser.o .obj/token.o .obj/main.o   -L/home/ytan/rpi-xtools/delme/qtbase/lib -lQt5Bootstrap -lpthread 
/home/ytan/rpi-xtools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-ld: unrecognized option '-Wl,--gc-sections'

我知道-Wl,--gc-sections 是 arm-linux-gnueabihf-g++ 的命令,而不是 arm-linux-gnueabihf-ld,但我不知道应该深入研究哪个 Makefile 来更改 arm-linux-gnueabihf- ld 到 arm-linux-gnueabihf-g++。

我拼命地寻找你,哦,网络上的神秘居民。

【问题讨论】:

    标签: linux qt raspberry-pi


    【解决方案1】:
    arm-linux-gnueabihf-ld: unrecognized option '-Wl,--gc-sections'
    

    您正在直接调用链接器。链接器得到--gc-sections,而不是-Wl,--gc-sections

    如果您通过编译器驱动程序进行链接,那么您将使用-Wl,--gc-sections。这个食谱看起来像arm-linux-gnueabihf-gcc ... -o moc -Wl,--gc-sections

    确保您的编译标志包括-ffunction-sections 和/或-fdata-sections


    我不知道应该深入研究哪个 Makefile 将 arm-linux-gnueabihf-ld 更改为 arm-linux-gnueabihf-g++。

    由于直接调用链接器,并且如果项目设置正确,那么您只需要:

        CPPFLAGS="-DNDEBUG -g2 -O3 ... " \
        CFLAGS="... -ffunction-sections -fdata-sections" \
        CXXFLAGS="... -ffunction-sections -fdata-sections" \
        LDFLAGS="... --gc-sections" \
    ./configure <other config options>
    

    如果您有一定的灵活性,那么您应该通过编译器驱动程序转换为链接。这是 Clang 和 GCC 的人推荐的,它可以很容易地做一些事情,比如用消毒剂(-fsanitize=address-fsanitize=undefined 等)测试你的程序。编译器将为您添加适当的库。否则,您将需要自己弄清楚它们(在某些系统上很重要,例如 OS X)。

    【讨论】:

    • "你正在直接调用链接器。"
    • "...那么您应该通过编译器驱动程序转换为链接。"
    • 该过程与您用于CFLAGSCXXF:AGS-ffunction-sections -fdata-sections 的过程应该没有太大区别。这只是一个不同的make variable
    猜你喜欢
    • 1970-01-01
    • 2021-04-04
    • 2014-02-13
    • 2019-09-14
    • 1970-01-01
    • 2014-09-04
    • 1970-01-01
    • 1970-01-01
    • 2015-10-09
    相关资源
    最近更新 更多