Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 23, 2006, 02:20 PM   #1
mduser63
macrumors 68040
 
mduser63's Avatar
 
Join Date: Nov 2004
Location: Salt Lake City, UT
Send a message via AIM to mduser63
Question about compiling a FORTRAN program

I've got source code for a couple FORTRAN programs used in one of my engineering classes. The teacher has provided .exe versions for the majority of the students (using Windows). Presumably for the students not using Windows (there are several), he posted the source code for the programs. After some work, I was able to compile them using g77 and some LINPACK files I downloaded. They run great on my PowerBook. However, when I move them to the Power Mac G5, I get errors about dynamic libraries being unavailable. Presumably, this has something to do with the fact that there isn't a FORTRAN compiler installed on the G5.

I'd like to provide compiled versions for the Mac to the teacher so that he can post them for the benefit of other Mac-using students. However, first I need to somehow compile them so that they aren't dependent on libraries that most people don't have installed.

I've very much a novice at programming, and in fact, this is my first experience with FORTRAN whatsoever. Does anyone know how I could compile a standalone executable that will run on any (PowerPC at least) Mac without needing external libraries? These are both command line programs if that matters.
mduser63 is offline   0 Reply With Quote
Old Feb 23, 2006, 02:49 PM   #2
Nuc
macrumors 6502a
 
Nuc's Avatar
 
Join Date: Jan 2003
Location: TN
I use gfortran and also have g77 installed so,
Try this:
g77 filename.f -o execfilename

ie.

g77 helloworld.f -o helloworld

the -o is the output command. You should be able to transfer it to the G5 then...hopefully.

Hope this helps,

Nuc
__________________
rMBP 2.6/16/512
&
2.33GHz 17" MBP C2D
Nuc is offline   0 Reply With Quote
Old Feb 23, 2006, 03:07 PM   #3
zimv20
macrumors 601
 
zimv20's Avatar
 
Join Date: Jul 2002
Location: chicago
once upon a time, i coded in FORTRAN. one time i started a command in column 6 instead of column 7. boy did that not go well.

such an alien concept today.
__________________
Oct 2011: check out my band's first album @ boxsetauthentic.com
zimv20 is offline   0 Reply With Quote
Old Feb 23, 2006, 03:08 PM   #4
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Quote:
Originally Posted by mduser63
Does anyone know how I could compile a standalone executable that will run on any (PowerPC at least) Mac without needing external libraries?
It's all in the way you link your object files, if any of the objects are only available as precombiled shared libraries you're sunk. You either need source code or archive libraries to make a self contained executable.

By default gcc and g77 generally try to link statically, so I suspect that one of your objects is a shared library (probably the LINPACK routines), which you should be able to copy over to the other box as well.

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Feb 23, 2006, 03:08 PM   #5
mduser63
Thread Starter
macrumors 68040
 
mduser63's Avatar
 
Join Date: Nov 2004
Location: Salt Lake City, UT
Send a message via AIM to mduser63
Thanks for the reply. I was already using the -o option to create an output file, although I don't believe it's necessary...g77 will just default to using a.out if you don't specify a name with the -o option.

The error I get when I try to run the program on the G5 is the following:

$ ./anplot
dyld: Library not loaded: /usr/local/lib/libg2c.0.dylib
Referenced from: /Programming/fortran/./anplot
Reason: image not found
Trace/BPT trap
$

EDIT, the last few replies came while I was typing this. The LINPACK routines that I'm using are all on my machine as .f files, not precompiled. I'm including them as files that need to be compiled to produce the final output file. Here's my compiler command:

