温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

gcc编译选项

发布时间:2020-09-06 16:09:36 来源:网络 阅读:1825 作者:清风徐来918 栏目:开发技术


(1)fpic 和 fPIC 区别

在64位下编译动态库的时候,经常会遇到下面的错误

/usr/bin/ld: /tmp/ccQ1dkqh.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC


Use -fPIC or -fpic to generate code. Whether to use -fPIC or -fpic to generate code is target-dependent. The -fPIC choice always works, but may produce larger code than -fpic (mnenomic to remember this is that PIC is in a larger case, so it may produce larger amounts of code). Using -fpic option usually generates smaller and faster code, but will have platform-dependent limitations, such as the number of globally visible symbols or the size of the code. The linker will tell you whether it fits when you create the shared library. When in doubt, I choose -fPIC, because it always works.


-fPIC: 总是能够工作,但可能产生的代码较大

-fpic: 通常能产生更快更小的代码,但有平台限制。



(2)编译选项 -static 的作用

gcc编译选项gcc编译选项



(3)-march 指定目标架构选项

-march选项就是就是指定目标架构的名字,gcc就会生成针对目标架构优化的目标代码,如-march=prescott会生成针对i5或i7的目标码,从而充分发挥cpu的性能。

自gcc4.2,引入了 -march=native ,从而允许编译器自动探测目标架构并生成 针对目标架构优化的目标代码 ,这比手工设置要安全的多。

通过下面的命令查询当前机器的架构名称,比如:


#gcc -march=native -Q --help=target | grep march

 -march=                     haswell


有的时候编译会报 "no such instruction", (没有这个机器指令)

解决的方案:

1.makefile 中删掉 -march=native

2.找到正确的目标框架名称设置


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI