alex123
asked on
Linking with Fortran
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/libgribex R64.a(grsd ef.o)(.tex t+0xbc): In function `grsdef_':
: undefined reference to `G77_getenv_0'
/usr/local/lib64/libgribex R64.a(grsd ef.o)(.tex t+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
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/libgribex
: undefined reference to `G77_getenv_0'
/usr/local/lib64/libgribex
: 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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you! This did it.
ASKER