X
82 Rate this article:
No rating

Compiling C++ routines with gcc for use with CALL_EXTERNAL

Anonym
Topic:
I am trying to call a C++ routine that I want to compile with gcc on a Sparc running SunOS 4.1.3 and call from IDL with CALL_EXTERNAL. The flags used for the compile and link calls given in the IDL manual examples for the SunOS cc compiler are very different from the ones I need to use with gcc so I'm apparently not building the right kind of shared object file (i.e. I'm getting messages like:
    ld.so: Undefined symbol: ___11spin_systemi)
Has anyone done this sucessfully (i.e. used IDL with gcc) and if so any suggestions, e.g. what flags to use for the compile and link steps ? Discussion:
I had a similar problem with a slightly more difficult example -- using a C++ routine with CALL_EXTERNAL from IDL where the C++ routine was a wrapper for a FORTRAN routine. I found that I could only get it to work by using the Sun linker.

The following Makefile section worked successfully on SunOS 4.1.2 with its bundled "ld", gcc 2.6.3 and Sun SPARCompiler Fortran 2.0.1:

### NOTE: No "LD" define -- the default Sun linker is "/bin/ld".
CXX = g++
CXXFLAGS = -fpic
FFLAGS = -pic
LDFLAGS = -L/usr/lang/SC2.0.1
LDLIBS = -lF77 -lM77 -lpfc -lm

xxx.so: xxx.o ....
    $(LD) -o xxx xxx.o ....

(This was off the newsgroup. The answer is J. Bob Brown's)

**Another answer from the newsgroup**
I interface to the LAPACK library via a C wrapper.

Compiling with GCC, you should use:

CFLAGS=-fpic
LDFLAGS=-G

for Sun CC:
CFLAGS=-Kpic
LDFLAGS=-G

That's using GCC 2.7.2 and Sparcworks C 4.0

NOTE: this is from the newsgroup. Answer by :--
David Fenyes University of Texas Medical School
dave@msrad71.med.uth.tmc.edu Dept. of Radiology