To make .exes in linux

Programming, for all ages and all languages.
OSMAN

To make .exes in linux

Post by OSMAN »

Hi.

Could you give me a simple makefile example of how can I compile my C-programs into ms-exe on linux?
(I have gcc, ld and all that)

(I need this information because the one I am teaching to program, uses Windows95 and we write the programs here, with my Linux)

I don't think that's very difficult when I just need to use stdandard C libs; doesn't DOS use them also?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:To make .exes in linux

Post by Solar »

The problem is that Windows executables have a different format (PE) than Linux (ELF). Also, the C standard lib you have installed under Linux has the same API as the one on Windows, on the front side, but on the back side it calls Linux kernel functions... so that doesn't help either.

You need a cross-compiler. If you are lucky, your Linux distro of choice offers a Mingw32 package; if not, you will have some tinkering to do...
Every good solution is obvious once you've found it.
OSMAN

Re:To make .exes in linux

Post by OSMAN »

Allright!

Now I have Mingw32. How can I use it?
OSMAN

Re:To make .exes in linux

Post by OSMAN »

^ Doesn't anybody really know? ^ :)
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:To make .exes in linux

Post by Solar »

MingW32 is, basically, a GCC generating Windows executables. Last time I looked, www.mingw.org held the docs. Which part gives you trouble?
Every good solution is obvious once you've found it.
OSMAN

Re:To make .exes in linux

Post by OSMAN »

The problem is that I don't get the purpose and usage of mingw at all, and the docs didn't help. If I write mingw or mingw32 to the command line: "command not found", even I installed the rpm succesfully. Has it some relationships with GCC? If has, how can I get GCC to produce exe-format?
(I don't think that's more complicated than a single commad line, but could you tell me it?)
AR

Re:To make .exes in linux

Post by AR »

How about the way GCC does all cross compilers:
i686-pc-mingw32-gcc -o something.exe something.o

You would obviously be able to find out what the proper name for the compiler program is by looking in /usr/bin [or /bin]...
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:To make .exes in linux

Post by Solar »

OSMAN wrote: ...the docs didn't help...

Has it some relationships with GCC?
You haven't read the docs.
Every good solution is obvious once you've found it.
Eero Ränik

Re:To make .exes in linux

Post by Eero Ränik »

Solar wrote: You haven't read the docs.
So cruel, but yet... so true.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:To make .exes in linux

Post by Candy »

Eero R?nik wrote: So cruel, but yet... so true.
No need to waste your time on something that can be easily explained and helped. Even shorter would be RTFM, but most people are offended by it nowadays.
OSMAN

Re:To make .exes in linux

Post by OSMAN »

Amazing, but true, and my own fault.
BUT DOES... let's calm down... but does:
$ gcc -c hello.c
produce hello.exe as they say at mingw.org?
I don't think so; it's a.out.

With the energy you have wasted by telling me "Haven't read the docs", you could have told me the command line twice.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:To make .exes in linux

Post by Candy »

OSMAN wrote: Amazing, but true, and my own fault.
BUT DOES... let's calm down... but does:
$ gcc -c hello.c
produce hello.exe as they say at mingw.org?
I don't think so; it's a.out.

With the energy you have wasted by telling me "Haven't read the docs", you could have told me the command line twice.
No we couldn't.

By reading the docs you will gain a deeper understanding of how stuff works, and without this sense of how it works you will NEVER, I repeat, NEVER, create a decent OS that is in fact your own. You will never belong to the top bit of programmers that can help you with problems and that can solve things that people consider unsolvable or very hard.

We could read the doc, figure out what's meant by it and tell you. If we did that, you would come here next time and complain "the program I compiled doesn't run in linux" or some other question (emphasis on it being a question that is also pretty much described in documents which you haven't read). We'd keep answering your questions for you, you wouldn't learn a thing and you'd be wasting our expensive time.

Now, if you have a question that isn't answered in accompanying documents, we're more than happy to help you since it isn't a waste of our time then.

PS: final answer: No it keeps producing Linux executables (which are very probably elf files). It would be very stupid to replace your system compiler with a cross compiler.
OSMAN

Re:To make .exes in linux

Post by OSMAN »

This windows-exe thing has nothing to do with my OS, that's why I'd rather read documentation about system programming than getting deeper into some minwg32 docs. I just have a friend who'd like to run the helloworld-dos-programs we write in my house on his computer with Windwz. Now the thing is, that I'm not like that I'd just be not reading the manuals and asking everything from you right away; but as I mentioned, producing exes in linux, I just wanted to know the command line option for it without studying everything about it. But I guess that wasn't as simple as that then. And we can run the elfs here so no problem.
Eero Ränik

Re:To make .exes in linux

Post by Eero Ränik »

Actually, it was as simple as that. I mean, AR posted everything you wanted to know, if you bothered to scroll up a bit and look at his post.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:To make .exes in linux

Post by Candy »

There's a hint hidden in my distinguishment of "system compiler" with "cross compiler". Which does normal "gcc" invoke?
Post Reply