Ubuntu9.10 gcc as ld编译Hello world 不能生成执行文件
Ubuntu9.10上 终端中
//***************************
//C语言程序 文件名为ctest.c
//程序
#include <stdio.h>
int main()
{
printf("Hello world!\n");
return 0 ;
}
//***************************
用gcc -S ctest.c
产生ctest.s文件
//****************************
.file "ctest.c"
.section .rodata
.LC0:
.string "Hello world!"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $16, %esp
movl $.LC0, (%esp)
call puts
movl $0, %eax
leave
ret
.size main, .-main
.ident "GCC: (Ubuntu 4.4.1-4ubuntu8) 4.4.1"
.section .note.GNU-stack,"",@progbits
//***************************************************
然后 as -o ctest.o ctest.s
生成ctest.o
然后 ld -o ctest ctest.o
接着就出现以下提示:
ld: warning: cannot find entry symbol _start; defaulting to 0000000008048074
ctest.o: In function `main':
ctest.c:(.text+0x11): undefined reference to `puts'
没产生执行文件ctest
问题出现在哪里
//***************************
//C语言程序 文件名为ctest.c
//程序
#include <stdio.h>
int main()
{
printf("Hello world!\n");
return 0 ;
}
//***************************
用gcc -S ctest.c
产生ctest.s文件
//****************************
.file "ctest.c"
.section .rodata
.LC0:
.string "Hello world!"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $16, %esp
movl $.LC0, (%esp)
call puts
movl $0, %eax
leave
ret
.size main, .-main
.ident "GCC: (Ubuntu 4.4.1-4ubuntu8) 4.4.1"
.section .note.GNU-stack,"",@progbits
//***************************************************
然后 as -o ctest.o ctest.s
生成ctest.o
然后 ld -o ctest ctest.o
接着就出现以下提示:
ld: warning: cannot find entry symbol _start; defaulting to 0000000008048074
ctest.o: In function `main':
ctest.c:(.text+0x11): undefined reference to `puts'
没产生执行文件ctest
问题出现在哪里
...全文
相关推荐
ubuntu10.10下测试gcc,gfortran编译器的helloworld工程
ubuntu10.10下测试gcc,gfortran编译器的helloworld工程 博客配套工程文档
如何在Linux下用gcc编译c程序
Linux 内核和许多其他自由软件以及开放源码应用程序都是用 C 语言编写并使用 GCC 编译的。
ubuntu环境下从零开始建立,编译,运行一个c程序的步骤
ubuntu环境下从零开始建立,编译,运行一个c程序的步骤。
8linux(ubuntu)安装 GCC 和 G++ C++ 开发环境.docx
linux(ubuntu)安装 GCC 和 G++ C++ 开发环境教程,通过指令直接安装。
在Linux下编译并运行C程序
在Linux下编译并运行C/C++程序的流程,包括环境设定,编译命令,makefile编写等


