Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to build a .exe file under Linux using gfortran 1

Status
Not open for further replies.

moppelg

Technical User
Apr 26, 2009
7
DE
Hello,
I want to create .exe files using gefortran under Linux. But when I type:

gfortran -o test.exe test.f95

in the console I can't open test.exe" on Windows.

To open all *.out files on Linux is no problem.

- Are there any flags I must set to create *.exe files?
- Or is it only possible to create a functional *.exe compiling the code using gfortran in Windows?

Thanks in advance!

Best regards,

moppel
 
Linux and Windows are two different systems. Executables on Linux will not work on Windows and vice-versa.
 
Thanks for your answer xwb. I know about this.

But my hope was, that I can also compile *.exe files for windows using some flags.

If you're right I have to use a second pc with windows and a fortran compiler on it and compile it again?! What a pity
 
Perhaps MinGW would make it possible - read here:
As I understood you should download the shell scripts from the above page and build the cross compiler suite via the shell script x86-mingw32-build.sh.
The other way as I read here
how to install MinGW would be with
sudo apt-get install mingw32

Then you could probably compile a C program for Windows using a shell-script named i586-pc-mingw32-gcc.
I thing something like this would be then possible
i586-pc-mingw32-gcc -o myprog.exe myprog.c

But I don't know if a fortran script is provided too? Probably not, then you need to solve, how to feed gcc with your fortran code. Compiling first using gfortran or g77 into object code and then linking with gcc? Or using f2c?
 
If you hava gcc woth fortran enabled, then this should work to compile a fortran source:
gcc -lgfortranbegin -lgfortran myprog.f
 
Hey Mikrom,

thanks very much for your effort. But unfortunately I am now a little bit confused with your second answer.
Did you mean, when I installed MinGW, I only have to type:

gcc -lgfortranbegin -lgfortran myprog.f

instead of:

i586-pc-mingw32-gcc -o myprog.exe myprog.c ???

I also needn't to add "-o test.exe" to gcc -lgfortranbegin -lgfortran myprog.f ?
I have no problem to use the second code you gave me. But it creates also a.out (or with -o.test.exe a exe file) I nevertheless can't start using windows, only with Linux.
Well, maybe I didn't install MinGW correctly, I will try tomorrow again.
Probably after all using a real Windows with suitable compilers is more easy to handel :)

Thanks!

moppel
 
mingw normally generates a.exe: not a.out. It should execute under windows. Alternatively you can use cygwin which will also generate an executable which will work under windows.
 
Thanks, I will think about Cygwin when I failed with MinGW.
I just looked on the internet and maybe it answers my other MinGW question. So after installing MinGW, I have to type in the Linux console:

i586-pc-mingw32-gcc -lgfortranbegin -lgfortran -o myprog.exe myprog.f

Hope it's a right summery of this topic... :)
 
moppelg said:
Did you mean, when I installed MinGW, I only have to type:
gcc -lgfortranbegin -lgfortran myprog.f
instead of:
i586-pc-mingw32-gcc -o myprog.exe myprog.c ???
No, I only mean how to compile fortran source directly with gcc command, without the fortran front end (gfortran).
You will then have to use i586-pc-mingw32-gcc instead of gcc.

moppelg said:
I also needn't to add "-o test.exe" to gcc -lgfortranbegin -lgfortran myprog.f ?
You need to add the -o option (sorry I forgot it)

xwb said:
Alternatively you can use cygwin which will also generate an executable which will work under windows.
Yes, but MinGW generates native windows EXE and Cygwin doesn't. The executable generated with gcc on Cygwin runs only in Cygwin environment.


Moppelg, I only wrote what would be IMHO possible. But I have not experience with cross-compiling. I'm only using MinGW on Windows.

Other interesting link I found:
 
IMHO other possible approach, perhaps simpler:
Running gforran for Windows under wine (windows emulator) on Linux.
 
Haha, thanks for your effort.

I will prefer the second solution if it is working ;-)
 
Yes,

hier an example how to start gefortran using wine, dislin and openmp library to create a real windows exe:

gfortran -o test.exe test.f95 c:\Dislin\disgf.a -luser32 -lgdi32 -fopenmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top