Making gcc a windows .exe file

V

Victor Bazarov

cplusplus said:
Hi, I just started a C++ cource in school and am using
gcc --version 3.3.1 (Suse Linux 9.0). Everything is
working great except I need to have the exacuatable in
".exe" format and be able to run on a windows machine.
I asked my teacher how this could be done and he told
me by using the "-o" option or I could
simply rename the a.out file to "helloworld.exe".

Your teacher played a cruel joke on you. The name of the
file and the internal format of the executable are not at
all connected.
I used the following command:

g++ -ansi -pedantic -Wall -o helloworld.exe helloworld.cpp

It works great, but I was a bit skeptical so I put the file
on a floppy and tried opening it on a windows machine. The
file wont open and says that there is an error reading the file.
I assume this is because the program is a linux exacuatable file.
Is there a command I can use to make it an actual windows .EXE file?
No.

I tried looking through the man page and just couldn't find it.

You need what is known as a "cross-compiler". The compiler
that comes with your OS is only going to produce executables
for that OS.

Please ask in a newsgroup dedicated to your platform (either
one would do) since here it is off-topic. Yours is not a C++
_language_ problem but a C++ _compiler_ problem.

Victor
 
R

Russell Hanneken

cplusplus said:
Hi, I just started a C++ cource in school and am using
gcc --version 3.3.1 (Suse Linux 9.0). Everything is
working great except I need to have the exacuatable in
".exe" format and be able to run on a windows machine.
I asked my teacher how this could be done and he told
me by using the "-o" option or I could
simply rename the a.out file to "helloworld.exe".

I think maybe your instructor misunderstood what you were asking him.
He probably thought you were using a Windows version of GCC, and you
just wanted to know how to specify the name of the output file.

GCC actually can build executables for different platforms. You might
have to rebuild your compiler to get it to target Windows, though.

You should really ask this question on the newsgroup gnu.gcc.help.
comp.lang.c++ is for discussion of the C++ language, rather than
particular development tools like GCC. See the welcome message for this
group:

http://www.slack.net/~shiva/welcome.txt

Regards,

Russell Hanneken
(e-mail address removed)
Remove the 'g' from my address to send me mail.
 
R

Robert Diamond

There are ports of gcc to windows (ie: dev-cpp, is a windows IDE which uses
the ming gcc compiler on a windows box to compile windows binaries.) I'd
just install windows 98/95 and use it to compile your projects. Compile,
debug, etc... on your *nix install and then run your win install and open up
dev-c++/cywin etc... and compile.

If you do some googling someone's probably already done from a *nix box.
Probably some includes and special params to gcc or a different source tree
of gcc with win32 binary support. google it up ;)
 
C

cplusplus

Hi, I just started a C++ cource in school and am using
gcc --version 3.3.1 (Suse Linux 9.0). Everything is
working great except I need to have the exacuatable in
".exe" format and be able to run on a windows machine.
I asked my teacher how this could be done and he told
me by using the "-o" option or I could
simply rename the a.out file to "helloworld.exe".
I used the following command:

g++ -ansi -pedantic -Wall -o helloworld.exe helloworld.cpp

It works great, but I was a bit skeptical so I put the file
on a floppy and tried opening it on a windows machine. The
file wont open and says that there is an error reading the file.
I assume this is because the program is a linux exacuatable file.
Is there a command I can use to make it an actual windows .EXE file?
I tried looking through the man page and just couldn't find it.
Thanks for helping a newbie.

--Cameron
 
Joined
Jun 22, 2010
Messages
1
Reaction score
0
gcc for windows

You need a specific version of gcc to compile windows executables. Such precompiled versions of gcc are freely available, see mstenberg.com/blog/2010/06/13/gcc-for-windows/ for a quick getting-started guide.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top