c c++ 在linux上编译

来源:互联网 发布:mysql nosql 编辑:程序博客网 时间:2024/05/17 21:54

C语言编译:gcc[options] [filenames]

当不使用任何编译选项编译hello.c时,gcc将会自动编译产生一个a.out的可执行文件

vim test1.c

root@ubuntu-daisy:~/daisy# cat test1.c

#include<stdio.h>

int main(){

printf("helloxiujuan!\n");

}

gcc test1.c

linux会自动生成a.out 文件

./a.out

输出结果 hello Xiujuan

使用-o编译选择,可以为编译后的文件指定一个名:

root@ubuntu-daisy:~/daisy# ls

test1.c 

root@ubuntu-daisy:~/daisy# gcc test1.c -o hello

root@ubuntu-daisy:~/daisy# ls

hello  test1.c 

root@ubuntu-daisy:~/daisy# ./hello

Hello World!

 

C++ 编译:

 vim test2.cc

root@ubuntu-daisy:~/daisy# cat test2.cc

#include <iostream>

using namespace std;

int main(){

                 cout <<" hello world" <<endl;

g++ test2.cc

linux会自动生成a.out文件

./a.out

输出结果hello world





0 0
原创粉丝点击