gcc编译exe
linux下gcc -c wen.c -o wen.o 生成.o文件gcc wen.o -o wen 就变成.exe文件
2. 为什么我用gcc编译c程序到最后无法自动生成一个exe程序
gcc 是 Linux 系统下面的 C 语言编译器。它和 WINDOWS 系统下面的 Microsoft Visual Studio C++ 6.0 不同,在 WINDOWS 系统下面对任何的一个源程序,经编译、链接、到最终生成的所有可执行程序必定都是以 *.exe 结尾的,*.exe 是 WINDOWS 系统下面的可执行程序的后缀;而 gcc 对 C 语言进行编译,并没有规定可执行程序的具体名字到底是什么。举例如下:
$gcc my_program.c <cr>
如果在命令行中,没有带任何参数的话,如果 C 语言源程序没有任何语法错误的话,那么生成的缺省的可执行文件就是:a.out;
$gcc my_program.c -o my_runfile <cr>
如果在命令行中,指定:-o 参数,代表对 my_program.c 进行编译后,生成的可执行文件名为:my_runfile。
同理,在进行命令行编译过程中,只要指定了 -o 参数,那么你后面的可执行文件名,就随便由你自己决定了,这个就没有一定之规了。
3. linux 下可以用gcc 编译windows可用的 exe文件吗
根据gcc的编译选项可以看出: 不能
由于Linux和windows是完全不兼容的, Linux上不使用文件后缀名来区分文件, 所以同样是gcc编译出来的文件,在Linux上可以执行, 在windows就不能了。
可以安装Cygwin模拟Linux环境,将源代码拷到windows下, 用Cygwin编译出exe文件,可以在Windows上执行。
4. 如何在Linux下用gcc将c语言文件编译成32位exe文件,且可以在Windows下运行
有方法的,不过要看你编绎出的程序需要用到多少windows的库,看看linux下有没有可以替代的,不过很多时候没有windows内核还是无法编译成功的。
方法一:安装mingw32
方法二:virtualbox安装xp的虚拟机
方法三:通过wine使用cl命令行编译
上面几个方法你可以尝试一下。
至于编辑嘛,高手一般直接就用vim,如果你觉得难用的话,可以用eclipse或者kdevelop,kdevelop有点像windows下VS,希望对你有所帮助

