Problems with gfortran on Snow Leopard

Hi,

I have installed the precompiled binaries of gfortran on Mac OS X Snow Leopard which i have obtained from the hpc website (http://hpc.sourceforge.net/). However when trying to compile a large finite-element package (Elmer), the compilation fails with:

Lists.f90:1425:0: internal compiler error: in pt_solutions_same_restrict_base, at tree-ssa-structalias.c:5080
Please submit a full bug report,
with preprocessed source if appropriate.
See for instructions.
make[3]: *** [Lists.o] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Did anyone else experienced such error message when compiling a large fortran code base? I believe that the function in question above (pt_solutions_same_restrict_base) was introduced only recently as it is only appears in gcc trunk. The source file tree-ssa-structalias.c in gcc up to the branch 4.4 does not have this function defined. The compiler version reported on my system is 4.5, so i guess it was compiled from the trunk.

Anyone any idea on how to fix that? Did anyone use the gfortran distributed with fink, does it work with Snow Leopard?

Thanks a lot

Cheers,

Hakime

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Don't use the HPC Compiler

So, from various correspondence on the numpy and R-mac mailing list, I've gathered it's not the best idea to use the HPC compilers.

IT seems the ones available here are the way to go:

http://r.research.att.com/tools/

Check the "Alternative and experimental tools" section. You'll find the gfortran-42-5646.pkg installer.

Hope that helps,

-steve

gfortran-42-5646.pkg from att.com

Hi,

I've downloaded and installed it to the default location. I then tried to compile an empty program (program test ... end program test), and here are the results:


[/tmp]>cat test11.f90
program test11

end program test11
[/tmp]>gfortran -m64 test11.f90 -o test11
Undefined symbols:
"__gfortran_set_std", referenced from:
_MAIN__ in cc3Q5fo6.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
[/tmp]>

Also broken.

Unfortunately the fortran compiler for Snow Leopard available from http://r.research.att.com/tools/ is totally broken.

I installed it in the default location, which seems to be in /usr/bin and /usr/lib. Trying to compile:

PROGRAM FOO
WRITE(*,*) 'HELLO WORLD'
END PROGRAM FOO

ends to

ld: warning: in /usr/local/lib/libgfortran.dylib, file is not of required architecture
Undefined symbols:
"__gfortran_st_write", referenced from:
_MAIN__ in cc9DmhqG.o
"__gfortran_set_std", referenced from:
_MAIN__ in cc9DmhqG.o
"__gfortran_transfer_character", referenced from:
_MAIN__ in cc9DmhqG.o
"__gfortran_set_args", referenced from:
_main in libgfortranbegin.a(fmain.o)
"__gfortran_st_write_done", referenced from:
_MAIN__ in cc9DmhqG.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Quite bad, at least the version from hpc could compile OpenMPI 1.2.9.

Note also that it warns about /usr/local/lib/libgfortran.dylib, file is not of required architecture. The att.com installer installs libgfortran in /usr/lib/gcc/i686-apple-darwin10/4.2.1 so i don't know why it is going to look at /usr/local/lib where actually the libs from hpc (gfortran from http://hpc.sourceforge.net/) are installed. Even changing the path of gfortran and adding /usr/lib to DYLD_LIBRARY_PATH does not remove this warning. Strange!

Anyway that does not work and i am feeling that we are left without a stable/working free fortran compiler for Snow Leopard.

Any suggestion?

Cheers

32 vs 64 bit

Those problems definitely are related to absence of 64-bit versions of libraries. 64 bit compilation is default on Snow Leopard. My suggestion is to try compiling with the 32 bit switch, like so:

gfortran -m32 ...

Let us know if this changes the error messages at all.

Here are the

Here are the results:

[/tmp]>cat test.f90
program test11

end program test11
[/tmp]>gfortran test.f90
ld: warning: in /usr/local/lib/libgfortran.dylib, file is not of required architecture
Undefined symbols:
"__gfortran_set_std", referenced from:
_MAIN__ in ccyVLfAC.o
"__gfortran_set_args", referenced from:
_main in libgfortranbegin.a(fmain.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
[/tmp]>gfortran -m32 test.f90
ld: warning: in /usr/local/lib/libgfortran.dylib, file is not of required architecture
Undefined symbols:
"__gfortran_set_std", referenced from:
_MAIN__ in ccQk0do6.o
"__gfortran_set_args", referenced from:
_main in libgfortranbegin.a(fmain.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
[/tmp]>gfortran -m64 test.f90
Undefined symbols:
"__gfortran_set_std", referenced from:
_MAIN__ in cc9aSMji.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
[/tmp]>gfortran -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /Builds/apple/gcc-5646/build/obj/src/configure --disable-checking --prefix=/usr --mandir=/usr/share/man --enable-languages=c,objc,c++,obj-c++,fortran --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --with-gxx-include-dir=/usr/include/c++/4.2.1 --host=i686-apple-darwin10 --target=i686-apple-darwin10
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5646)
[/tmp]>

I see, so the -m64 flag got

I see, so the -m64 flag got rid of that "file is not of required architecture" warning but not the rest of the problem.
I have couple more suggestions, please run

1) (check that libgfortran contains the required symbol)
otool -vR /usr/local/lib/libgfortran.dylib |grep gfortran_set_std

2) (check if the thing get compiled in the first place)
gfortran -c -m64 test.f90
nm test.o

