【问题标题】:gcc - How to remove all absolute path from static library output (.a)gcc - 如何从静态库输出(.a)中删除所有绝对路径
【发布时间】:2013-01-11 08:01:12
【问题描述】:

我正在为 ARM 使用 GCC (Red Suite 4 NXP)。我正在编译用于最终应用程序的静态库文件 (.a)。我需要配置项目,以便任何开发人员都可以生成完全相同的静态库输出。 (这主要是为了让新开发人员可以验证他们的设置是否正确。)我有两个项目副本(来自 SVN 的两个结帐)。当我使用每个构建时,我注意到静态库 .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

【问题讨论】:

  • ar 通常不添加任何绝对路径。你能提供一些复制品吗?
  • @KonstantinVladimirov,我已将构建的控制台输出粘贴到问题正文中。如果您需要其他信息,请告诉我。 TIA
  • @Josh Petitt 您是否设法从静态库中删除这些绝对路径?
  • @halim 不,对不起,我已经有一段时间没有从事那个项目了

标签: gcc static-libraries


【解决方案1】:

更新

Via this answerGCC: static linking only some libraries

注意:如果您使用 .so 文件的完整路径,它将再次动态链接。


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

【讨论】:

  • 谢谢JSuar,我明天试试这个,让你知道。我在编写或编译库时没有遇到问题,它只是我要删除的路径。
  • 关于 ld 的 cmets 我认为不适用?我正在创建一个静态库,所以我只使用 gcc 和 ar? AFAIK,在我构建最终应用程序之前不会使用 ld?
  • 我创建了静态库项目,类似于您分享的“创建静态库项目”链接。
  • 我对这一切都不是很熟悉,但我认为发布我的发现可能会有所帮助。希望对您有所帮助。
  • 这个解决方案好运吗?你解决过你的问题吗?
猜你喜欢
  • 1970-01-01
  • 2018-10-12
  • 1970-01-01
  • 1970-01-01
  • 2012-11-26
  • 1970-01-01
  • 2019-03-04
  • 1970-01-01
  • 2010-11-04
相关资源
最近更新 更多