5. GCC编译器的参数与空格
按照INSTALL中的介绍,也是常用的方法,在configure的时候,加上–host=arm-linux,结果没有实现我们要的效果,没有将编译器从默认的
gcc改成arm-linux-gcc,编译器还是用的默认的gcc:
[crifan@localhost
lrzsz-0.12.20]$
CFLAGS=-O2
./configure
–host=arm-linux
loading
cache
./config.cache
………………..
checking
for
gcc…
(cached)
gcc
checking
whether
the
C
compiler
(gcc
-O2
)
works…
yes
checking
whether
the
C
compiler
(gcc
-O2
)
is
a
cross-compiler…
no
………………..
后来经过多次尝试,最后受默认的
CFLAGS=-O2
./configure
进行配置所启发,想到,是否可以将CC参数传入到configure中,
结果证实,如果没有自己的cache-file,即时加了对的CC参数,也还是无法传入:
[crifan@localhost
lrzsz-0.12.20]$
CFLAGS=-O2
CC=arm-linux-gcc
./configure
–host=arm-linux
loading
cache
./config.cache
………………..
checking
for
gcc…
(cached)
gcc
checking
whether
the
C
compiler
(gcc
-O2
)
works…
yes
checking
whether
the
C
compiler
(gcc
-O2
)
is
a
cross-compiler…
no
checking
whether
we
are
using
GNU
C…
(cached)
yes
………………..
而且,如果CC参数放在configure后面:
./configure
CC=arm-linux-gcc
则不能识别:
[crifan@localhost
lrzsz-0.12.20]$
CFLAGS=-O2
./configure
CC=arm-linux-gcc
configure:
warning:
CC=arm-linux-gcc:
invalid
host
type
………………..
参数传递必须像
CFLAGS=-O2
./configure
一样,将参数设置放在configure的前面:
CC=arm-linux-gcc./configure
才能识别的。
必须要自己制定自己的cache-file
然后用./configure进行新配置,加上CC参数,才会即时生效,编译器才可以变成我们要的arm-linux-gcc:
[crifan@localhost
lrzsz-0.12.20]$
CC=arm-linux-gcc
./configure
–cache-file=cache_file_0
–prefix=/usr/crifan/lrzsz
………………..
checking
for
gcc…
arm-linux-gcc
checking
whether
the
C
compiler
(arm-linux-gcc
)
works…
yes
checking
whether
the
C
compiler
(arm-linux-gcc
)
is
a
cross-compiler…
yes
checking
whether
we
are
using
GNU
C…
yes
………………..
否则,就无法将我们的CC参数传入了:
[crifan@localhost
lrzsz-0.12.20]$
CC=arm-linux-gcc
./configure
–prefix=/usr/crifan/lrzsz
………………..
checking
for
gcc…
(cached)
gcc
checking
whether
the
C
compiler
(gcc
)
works…
yes
checking
whether
the
C
compiler
(gcc
)
is
a
cross-compiler…
no
checking
whether
we
are
using
GNU
C…
(cached)
yes
………………..
[crifan@localhost
lrzsz-0.12.20]$
CFLAGS=-O2
CC=arm-linux-gcc
./configure
–cache-file=cache_file_0
loading
cache
cache_file_0
………………..
checking
for
gcc…
arm-linux-gcc
checking
whether
the
C
compiler
(arm-linux-gcc
-O2
)
works…
yes
checking
whether
the
C
compiler
(arm-linux-gcc
-O2
)
is
a
cross-compiler…
yes
checking
whether
we
are
using
GNU
C…
yes
最好此处在加上–prefix=/usr/crifan/lrzsz,表示具体安装到哪里
[crifan@localhost
lrzsz-0.12.20]$
CFLAGS=-O2
CC=arm-linux-gcc
./configure
–cache-file=cache_file_0
–prefix=/usr/crifan/lrzsz
loading
cache
cache_file_0
………………..
checking
for
gcc…
arm-linux-gcc
checking
whether
the
C
compiler
(arm-linux-gcc
-O2
)
works…
yes
checking
whether
the
C
compiler
(arm-linux-gcc
-O2
)
is
a
cross-compiler…
yes
checking
whether
we
are
using
GNU
C…
yes
………………..
其中,/usr/crifan/lrzsz是已经建立好的,已经存在的文件夹,上面这样表示编译后,
将生成的可执行文件安装拷贝到那个目录.
6. gcc编译后的文件怎样运行
Windows系统
假如生成的可执行文件名称为prog.exe,位于D:\cpp文件夹下,那么打开命令行,运行下面两条命令
cd D:\cpp
prog.exe
注意,如果用gcc编译的时候未指定可执行文件名称,则默认为a.exe
Linux系统
假如生成的可执行文件名称为prog,位于home下的CPP文件夹,那么打开终端,运行下面两条命令
cd ~/CPP
./prog
注意,如果用gcc编译的时候未指定可执行文件名称,则默认为a.out
7. 为什么我用gcc编译的.exe文件中文字显示不出来,是我代码有问题吗 #inc
不怕麻烦的话呢,可以调整#include结构来让各c文件相连。。
建议呢,把类型与函数的声明整理到特定的.h文件中,然后用#ifndef来使其只被包含一次,然后,在用到其它文件中实现的函数的时候将相应的.h文件include进来就好。这样呢,编译的时候可以单个文件逐一编译:
gcc -c main.c -o main.o
gcc -c del.c -o del.o
gcc -c insert.c -o insert.o
参数-c意思是只编译不连接,-o是名命输出文件。
全部编译成.o文件无误后,再将所有的.o文件相连:
gcc main.o del.o insert.o -o prog
就可以生成prog了。
然后举个例子说明处理.h文件:
比如这个create.c。里面定义了一个struct和一个函数。那么就可以写create.h如下:
#ifndef __CREATE_H__
#define __CREATE_H__
struct student
{
long num ;
float score;
struct student *next;
};
struct student *creat(void);
#endif
然后呢,因为student这个struct在这个.h文件里已经声明了,所以create.c里只要写#include "create.h",而在用到这个struct或者这个函数的场合,也只要这样简单一句就可以了。而.h文件开头的#ifndef可以保证同一个h文件不会被多次包含。当然,如果编译器支持的话,用#pragma once也许会比#ifndef更省事一些。