3) (now try linking with gfortran, perhaps the linker was called through gcc - that would have been incorrect)
gfortran test.o -o test
./test

As requested: [/tmp]>otool

As requested:


[/tmp]>otool -vR /usr/local/lib/libgfortran.dylib |grep gfortran_set_std
[/tmp]>gfortran -c -m64 test.f90
[/tmp]>nm test.o
0000000000000020 s EH_frame1
0000000000000000 T _MAIN__
0000000000000038 S _MAIN__.eh
U __gfortran_set_std
[/tmp]>gfortran test.o -o test
ld: warning: in test.o, file is not of required architecture
ld: warning: in /usr/local/lib/libgfortran.dylib, file is not of required architecture
Undefined symbols:
"_MAIN__", referenced from:
_main in libgfortranbegin.a(fmain.o)
"__gfortran_set_args", referenced from:
_main in libgfortranbegin.a(fmain.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
[/tmp]>./test
-bash: ./test: No such file or directory
[/tmp]>

Completely lost

Hi,

I'm new to xCode and to Fortran and I have been trying to get it working all day, but its a complete mess.

I have XCode and snow leopard.

Could anyone write a complete step by step guide to get fortran running with this configuration. It would help out a lot of people.

Tnx a lot
Seb

Problem mostly fixed

I played again with the gfortran version from hpc and finally I could succeed to compile the large finite element code that I use.

The trick is to avoid to use the -ftree-vectorize switch and to set the optimization flag not higher than -O2. You can get the compiler for Snow Leopard at:

http://hpc.sourceforge.net/

Not that the use of -ftree-vectorize was also the cause of the compilation failure of Open MPI 1.3.3 (actually any version higher than 1.2.9).

So besides the above mentioned care on the use of certain compiler switch, it works out of the box.

People can also use g95 to compile their fortran code on Snow Leopard, but at the moment it does not support 64 bits compilation.

http://www.g95.org/

Only mostly lost here

Hi Seb,

I only just got my first Fortran files working last week using Xcode. I'm also on Snow Leopard, and you're right, this would have helped me out before last week for sure! This isn't purely fortran (it's mixed c++ and fortran), but I hope this helps:

