Problem with gfortran and snowleopard

Discussion in 'Mac Programming' started by bamdad, Nov 8, 2010.

  1. macrumors newbie

    Joined:
    Aug 8, 2009
    Messages:
    16
    #1
    Hi guys,
    I know this post is quite similar to this one so I apologize in advance in case I cause any irritation. Unfortunately I have to compile an f.77 code on my snowleopard and try writing a mixed language code using fortran and C++. this is part of the research in our team and I am still bumping heads with the other guys on writing programs in C++. anyways, I have donwloaded the .dmg file from GCC's website that is supposed to instal gfortran 4.5.0 for snowleopard. but when I type gfortran in the terminal just to check whether the compiler has been installed correctly I get :

    Code:
    bamdad-hosseinis-macbook-pro:usr bamdadhosseini$ gfortran
    i686-apple-darwin10-gfortran-4.2.1: no input files
    
    I believe this means that the OS is using the 4.2.1 version by default. But this isnt the main problem I'm having. As I try compiling a simple hello program

    Code:
    program hello
        implicit none
    end program hello
    I get the following error in the console:

    Code:
    Building target: hello
    Invoking: MacOS X Fortran Linker
    gfortran  -o "hello"  ./hello.o   
    ld: warning: in /usr/local/lib/libgfortran.dylib, file was built for i386 which is not the architecture being linked (x86_64)
    Undefined symbols:
      "__gfortran_set_std", referenced from:
          _MAIN__ in hello.o
      "__gfortran_set_args", referenced from:
          _main in libgfortranbegin.a(fmain.o)
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    make: *** [hello] Error 1
    I am using eclipse helios with photran but the same error pops up when I try compiling the code in the terminal. Anyways, It indicates that Im having some incompatibilities compiling the code for 64bit.

    so, any ideas on how to fix this? I really hate working with fortran I just hope I get this over with soon
     
  2. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Messages:
    17,829
    Location:
    New England
    #2
    I saved your code as "deleteme.f90" then compiled it using
    Code:
    gfortran deleteme.f90
    using the version of gfortran I installed for the other thread. (Seems newer than what you have. Why?)

    Here it is verbose:
    Code:
    >[B]gfortran -v  -o deleteme deleteme.f90 [/B]
    Driving: gfortran -mmacosx-version-min=10.6.4 -v -o deleteme deleteme.f90 -lgfortran -shared-libgcc
    Using built-in specs.
    COLLECT_GCC=gfortran
    COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin10/4.6.0/lto-wrapper
    Target: x86_64-apple-darwin10
    Configured with: ../gcc-4.6-20100703/configure --enable-languages=fortran,c++ --host=x86_64-apple-darwin10 --build=x86_64-apple-darwin10
    Thread model: posix
    gcc version 4.6.0 20100703 (experimental) (GCC) 
    COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.6.4' '-v' '-o' 'deleteme' '-shared-libgcc' '-mtune=generic'
     /usr/local/libexec/gcc/x86_64-apple-darwin10/4.6.0/f951 deleteme.f90 -fPIC -quiet -dumpbase deleteme.f90 -mmacosx-version-min=10.6.4 -mtune=generic -auxbase deleteme -version -fintrinsic-modules-path /usr/local/lib/gcc/x86_64-apple-darwin10/4.6.0/finclude -o /var/folders/rv/rvEMx6AiGuOHeBY2fGRMbE+++TI/-Tmp-//ccVLqjN1.s
    GNU Fortran (GCC) version 4.6.0 20100703 (experimental) (x86_64-apple-darwin10)
    	compiled by GNU C version 4.6.0 20100703 (experimental), GMP version 4.3.1, MPFR version 2.4.1, MPC version 0.8.1
    GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
    GNU Fortran (GCC) version 4.6.0 20100703 (experimental) (x86_64-apple-darwin10)
    	compiled by GNU C version 4.6.0 20100703 (experimental), GMP version 4.3.1, MPFR version 2.4.1, MPC version 0.8.1
    GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
    COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.6.4' '-v' '-o' 'deleteme' '-shared-libgcc' '-mtune=generic'
     as -arch x86_64 -force_cpusubtype_ALL -o /var/folders/rv/rvEMx6AiGuOHeBY2fGRMbE+++TI/-Tmp-//ccSuVDSq.o /var/folders/rv/rvEMx6AiGuOHeBY2fGRMbE+++TI/-Tmp-//ccVLqjN1.s
    COMPILER_PATH=/usr/local/libexec/gcc/x86_64-apple-darwin10/4.6.0/:/usr/local/libexec/gcc/x86_64-apple-darwin10/4.6.0/:/usr/local/libexec/gcc/x86_64-apple-darwin10/:/usr/local/lib/gcc/x86_64-apple-darwin10/4.6.0/:/usr/local/lib/gcc/x86_64-apple-darwin10/
    LIBRARY_PATH=/usr/local/lib/gcc/x86_64-apple-darwin10/4.6.0/:/usr/local/lib/gcc/x86_64-apple-darwin10/4.6.0/../../../:/usr/lib/
    COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.6.4' '-v' '-o' 'deleteme' '-shared-libgcc' '-mtune=generic'
     /usr/local/libexec/gcc/x86_64-apple-darwin10/4.6.0/collect2 -dynamic -arch x86_64 -macosx_version_min 10.6.4 -weak_reference_mismatches non-weak -o deleteme -lcrt1.10.5.o -L/usr/local/lib/gcc/x86_64-apple-darwin10/4.6.0 -L/usr/local/lib/gcc/x86_64-apple-darwin10/4.6.0/../../.. /var/folders/rv/rvEMx6AiGuOHeBY2fGRMbE+++TI/-Tmp-//ccSuVDSq.o -lgfortran -lgcc_s.10.5 -lgcc_ext.10.5 -lgcc -no_compact_unwind -lSystem
    COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.6.4' '-v' '-o' 'deleteme' '-shared-libgcc' '-mtune=generic'
    
    B
     
  3. macrumors newbie

    Joined:
    Aug 8, 2009
    Messages:
    16
    #3
    Hi B! thanks for the reply. Now here's what I get when I do the same thing as you did

    Code:
    [B]>gfortran -v -o hello hello.f90[/B]
    Driving: /usr/bin/i686-apple-darwin10-gfortran-4.2.1 -mmacosx-version-min=10.6.4 -v hello.f90 -m64 -o hello -lgfortranbegin -lgfortran -shared-libgcc
    Using built-in specs.
    Target: i686-apple-darwin10
    Configured with: /Builds/apple/gcc-5664/build/obj/src/configure --disable-checking --prefix=/usr --mandir=/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 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1
    Thread model: posix
    gcc version 4.2.1 (Apple Inc. build 5664)
     /usr/libexec/gcc/i686-apple-darwin10/4.2.1/f951 hello.f90 -fPIC -quiet -dumpbase hello.f90 -mmacosx-version-min=10.6.4 -m64 -mtune=core2 -auxbase hello -version -I /usr/lib/gcc/i686-apple-darwin10/4.2.1/finclude -o /var/folders/zY/zYiMv3W8Hli7zuZAwHfolE+++TI/-Tmp-//cc1xIweY.s
    GNU F95 version 4.2.1 (Apple Inc. build 5664) (i686-apple-darwin10)
    	compiled by GNU C version 4.2.1 (Apple Inc. build 5664).
    GGC heuristics: --param ggc-min-expand=150 --param ggc-min-heapsize=131072
     /usr/libexec/gcc/i686-apple-darwin10/4.2.1/as -arch x86_64 -force_cpusubtype_ALL -o /var/folders/zY/zYiMv3W8Hli7zuZAwHfolE+++TI/-Tmp-//ccjQd2Dv.o /var/folders/zY/zYiMv3W8Hli7zuZAwHfolE+++TI/-Tmp-//cc1xIweY.s
     /usr/libexec/gcc/i686-apple-darwin10/4.2.1/collect2 -dynamic -arch x86_64 -macosx_version_min 10.6.4 -weak_reference_mismatches non-weak -o hello -lcrt1.10.6.o -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/x86_64 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/x86_64 -L/usr/lib/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../../i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../.. /var/folders/zY/zYiMv3W8Hli7zuZAwHfolE+++TI/-Tmp-//ccjQd2Dv.o -lgfortranbegin -lgfortran -lSystem -lgcc -lSystem
    ld: warning: in /usr/local/lib/libgfortran.dylib, file was built for i386 which is not the architecture being linked (x86_64)
    Undefined symbols:
      "__gfortran_set_std", referenced from:
          _MAIN__ in ccjQd2Dv.o
      "__gfortran_set_args", referenced from:
          _main in libgfortranbegin.a(fmain.o)
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    bamdad-hosseinis-macbook-pro:hello ba
    Now I believe the problem is with my current version of GCC. Since I am using apple's 4.2.1. Maybe I should install the new version? I just fear that by installing the new version I might blow something up :-s

    just in case, here's what I get when I use the set commant:

    Code:
    [B]>set[/B]
    Apple_PubSub_Socket_Render=/tmp/launch-tBgQ24/Render
    BASH=/bin/bash
    BASH_ARGC=()
    BASH_ARGV=()
    BASH_LINENO=()
    BASH_SOURCE=()
    BASH_VERSINFO=([0]="3" [1]="2" [2]="48" [3]="1" [4]="release" [5]="x86_64-apple-darwin10.0")
    BASH_VERSION='3.2.48(1)-release'
    COLUMNS=123
    COMMAND_MODE=unix2003
    DIRSTACK=()
    DISPLAY=/tmp/launch-Vlcyuy/org.x:0
    EUID=501
    GROUPS=()
    HISTFILE=/Users/bamdadhosseini/.bash_history
    HISTFILESIZE=500
    HISTSIZE=500
    HOME=/Users/bamdadhosseini
    HOSTNAME=bamdad-hosseinis-macbook-pro.local
    HOSTTYPE=x86_64
    IFS=$' \t\n'
    LANG=en_US.UTF-8
    LD_LIBRARY_PATH=/usr/local/cuda/lib
    LINES=34
    LOGNAME=bamdadhosseini
    MACHTYPE=x86_64-apple-darwin10.0
    MAILCHECK=60
    OLDPWD=/Users/bamdadhosseini/eclipse_workspace
    OPTERR=1
    OPTIND=1
    OSTYPE=darwin10.0
    PATH=/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/X11/bin:/usr/local/cuda/bin
    PIPESTATUS=([0]="1")
    PPID=1171
    PS1='\h:\W \u\$ '
    PS2='> '
    PS4='+ '
    PWD=/Users/bamdadhosseini/eclipse_workspace/hello
    SHELL=/bin/bash
    SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
    SHLVL=1
    SSH_AUTH_SOCK=/tmp/launch-kBz8VY/Listeners
    TERM=xterm-color
    TERM_PROGRAM=Apple_Terminal
    TERM_PROGRAM_VERSION=273
    TMPDIR=/var/folders/zY/zYiMv3W8Hli7zuZAwHfolE+++TI/-Tmp-/
    UID=501
    USER=bamdadhosseini
    _=hello.f90
    __CF_USER_TEXT_ENCODING=0x1F5:0:0
     
  4. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Messages:
    17,829
    Location:
    New England
    #4
    Apple's version 4.2.1 that comes with Xcode does not have fortran enabled. You need a gcc that has --enable-languages=fortran. See the output below from my MBP. The two gccs live in peace.

    Code:
    $ gcc -v
    Using built-in specs.
    Target: i686-apple-darwin10
    Configured with: /var/tmp/gcc/gcc-5664~38/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man [B]--enable-languages=c,objc,c++,obj-c++[/B] --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1
    Thread model: posix
    gcc version 4.2.1 (Apple Inc. build 5664)
    $ /usr/local/bin/gcc -v
    Using built-in specs.
    COLLECT_GCC=/usr/local/bin/gcc
    COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin10/4.6.0/lto-wrapper
    Target: x86_64-apple-darwin10
    Configured with: ../gcc-4.6-20100703/configure [B]--enable-languages=fortran,c++[/B] --host=x86_64-apple-darwin10 --build=x86_64-apple-darwin10
    Thread model: posix
    gcc version 4.6.0 20100703 (experimental) (GCC)
    B
     
  5. macrumors newbie

    Joined:
    Aug 8, 2009
    Messages:
    16
    #5
    thanks alot B, I got everything under control. I only have one question, I used the export PATH command to change the default compiler of the system. Now whenever I type GCC -v the terminal uses 4.6.0. Should I use the export command again in case I needed to use the previous GCC 4.2.1?
     
  6. balamw, Nov 10, 2010
    Last edited: Nov 10, 2010

    Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Messages:
    17,829
    Location:
    New England
    #6
    My PATH is:
    Code:
    PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/X11/bin
    This way gcc -> /usr/bin and (/usr/local/bin/)gfortran -> /usr/local/bin/gcc (later in the path).

    B
     

Share This Page