| Richard E Maine 2005-04-06, 12:21 pm |
| In article <e9f45912.0504050056.18fc744c@posting.google.com>,
ruben81@gmail.com (Bartolo) wrote:
> I've got a problem linking several files that use librarie functions
> and subroutines. For example malloc can be only called by the main
> file of my program but not from another. I've tried declaring
> 'external malloc,free' and still the same problem. How do a invoque a
> library function outside the main program file?
The same way as in the main program file. There is *NO* difference at
the source code level. You don't show what command you use to link in
all the libraries; one suspicion is that the problem lies there.
In particular, the unix linker is very sensitive to the order in which
you specify files and libraries to be linked. Everything to be linked is
scanned in order with no backtracking. This means that if something in
library x references something in library y, then library x better
precede library y on the command line.
> lib/libbiof77.a(rand.o)(.text+0x640): En la función `RANPERM':
> : undefined reference to `MALLOC'
My attention is also drawn to the fact that the undefined reference is
all caps and lacks a trailing underscore. I'm not sure what system this
is from - clearly some unix variant, but I can't tell in more detail.
Anyway, that is slightly unusual (though there are systems like that, so
I might be going off on a wrong tangent here). It does make me think to
ask whether you are mixing code compiled with different languages or
even different compilers of the same language. That can have
complications, which include issues of different "name mangling"
conventions among the compilers.
--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
|