(e-mail address removed) (Gunasekaran) wrote:
# Dear all,
#
# I wrote a c program and tried to call NAG(desinged for FORTRAN)subroutine.
# Compiler gives the following error message
# undefined to `__ctype_b'
# /usr/local/FFC/lib/libfj9i6.so: undefined reference to `__ctype_tolower'
This is almost certainly from the linker, not the compiler; you may
not be aware of it because many (most?) compilers will run the linker
automatically for you, often by default. But in a mixed-language
situation you may need to override this behavior -- in particular, you
may need to use the C compiler to just compile (often specified by a
command line flag, conventionally -c) and then the Fortran compiler to
drive the linking.
<ctype.h> can be macros or functions. Apparently the library expects the function
entry points but for some reason can't find them in libc. You should probably check
the libraries and entry point names.
Or macros using 'hidden' data, which looks to be the case here.
You might have to link libc before this other library.
That's unlikely to help; the most common linker behavior is to search
a library only for currently unresolved symbols, so you need to
specify a library that provides a symbol *after* whatever uses it.
But the linking done automatically by the C compiler almost certainly
specifies the C library (maybe libc, maybe something else) last, so
this would not be the problem.
I suspect a more likely problem is a mismatch between the C compiler
and/or library the OP is using and that expected by the library s/he
has. Many implementations have different "modes" of various kinds --
static vs dynamic linking, threaded vs not, different memory models --
and on many platforms there are multiple C implementations (compilers
and/or libraries) available, which are not necessarily compatible with
each other. In general, whatever compiler and options were used to
compile the library, you should if possible use the same for your code
and not assume that anything else will work.
To the OP: I suggest, if the appropriate restrictions aren't obvious
in your (NAG) library, like a README or such, or on the source you got
it from, you take this to comp.lang.fortran, and tell them what NAG
you are using (or where you got it) and what C you are using with it
and with what options. The folks there are much more familiar with,
and tolerant of, C/Fortran interfacing issues, and system specifics.
Although they will probably chide you for not just using Fortran -- if
you have a good reason, state it up front to save time.
- David.Thompson1 at worldnet.att.net