gpt4 book ai didi

gcc - 如何从静态库输出 (.a) 中删除所有绝对路径

转载 作者:行者123 更新时间:2023-12-04 12:22:59 25 4
gpt4 key购买 nike

我正在为 ARM 使用 GCC ( Red Suite 4 NXP )。我正在编译用于最终应用程序的静态库文件 (.a)。我需要配置项目,以便任何开发人员都可以生成完全相同的静态库输出。 (这主要是为了让新开发人员可以验证他们的设置是否正确。)我有我的项目的两个副本(两个从 SVN checkout )。当我使用每个构建时,我注意到静态库 .a 输出文件中的一些绝对路径信息。这意味着 SVN 会检测到更改。我已经在使用 ar -D(确定性)选项。还有其他选项可以删除路径信息吗?我试过 gcc -s 但这没有用(这似乎只适用于最终的可执行文件,而不是库)

我不知道 .a 中的绝对路径在哪里/为什么,但如果有人能指出我正确的方向,我可以提供更多信息。

我已经查看了 strip 实用程序手册页(还没有尝试过),这会删​​除此路径信息吗?

此外,我正在使用 Red Suite 来管理项目,所以我正在尝试以 Red Suite 的方式做事(并让它做它的事)。但是,如果我需要调整 gcc 或 ar 选项,我知道该怎么做。我只是不知道要更改什么选项。

这是构建控制台输出。这会导致我的项目的绝对路径包含在生成的 .a 中。这就是我正在努力解决的问题。

**** Build of configuration Release for project lib_touch ****

make -j all
Building file: C:/Users/my_user_name/Documents/My Project Verification build/src/touch/Touch.c
Building file: C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchCalibration.c
Building file: C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchPoint.c
Building file: C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchEventQueue.c
Invoking: MCU C Compiler
Invoking: MCU C Compiler
arm-none-eabi-gcc -D__REDLIB__ -DNDEBUG -D__CODE_RED -D__USE_CMSIS=CMSISv2p00_LPC177x_8x -I"C:\Users\my_user_name\Documents\My Project Verification build\src\build\RedSuite4NXP\CMSISv2p00_LPC177x_8x\inc" -I../../../../board -I../../../../board/lpc1788 -I../../../../communication -I../../../../events -I../../../../geometry -I../../../../graphics -I../../../../hmilogic/include -I../../../../sound -I../../../../util -O3 -Wall -Werror -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -std=gnu99 -mcpu=cortex-m3 -mthumb -MMD -MP -MF"touch/Touch.d" -MT"touch/Touch.d" -o"touch/Touch.o" "C:/Users/my_user_name/Documents/My Project Verification build/src/touch/Touch.c"
arm-none-eabi-gcc -D__REDLIB__ -DNDEBUG -D__CODE_RED -D__USE_CMSIS=CMSISv2p00_LPC177x_8x -I"C:\Users\my_user_name\Documents\My Project Verification build\src\build\RedSuite4NXP\CMSISv2p00_LPC177x_8x\inc" -I../../../../board -I../../../../board/lpc1788 -I../../../../communication -I../../../../events -I../../../../geometry -I../../../../graphics -I../../../../hmilogic/include -I../../../../sound -I../../../../util -O3 -Wall -Werror -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -std=gnu99 -mcpu=cortex-m3 -mthumb -MMD -MP -MF"touch/TouchCalibration.d" -MT"touch/TouchCalibration.d" -o"touch/TouchCalibration.o" "C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchCalibration.c"
Invoking: MCU C Compiler
Invoking: MCU C Compiler
arm-none-eabi-gcc -D__REDLIB__ -DNDEBUG -D__CODE_RED -D__USE_CMSIS=CMSISv2p00_LPC177x_8x -I"C:\Users\my_user_name\Documents\My Project Verification build\src\build\RedSuite4NXP\CMSISv2p00_LPC177x_8x\inc" -I../../../../board -I../../../../board/lpc1788 -I../../../../communication -I../../../../events -I../../../../geometry -I../../../../graphics -I../../../../hmilogic/include -I../../../../sound -I../../../../util -O3 -Wall -Werror -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -std=gnu99 -mcpu=cortex-m3 -mthumb -MMD -MP -MF"touch/TouchEventQueue.d" -MT"touch/TouchEventQueue.d" -o"touch/TouchEventQueue.o" "C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchEventQueue.c"
Finished building: C:/Users/my_user_name/Documents/My Project Verification build/src/touch/Touch.c
arm-none-eabi-gcc -D__REDLIB__ -DNDEBUG -D__CODE_RED -D__USE_CMSIS=CMSISv2p00_LPC177x_8x -I"C:\Users\my_user_name\Documents\My Project Verification build\src\build\RedSuite4NXP\CMSISv2p00_LPC177x_8x\inc" -I../../../../board -I../../../../board/lpc1788 -I../../../../communication -I../../../../events -I../../../../geometry -I../../../../graphics -I../../../../hmilogic/include -I../../../../sound -I../../../../util -O3 -Wall -Werror -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -std=gnu99 -mcpu=cortex-m3 -mthumb -MMD -MP -MF"touch/TouchPoint.d" -MT"touch/TouchPoint.d" -o"touch/TouchPoint.o" "C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchPoint.c"

Finished building: C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchEventQueue.c
Finished building: C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchCalibration.c


Finished building: C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchPoint.c

Building target: lib_touch.a
Invoking: MCU Archiver
arm-none-eabi-ar -rD "lib_touch.a" ./touch/Touch.o ./touch/TouchCalibration.o ./touch/TouchEventQueue.o ./touch/TouchPoint.o
c:\code_red\RedSuiteNXP_4.3.0_1033\redsuite\tools\bin\arm-none-eabi-ar.exe: creating lib_touch.a
Finished building target: lib_touch.a

make --no-print-directory post-build
Performing post-build steps
arm-none-eabi-size "lib_touch.a" ; cp "lib_touch.a" "../../../../lib/lib_touch.a"; # arm-none-eabi-objdump -h -S "lib_touch.a" >"lib_touch.lss"
text data bss dec hex filename
1864 0 156 2020 7e4 Touch.o (ex lib_touch.a)
576 0 0 576 240 TouchCalibration.o (ex lib_touch.a)
320 0 0 320 140 TouchEventQueue.o (ex lib_touch.a)
96 0 0 96 60 TouchPoint.o (ex lib_touch.a)

更新:更多信息

我做了更多的挖掘,看起来完整的文件路径在字符串常量的前面。 .a 文件中的路径数据显示
C:/Users/my_user_name/Documents/My Project Verification build/src/touch/Touch.c.TouchIdleTimer

我在文件 Touch.c 中有一个字符串文字“TouchIdleTimer”。这是原因吗?我将如何删除路径部分,或者有可能吗? TIA

最佳答案

更新

Via this answerGCC: static linking only some libraries

Note: If you use full path of a .so file, it will again be linked in dynamically.



Enhanced Static Library Support in Code Red IDE v4: Creating static library projects

四处搜索,我看到了关于 -fPIC 的建议或 -fpic .有人推荐 in this comment thread回答与您类似的问题。

3.2 Shared libraries and static libraries提供了编译共享和静态库的很好的分割。

您声明静态不是共享库,但以防万一: How to Write Shared Libraries

关于gcc - 如何从静态库输出 (.a) 中删除所有绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14554287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com