Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mduser63

macrumors 68040
Original poster
Nov 9, 2004
3,042
31
Salt Lake City, UT
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.
 

Nuc

macrumors 6502a
Jan 20, 2003
798
6
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
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
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.
 

balamw

Moderator emeritus
Aug 16, 2005
19,365
979
New England
mduser63 said:
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
 

mduser63

macrumors 68040
Original poster
Nov 9, 2004
3,042
31
Salt Lake City, UT
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.
 

balamw

Moderator emeritus
Aug 16, 2005
19,365
979
New England
mduser63 said:
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
 

mduser63

macrumors 68040
Original poster
Nov 9, 2004
3,042
31
Salt Lake City, UT
balamw said:
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.
 

balamw

Moderator emeritus
Aug 16, 2005
19,365
979
New England
mduser63 said:
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
 

mduser63

macrumors 68040
Original poster
Nov 9, 2004
3,042
31
Salt Lake City, UT
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.
 

balamw

Moderator emeritus
Aug 16, 2005
19,365
979
New England
mduser63 said:
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
 

mduser63

macrumors 68040
Original poster
Nov 9, 2004
3,042
31
Salt Lake City, UT
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).
 

balamw

Moderator emeritus
Aug 16, 2005
19,365
979
New England
mduser63 said:
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
 

mduser63

macrumors 68040
Original poster
Nov 9, 2004
3,042
31
Salt Lake City, UT
balamw said:
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.