gcc简单案例

gcc编译so和可执行文件

gcc -o libfun1.so fun1.cpp -shared -fPIC
就可以得到文件名为libfun1.so的文件了。

其中 -shared选项说明编译成的文件为动态链接库,不使用该选项相当于可执行文件

-fPIC 表示编译为位置独立的代码,不用此选项的话编译后的代码是位置相关的。

加载so编译可执行文件

gcc -std=c++11 -o main main.cpp -I./fun1/ -lfun1 -L./fun1/
 

C++版本设置

The default mode is C++98 for GCC versions prior to 6.1, and C++14 for GCC 6.1 and above. You can use command-line flag -std to explicitly specify the C++ standard. For example,

-std=c++98, or -std=gnu++98 (C++98 with GNU extensions)

-std=c++11, or -std=gnu++11 (C++11 with GNU extensions)

-std=c++14, or -std=gnu++14 (C++14 with GNU extensions), default mode for GCC 6.1 and above.

-std=c++17, or -std=gnu++17 (C++17 with GNU extensions), experimental.

-std=c++2a, or -std=gnu++2a (C++2a with GNU extensions), experimental.

 

头文件路径,库目录,库名称路径设置

-I, -L and -l,

-I/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include

-L/lib

-lgcc_s     // libgcc_s.a

如果加载的库还依赖其它库,要把路径加载到

export LD_LIBRARY_PATH=xxdir:$LD_LIBRARY_PATH

 

参考

https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html

https://blog.csdn.net/gaoxiang__/article/details/38094525

 

https://colobu.com/2018/08/28/15-Most-Frequently-Used-GCC-Compiler-Command-Line-Options/

https://blog.csdn.net/gatieme/article/details/21389603

https://blog.csdn.net/fengbingchun/article/details/80960916

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Luchang-Li

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值