[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Linking with Fortran

Posted on 2006-03-27
3
Medium Priority
?
757 Views
Last Modified: 2013-11-08
Hello,

I've ran into a problem linking C++ code with code calling functions from a Fortran compiled library.

I have
1. precompiled binary called glib.o which connects to a Fortran library
2. a small piece of C++ code called reader.cc which calls functions from glib.o

If I compile like this it works fine

g77 reader.cc glib.o -lf2c -lm -lgribexR64 -lstdc++

however if I change it to

g++ reader.cc glib.o -lf2c -lm -lgribexR64

it fails and outputs linker errors all which look like

/usr/local/lib64/libgribexR64.a(grsdef.o)(.text+0xbc): In function `grsdef_':
: undefined reference to `G77_getenv_0'
/usr/local/lib64/libgribexR64.a(grsdef.o)(.text+0x16c): In function `grsdef_':
: undefined reference to `G77_getenv_0'

It appears that the reason for this is that when I compile with g77 I include the standard C++ library however when I compile with g++ I don't include its fortran equivalent. If someone could provide the necessary library or some other way of compiling this using g++ and not g77 it would be very helpful.

Thank you,

Alex
0
Comment
Question by:alex123
  • 2
3 Comments
 

Author Comment

by:alex123
ID: 16305763
Forgot to mention I am using gcc 3.4.5 on Suse9, Intel 64bit CPU
0
 
LVL 11

Accepted Solution

by:
DeanHorak earned 1000 total points
ID: 16310835
Try changing the fortran runtime library name - this was changed in later versions of the GNU toolset

i.e. change
g++ reader.cc glib.o -lf2c -lm -lgribexR64
to
g++ reader.cc glib.o -lg2c -lm -lgribexR64
0
 

Author Comment

by:alex123
ID: 16312219
Thank you! This did it.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses
Course of the Month20 days, 13 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question