免费注册 查看新帖 |

Chinaunix

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

hello world 编译 link [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-01-18 11:54 |只看该作者 |倒序浏览
想了解编译和link得过程.
不得其门.
什么是编译.
什么是链接.
#include <stdio.h>
int main()
{

printf("hello world \r\n");
return 1;
}
gcc hello.c
helloworld 从编译到加载得过程是什么样子.
我只知道傻傻的敲一个./a.out .被linux侮辱了.

论坛徽章:
0
2 [报告]
发表于 2008-01-18 13:21 |只看该作者
man gcc
man  objdump
刚看到一本书<c标准与实践>,也许对你有用

[ 本帖最后由 ruoyisiyu 于 2008-1-18 13:24 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2008-01-18 13:22 |只看该作者
欢迎lz来到linux世界
你的问题不是几页能回答的。
不过给你加油努力,
被linux侮辱了不可笑,侮辱了linux就可笑了。

论坛徽章:
0
4 [报告]
发表于 2008-01-18 13:53 |只看该作者
gnu的编译前先有预处理阶段,把好多文件加载进来,很多宏定义、inline函数等展开。
−E Stop after the preprocessing stage; do not run the compiler proper. The output is in the form of preprocessed
source code, which is sent to the standard output.
Input files which don’t require preprocessing are ignored.
然后可以只生产目标文件,注意这样可以实现多文件的书写代码,然后最后link到一起,期间可能会link一些标准库之类的
−c Compile or assemble the source files, but do not link. The linking stage simply is not done. The ultimate
output is in the form of an object file for each source file.
By default, the object file name for a source file is made by replacing the suffix .c, .i, .s, etc., with .o.
Unrecognized input files, not requiring compilation or assembly, are ignored.
当然gcc也支持翻译到汇编代码
−S Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler
code file for each non-assembler input file specified.
By default, the assembler file name for a source file is made by replacing the suffix .c, .i, etc., with .s.
Input files that don’t require compilation are ignored.

可能我讲的有点乱,而且浮于表面
具体可以参考gcc文档

论坛徽章:
0
5 [报告]
发表于 2008-01-18 14:17 |只看该作者
《linker and loader》这个书最能解决楼主的困惑,不过需要楼主具备一定的知识。

论坛徽章:
0
6 [报告]
发表于 2008-01-18 14:19 |只看该作者
原帖由 ruoyisiyu 于 2008-1-18 13:21 发表
man gcc
man  objdump
刚看到一本书,也许对你有用

thank you 回答.帮顶!

论坛徽章:
0
7 [报告]
发表于 2008-01-18 14:20 |只看该作者
原帖由 scuhkr 于 2008-1-18 13:22 发表
欢迎lz来到linux世界
你的问题不是几页能回答的。
不过给你加油努力,
被linux侮辱了不可笑,侮辱了linux就可笑了。

thank you 回答.帮顶!

论坛徽章:
0
8 [报告]
发表于 2008-01-18 14:21 |只看该作者
原帖由 bsdc 于 2008-1-18 13:53 发表
gnu的编译前先有预处理阶段,把好多文件加载进来,很多宏定义、inline函数等展开。
−E Stop after the preprocessing stage; do not run the compiler proper. The output is in the form of preprocess ...

thank you 回答.帮顶!

论坛徽章:
0
9 [报告]
发表于 2008-01-18 14:22 |只看该作者
原帖由 bsdc 于 2008-1-18 13:53 发表
gnu的编译前先有预处理阶段,把好多文件加载进来,很多宏定义、inline函数等展开。
−E Stop after the preprocessing stage; do not run the compiler proper. The output is in the form of preprocess ...

thank you 回答.帮顶!

论坛徽章:
0
10 [报告]
发表于 2008-01-18 14:23 |只看该作者
原帖由 Sorehead 于 2008-1-18 14:17 发表
《linker and loader》这个书最能解决楼主的困惑,不过需要楼主具备一定的知识。

thank you 回答.帮顶!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP