From: Hifi-Comp on
On Jun 22, 6:17 pm, baf <b...(a)nowhere.net> wrote:
> Hifi-Comp wrote:
> > On Jun 21, 10:25 am, "e p chandler" <e...(a)juno.com> wrote:
> >> "fj" <francois.j...(a)irsn.fr> wrote in message
>
> >>news:986367df-d557-41bf-ac52-5efa049f8506(a)t10g2000yqg.googlegroups.com....
>
> >>> On 21 juin, 04:24, Hifi-Comp <wenbinyu.hea...(a)gmail.com> wrote:
> >>>> On Jun 20, 3:21 am, baf <b...(a)nowhere.net> wrote:
> >>>>> Hifi-Comp wrote:
> >>>>>> On Jun 19, 1:31 pm, baf <b...(a)nowhere.net> wrote:
> >>>>>>> Tobias Burnus wrote:
> >>>>>>>> Hifi-Comp wrote:
> >>>>>>>>> I am using gfortran on windows. -flto is not available for win32
> >>>>>>>>> gcc
> >>>>>>>>> version 4.6.0 20100524.
> >>>>> The new build of gfortran for windows is now available at the same link
> >>>>> as you list above.  I tested it with -flto and it produced an
> >>>>> executable
> >>>>> that ran fine.  The compiler will also install the latest version of
> >>>>> binutilts (2.20.51).- Hide quoted text -
> >>>> Thanks. I downloaded the updated build. However, when I compile the
> >>>> codes according to case 3 given by Steve's post. I get the following
> >>>> error message:
> >>>> c:/program files/gfortran/bin/../lib/gcc/i586-pc-
> >>>> mingw32/4.6.0/../../../libmingw
> >>>> 32.a(main.o):main.c:(.text+0xd2): undefined reference to `WinMain(a)16'
> >>>> collect2: ld returned 1 exit status
> >>> I got the same message this morning because I forgot to link with the
> >>> main program !
> >> Strange. I usually use G95 and I get a different message, an undefined
> >> reference to _MAIN.
> >> gfortran gives the message above. Interesting. I have not used gfortran
> >> enough to make this mistake on my own. [smile]
>
> >> -- e- Hide quoted text -
>
> >> - Show quoted text -
>
> > I uninstalled and reinstalled. Still getting the same error message.
> > My system is WinXP SP3.
>
> I used the code that you provided in your original post and got the
> following results with the build of the compiler currently available.
> Looks like there is only a minor "penalty" for using separate files for
> the modules and main program.  I suspect that the problem you are
> reporting with the linker is due to an old version of ld in the $PATH
> prior to the new version provided with the latest compiler package.
>
> D:\fortran\test>gfortran -v
> Using built-in specs.
> COLLECT_GCC=gfortran
> COLLECT_LTO_WRAPPER=c:/program
> files/gfortran/bin/../libexec/gcc/i586-pc-mingw32
> /4.6.0/lto-wrapper.exe
> Target: i586-pc-mingw32
> Configured with: ../gcc-trunk/configure --prefix=/mingw
>   --enable-languages=c,fortran --with-gmp=/home/brad/gfortran/dependencies
>   --disable-werror --enable-threads --disable-nls --build=i586-pc-mingw32
>   --enable-libgomp --disable-shared --disable-win32-registry
>   --with-dwarf2 --disable-sjlj-exceptions --enable-lto
> Thread model: win32
> gcc version 4.6.0 20100620 (experimental) [trunk revision 161045] (GCC)
>
> D:\fortran\test>gfortran  -O3 -ffast-math -march=native -fwhole-file
> -flto onefile.f90 -o onefile
>
> D:\fortran\test>onefile
>   Analysis Runs for    9.30000022E-02  Seconds.
>    -19999999.999990787
>   DNAD Runs for    0.11000000      Seconds.
>    -19999999.999990787        25000000.000000000
>
> D:\fortran\test>gfortran -c -O3 -ffast-math -march=native -fwhole-file
> -flto cputime.f90
>
> D:\fortran\test>gfortran -c -O3 -ffast-math -march=native -fwhole-file
> -flto dnad.f90
>
> D:\fortran\test>gfortran -c -O3 -ffast-math -march=native -fwhole-file
> -flto main.f90
>
> D:\fortran\test>main
>   Analysis Runs for    9.39999968E-02  Seconds.
>    -19999999.999990787
>   DNAD Runs for    0.11000000      Seconds.
>    -19999999.999990787        25000000.000000000- Hide quoted text -
>
> - Show quoted text -

Thanks a lot for all of you. I have resolved the problem. The remain
question is that I cannot use -flto for linking files into a DLL.
gfortran -O3 -flto -march=native -ffast-math -funroll-loops -ftree-
vectorize -shared -mrtd file1.o file2.o file3.o -o test.dll

all the *.o files are compiled using -flto -fwhole-file.

And the dll is linked to an overall program through
gfortran -O3 -flto -fwhole-program -march=native -ffast-math -
funroll-loops -ftree-vectorize -o test file4.o -L. test.dll

I have no problem in compiling the executable. But when the code is
invoked, the system crashed.
From: e p chandler on
>"Hifi-Comp" wrote
[snip discussion on using LTO]

>Thanks a lot for all of you. I have resolved the problem. The remain
>question is that I cannot use -flto for linking files into a DLL.
>gfortran -O3 -flto -march=native -ffast-math -funroll-loops -ftree-
>vectorize -shared -mrtd file1.o file2.o file3.o -o test.dll

>all the *.o files are compiled using -flto -fwhole-file.

>And the dll is linked to an overall program through
>gfortran -O3 -flto -fwhole-program -march=native -ffast-math -
>funroll-loops -ftree-vectorize -o test file4.o -L. test.dll

>I have no problem in compiling the executable. But when the code is
>invoked, the system crashed.

Why are you using -mrtd in the command to create your dll?

That option changes the calling convention into the DLL from CDECL to
STDCALL. On 32 bit Windows it creates a DLL that can be called from
languages like Visual Basic or Delphi. See any one of my previous postings
on that subject.