1. Make sure you have installed a fortran compiler (I'm using gfortran version 4.3.0, installed by MacPorts).

2. Start a new project in Xcode using the c++ command line tool.
Under "Choose a template for your new project:" select Application > Command Line Tool. In the drop-down-menu, select "C++ stdc++".

3. Select the destination folder for the project and name it.

4. Select Debug mode. In the Groups and files pane, click the Source folder triangle to view the documents you will be compiling. Right now, there should be one main.cpp file and no others.

5. Add a fortran file to the source folder: First, click select the source folder in the Groups & Files pane. Now select File > New File and a window will appear so you can select the file template. Under the Mac OS X icon, select "Other" and choose "Empty File" before clicking "Next". When you name the new file, attach the fortran suffix, ".f" to the end so the file will be recognized as a fortran file during the build phase. In the projects window, make sure the new fortran file is in the Source folder.

6. Now edit the files.
%% Here is a very basic sample code to run:
%% main.cpp
#include
using namespace std;

extern "C"
{
void ffunction_(float *a, float*b);
}

int main ()
{
cout << "Hello, World!\n";

float a = 1.0, b = 2.0;

cout << "Before running Fortran function:" << endl;
cout << "a = " << a << endl;
cout << "b = " << b << endl;

ffunction_(&a,&b);

cout << "After running Fortran function:" << endl;
cout << "a = " << a << endl;
cout << "b = " << b << endl;

return 0;
}

%% The fortran file, fortran_test.f

subroutine ffunction(a,b)
a = 3.0
b = 4.0
end
7. Now, in the Groups & Files pane, click the triangle to the left of Targets and select the target icon. Right-click it and select "Get Info", or just click the info icon at the top of the project window. Select the "Rules" tab.

8. One last thing. You need to know the pathname for your copy of gfortran. Open a terminal window and type: "where gfortran" The pathname will be on the next line. My gfortran is /usr/local/bin/gfortran

9. Click the "+" at the lower left of the rules panel to add a new rule to your build to handle fortran files. Choose:
Process: "Fortran source files"
using: "Custom script:"
In the new typing field, type the following:
/usr/local/bin/gfortran -g -c ${PROJECT_DIR}/${INPUT_FILE_NAME} -o ${TARGET_BUILD_DIR}/${INPUT_FILE_BASE}.o
%% Replace "/usr/local/bin/gfortran" with your own gfortran
%% pathname if needed.
In the "with output files:" field, type:
$(TARGET_BUILD_DIR)/$(INPUT_FILE_BASE).o
%% the custom script line needs curly braces, { }, because it talks
%% to the command line. The output files line is telling Xcode where
%% the output file is, and Xcode uses regular parentheses ( ).

10. Now, everything should be ready. Click "Build and Run" or "Build and Debug". If it compiled successfully, go to the Groups & Files pane, open the products folder by clicking the triangle and double-click the executable displayed there.

-Rachel

Almost made it..

Rachel,

I tried on my Leopard and I only got a nasty:

Command /bin/sh failed with exit code 1

any idea why?
Thank you!!!!

Fortran on Snow Leopard (and Leopard?)

I am adding this because the messages here initially confused more than they helped.

There is a problem building many open source packages containing Fortran code on 10.5 and 10.6.

As mentioned above recent Apple compilers will default to building X86_64 code on 64 bit processor machines. The various Fortran compilers all seem to default to 32bit i386 code.

As a result when trying to do a standard configure/make build there will be failures in both the configure and make steps with 'wrong architecture' messages.

The appropriate cure depends on the desired outcome. If you want 64bit code add -m64 to FFLAGS. If you want 32bit code add --arch i386 to CFLAGS and CXXFLAGS.

Also don't use -O3 'optimisation'. It is very suboptimal on modern processors as well being bug ridden. Modern CPUs are not limited by core speed. The problem is feeding in instructions fast enough to keep the pipelines full. Hence Apple recommends using -Os which is like -O2 with the omission of 'optimisations' that increase code size.

Finally on optimisation. If you profile most scientific code, you find it spends most of its time in the math libraries which Apple built. So optimisations in the code users build makes little difference to overall time. For many purposes you might as well use O0 and be able to debug the code more easily.

Hope this helps someone.
Bill Northcott

Fortran on Snow Leopard

This is pretty basic, but after much floundering (including dead ends with pre-built binaries, recovery from which required rebuilding /usr), I finally got gfortran working on OS X 10.6, and thought others might find my route useful. Quite simple, and obvious in hindsight -- just build gcc44 with fink:

- install Xcode
- install fink (I'm using the 32-bit version)
- install gcc44 with fink

That's it. It works by virtue of fortran being among the --enable-languages options set by fink during the gcc44 build (note that of this writing there are no fink binaries for Snow Leopard, so it builds everything from source).

Even though my fink is 32-bit, this gcc44 install results in a 64-bit gfortran compiler. Thus, to build open source packages such as netcdf and openmpi (which I do manually from the source, that is, not using fink), I needed to specify FFLAGS=-m64 FCFLAGS=-m64 for the configure step. To build those packages for all users, I used sudo rather than logging in as root, as something about my root environment (which I very rarely use) messed up those builds when I tried the latter.

Note that for this setup, one needs to use the -m64 flag during compilation and linking of all fortran programs.

-Andy

Fortran on Snow Leopard

I am a UNIX newbie but having been encouraged by Andy’s post of Tue, 2010-01-26 11:22 ack3000, I tried to follow his procedure to install gfortran on my Mac-Pro. I had previously installed X-code [version 3.2 (1610)] and the 32-bit version of fink. With the command

‘sudo fink install gcc44’

it appeared that I successfully installed the 64-bit gfortran compiler.

Using the usual command: gfortran –m64 –o Hello Hello.F90
I was able to produce the executable file Hello from the file Hello.F90. But when I attempted to run this file from the command line: ‘./ Hello’

I got the message : ‘./: Permission denied.’

even though the ls –l command gives the permission string ‘-rwxr-xr-x’ for the Hello file.

The executable files I made work fine when I double click on their icons but, of course, I need to be able to run them from a command line.

My operation system is Mac OS X 10.6.2. Any suggestions?

- Richard

Space in the command

Hello,

From what I read you put a space between "./" and "Hello".

The way to execute a command in a terminal is to provide either the name of an executable with a full path or the name of an executable that is present in a set of ad hoc directories. When you type "ls" the system converts it to "/bin/ls" and executes that program.

In your case the message ‘./: Permission denied.’ indicates that you tried to execute the present directory.

Can you try "./Hello" (which is the full path to "Hello" in the present directory ".") without any space ?

Pierre