gcc-如何从静态库输出(.a)中删除所有绝对路径 [英] gcc - How to remove all absolute path from static library output (.a)

查看:132
本文介绍了gcc-如何从静态库输出(.a)中删除所有绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using GCC for ARM (Red Suite 4 NXP). I am compiling static library files (.a) that are used for a final application. I need to configure the project so any developer can produce the exact same static library output. (This is mainly so a new developer can verify they have their setup correct.) I have two copies of my project (two checkouts from SVN). When I build with each, I notice some absolute path information in the static library .a output files. This means that SVN detects as a change. I'm using the ar -D (deterministic) option already. Are there any other options to remove path information? I tried gcc -s but this didn't work (it appears this is only for final executable, not libraries)

我不知道.a中绝对路径的位置/原因,但是如果有人可以将我指向正确的方向,我可以提供更多信息.

I don't know where/why the absolute paths are in the .a, but I can provide more information if someone can point me in the right direction.

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

I've looked at the strip utility man pages (haven't tried it yet), would this remove this path information?

此外,我正在使用Red Suite来管理项目,所以我试图以Red Suite的方式进行操作(并让它完成其工作).但是,如果有我需要调整的gcc或ar选项,我确实知道该怎么做.我只是不知道要更改什么选项.

Also, I am using Red Suite to manage the project, so I'm trying to do things the Red Suite way (and to let it do its thing). However, if there is a gcc or ar option I need to adjust, I do know how to do that. I just don't know what option to change.

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

Here is the build console output. This causes the absolute path of my project to be included into the resulting .a. That is what I am trying to fix.

**** 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文件中的路径数据显示

I have done some more digging, and it appears the full file path is in front of a string constant. The path data within the .a file shows

C:/Users/my_user_name/Documents/My Project Verification build/src/touch/Touch.c.TouchIdleTimer

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

I have a string literal "TouchIdleTimer" within the file Touch.c. Is this the cause? How would I remove the path portion, or is it possible? TIA

推荐答案

更新

通过此答案

Via this answer to GCC: static linking only some libraries

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

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


代码Red IDE v4中增强的静态库支持:创建静态库项目

四处搜寻,我看到有关-fPIC-fpic的建议.推荐在此评论主题中的="nofollow noreferrer"> .

Searching around I'm seeing suggestions for -fPIC or -fpic. It was recommended in this comment thread in response to a question similar to yours.

3.2共享库和静态库提供了一个不错的选择编译共享库和静态库的细目.

3.2 Shared libraries and static libraries provides a nice breakdown of compiling shared and static libraries.

您说静态不是共享库,只是为了以防万一:如何编写共享库

You stated static not shared libraries but just in case: How to Write Shared Libraries

这篇关于gcc-如何从静态库输出(.a)中删除所有绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