使用gcc时参数的顺序是否重要

使用gcc时参数的顺序是否重要

本文介绍了使用gcc时参数的顺序是否重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  

如果您指定 -static 链接。



基本上,如果您选择静态链接库,则应在代码后指定库,因为GCC会首先扫描外部库依赖关系的代码,然后检查要引入的库。如果在需要它们的代码之前指定了库,GCC将扫描并确定不需要库,并且最终会出现链接器错误。 / p>

gcc  -o fig fig.c -I./include ./lib/libmylib.a -g

gcc -g  fig.c  -o fig -I./include ./lib/libmylib.a

gcc -g -o fig fig.c -I./include ./lib/libmylib.a

It seems that the gcc accept different kinds of sequence.However, what is a not acceptable sequence? Does the sequence of arguments matters?

解决方案

One sequence that does matter is where you put libraries if you specify -static linkage.

Basically, if you choose to statically link libraries in, the libraries should be specified after your code, as GCC will scan the code first for external library dependencies and then check the libraries to bring in. If you specified the libraries before the code that needs them, GCC would scan and determine no libraries were needed, and you'd end up with linker errors.

这篇关于使用gcc时参数的顺序是否重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 17:47