使用 gcc 时参数的顺序重要吗?
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
看来 gcc 接受不同类型的序列。 然而,什么是不可接受的顺序呢?论证的顺序重要吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您指定
-static
链接,那么一个重要的顺序是放置库的位置。基本上,如果您选择静态链接库,则应在代码之后指定库,因为 GCC 将首先扫描代码以查找外部库依赖项,然后检查要引入的库。如果您在需要的代码之前指定库GCC 会扫描并确定不需要库,最终会出现链接器错误。
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.