g77 anplot.f ~/blas/* ~/linpack/* -o anplot

Where ~/blas/ and ~/linpack/* contain all of the library routines called in anplot.f.

The same anplot executable runs fine on my PowerBook where I compiled it.
mduser63 is offline   0 Reply With Quote
Old Feb 23, 2006, 03:17 PM   #6
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Quote:
Originally Posted by mduser63
The error I get when I try to run the program on the G5 is the following:

$ ./anplot
dyld: Library not loaded: /usr/local/lib/libg2c.0.dylib
Referenced from: /Programming/fortran/./anplot
Reason: image not found
Trace/BPT trap
$
Looks like you need to explicitly include the static version of libg2c, or copy over /usr/local/lib/libg2c.0.dylib

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Feb 23, 2006, 03:30 PM   #7
mduser63
Thread Starter
macrumors 68040
 
mduser63's Avatar
 
Join Date: Nov 2004
Location: Salt Lake City, UT
Send a message via AIM to mduser63
Quote:
Originally Posted by balamw
Looks like you need to explicitly include the static version of libg2c, or copy over /usr/local/lib/libg2c.0.dylib

B
How would I go about including the static version of libg2c? Should it already be on my computer, or would I need to download it? I'd rather not copy it over, because the goal is to be able to give the compiled executable to others so they can run it with a minimum amount of trouble. I really get turned off by software when it makes me install a bunch of extra stuff in order to get it running.
mduser63 is offline   0 Reply With Quote
Old Feb 23, 2006, 03:34 PM   #8
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Quote:
Originally Posted by mduser63
How would I go about including the static version of libg2c? Should it already be on my computer, or would I need to download it? I'd rather not copy it over, because the goal is to be able to give the compiled executable to others so they can run it with a minimum amount of trouble. I really get turned off by software when it makes me install a bunch of extra stuff in order to get it running.
It's probable already in /usr/local/lib/libg2c.a. Depends on how you installed g77.

You could also just try adding -noshared or -static to the command line and see if that gets passed properly to the linker and it makes the right decision.

You don't always have access to the source or an archive library, so sometimes you just have to share dynamically linked executables. That doesn't seem to be the case this time.

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Feb 23, 2006, 04:07 PM   #9
mduser63
Thread Starter
macrumors 68040
 
mduser63's Avatar
 
Join Date: Nov 2004
Location: Salt Lake City, UT
Send a message via AIM to mduser63
Sorry to keep bugging you with questions. I do have libg2c.a where you said. I'm not sure how to tell g77 to use that instead of the dynamic library. I couldn't find the option to do so in the g77 help. Again, I'm quite new at programming, so please forgive me if this is a dumb question.
mduser63 is offline   0 Reply With Quote
Old Feb 23, 2006, 04:12 PM   #10
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Quote:
Originally Posted by mduser63
Sorry to keep bugging you with questions. I do have libg2c.a where you said. I'm not sure how to tell g77 to use that instead of the dynamic library. I couldn't find the option to do so in the g77 help. Again, I'm quite new at programming, so please forgive me if this is a dumb question.
The linker's usually smart enough to do so if you just add the filename to your g77 line. i.e. g77 anplot.f ~/blas/* ~/linpack/* /usr/local/lib/libg2c.a -o anplot

Did you try -static or -noshared?

i.e. g77 -static anplot.f ~/blas/* ~/linpack/* -o anplot

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Feb 23, 2006, 04:27 PM   #11
mduser63
Thread Starter
macrumors 68040
 
mduser63's Avatar
 
Join Date: Nov 2004
Location: Salt Lake City, UT
Send a message via AIM to mduser63
Putting libg2c.a in the command line didn't work. The compiler still worked, but running the executable on the G5 produced the same error. Using the -noshared option just gave me an error saying that that was an unrecognized option. However, when I used the -static option, I got a much more complex error:

$ g77 -static anplot.f ~/linpack/* ~/blas/* -o anplot
~/linpack/cgefa.f: In subroutine `cgefa':
In file included from ~/linpack/cgefa.f:0:
~/linpack/cgefa.f:55: error: unrecognizable insn:
(insn 222 221 223 10 (set (reg:SF 243)
(subreg:SF (mem/u/f:SC (lo_sum:SI (reg/f:SI 229)
(symbol_ref/f:SI ("*LC1") [flags 0x2] <complex_cst 0x40e49ca8>)) [0 S8 A32]) 0)) -1 (nil)
(expr_list:REG_DEAD (reg/f:SI 229)
(nil)))
~/linpack/cgefa.f:55: internal compiler error: in extract_insn, at recog.c:2083
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

If it helps you at all, here's a link to the source for anplot (I renamed anp.f to anplot.f).
mduser63 is offline   0 Reply With Quote
Old Feb 23, 2006, 04:33 PM   #12
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Quote:
Originally Posted by mduser63
If it helps you at all, here's a link to the source for anplot (I renamed anp.f to anplot.f).
Nah, the problem is all in the linking.

You could try this: delete libg2c.dylib. (rename or back it up if you're paranoid). The linker should be smart enough to try and use libg2c.a. You might also have to add a -llibg2c after g77.

EDIT: Should check man pages before I suggest things. Try -Bstatic or -non_shared as options. You can try them right after g77 or at the end of the line.

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Feb 23, 2006, 04:38 PM   #13
mduser63
Thread Starter
macrumors 68040
 
mduser63's Avatar
 
Join Date: Nov 2004
Location: Salt Lake City, UT
Send a message via AIM to mduser63
Quote:
Originally Posted by balamw
Nah, the problem is all in the linking.

You could try this: delete libg2c.dylib. (rename or back it up if you're paranoid). The linker should be smart enough to try and use libg2c.a. You might also have to add a -llibg2c after g77.

B
That did the trick! It runs fine on the G5 now. Thanks for your patience and help.

EDIT: Just saw your edit. I tried -Bstatic and -non_shared after replacing the libraries. Neither worked. -non_shared was an unrecognized option, and while the compiler didn't complain about -Bstatic, I got the same error about a missing libg2c.dylib when I ran the executable on the G5. No matter, the method involving moving/deleting the relevant dylibs worked fine.

Last edited by mduser63; Feb 23, 2006 at 04:44 PM.
mduser63 is offline   0 Reply With Quote
Old Feb 23, 2006, 06:33 PM   #14
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Quote:
Originally Posted by mduser63
That did the trick! It runs fine on the G5 now. Thanks for your patience and help.
Glad it worked out. It shouldn't be that hard.

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
How to run fortran on mac phamnu Mac Programming 1 Aug 25, 2013 09:56 PM
Compiling SendMail program - Need Help papo2 OS X 10.8 Mountain Lion 0 Mar 29, 2013 02:56 PM
Fortran g77 on Mac nicolaus Mac Programming 5 Feb 7, 2013 08:09 AM
Compiling a C++ program to an IOS application richi27 iPhone/iPad Programming 4 Aug 4, 2012 07:54 PM
Fortran and Netcdf dukebound85 Mac Programming 3 Jun 20, 2012 11:31 PM

Forum Jump

All times are GMT -5. The time now is 08:51 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC