免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2673 | 回复: 1
打印 上一主题 下一主题

gcc选项-fPIC的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-02-07 15:34 |只看该作者 |倒序浏览
首先-fpic,gcc手册上说是编译共享库库
-fPIC,gcc手册上说是动态链接

是不是-fPIC就是支持动态链接的共享库?

Configured with: /dw/gaoming/x01tool/buildroot/toolchain_build_arm/gcc-4.0.1/configure --prefix=/dw/buildroot/build_arm/staging_dir --build=i386-pc-linux-gnu --host=i386-pc-linux-gnu --target=arm-linux-uclibc --enable-languages=c,c++ --disable-__cxa_atexit --enable-target-optspace --with-gnu-ld --disable-shared --disable-nls --enable-threads --enable-multilib
Thread model: posix
gcc version 4.0.1

这个工具链在编译时候加上-fPIC选项和不加fPIC是有区别的,加了可以达到共享库的效果

Configured with: ../gcc-3.4.2/configure --prefix=/opt/toolchains/uclibc-crosstools_gcc-3.4.2_uclibc-20050502/ --target=mips-linux-uclibc --build=mips-linux --host=mips-linux --enable-target-optspace --disable-nls --with-gnu-ld --enable-shared --enable-languages=c,c++ --enable-threads --infodir=/opt/toolchains/uclibc-crosstools_gcc-3.4.2_uclibc-20050502/info --mandir=/opt/toolchains/uclibc-crosstools_gcc-3.4.2_uclibc-20050502/man --disable-__cxa_atexit --disable-checking --with-arch=mips32
Thread model: posix
gcc version 3.4.2

这个工具链加不加fPIC都可以达到共享库的效果

我看他们的区别就是--disable-shared  --enable-shared
我的理解是gcc enable-shared后就不用加fPIC选项了,不知道是否正确

另外我想知道,机器上已经装好gcc了,我如何在命令行中改变gcc的配置?

论坛徽章:
0
2 [报告]
发表于 2009-02-08 16:56 |只看该作者
-fpic
           Generate position-independent code (PIC) suitable for use in a
           shared library, if supported for the target machine.         Such code
           accesses all constant addresses through a global offset table
           (GOT).  The dynamic loader resolves the GOT entries when the pro-
           gram starts (the dynamic loader is not part of GCC; it is part of
           the operating system).  If the GOT size for the linked executable
           exceeds a machine-specific maximum size, you get an error message
           from the linker indicating that -fpic does not work; in that case,
           recompile with -fPIC instead.  (These maximums are 16k on the m88k,
           8k on the Sparc, and 32k on the m68k and RS/6000.  The 386 has no
           such limit.)

           Position-independent code requires special support, and therefore
           works only on certain machines.  For the 386, GCC supports PIC for
           System V but not for the Sun 386i.  Code generated for the IBM
           RS/6000 is always position-independent.

       -fPIC
           If supported for the target machine, emit position-independent
           code, suitable for dynamic linking and avoiding any limit on the
           size of the global offset table.  This option makes a difference on
           the m68k, m88k, and the Sparc.

           Position-independent code requires special support, and therefore
           works only on certain machines.

评分

参与人数 1可用积分 +1 收起 理由
samon_fu + 1 虽然是man手册信息,但是管用。分不多 ...

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP