help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Linking to external static (!) library


From: Martin Helm
Subject: Re: Linking to external static (!) library
Date: Tue, 19 Apr 2011 21:18:37 +0200
User-agent: KMail/1.13.6 (Linux/2.6.34.7-0.7-desktop; KDE/4.6.2; x86_64; ; )

Am Dienstag, 19. April 2011, 20:47:48 schrieb c.:
> On 19 Apr 2011, at 20:03, Martin Helm wrote:
> > Am Dienstag, 19. April 2011, 19:23:53 schrieb TOT:
> >> Hi everyone.
> >> There is a big static C library (several lib*.a files). It contains
> >> references to MPI library (I'm not sure how)
> >> There is one header file (c*.h), containing several other header files
> >> and so on.
> >> This library compiled using gcc (compatible with octave).
> >> 
> >> Lets assume that in the library "myopen" function exists. I want to call
> >> it in the octave and return the value of it (say 1 if everything is OK
> >> and -1 on error).
> >> 
> >> I'm tying to use OCT files, but I end up with an error from ld:
> >> "recompile with -fPIC".
> >> The library is huge, makefiles are huge and -fPIC option to be placed in
> >> too many places, so I don't want to do this.
> >> 
> >> Two questions:
> >> 
> >> Is there any way to link to this library (via tweaking mkoctfile or by
> >> other means, but not recompiling the library)?
> >> 
> >> Is it the same for matlab?
> >> 
> >> Regards,
> >> Anar.
> > 
> > I can be wrong since I never tried it (what you want to try), but I doubt
> > it is possible since the man page of mkoctfile explicitely states
> > "mkoctfile is used to compile C, C++, or Fortran source code in to a
> > dynamically loadable .oct file for octave"
> > You will have no luck creating a dynamically loadable file when linking
> > against a library built without -fPIC.
> 
> Actually it is possible, what needs to be dynamic is the final oct file but
> it can include object code from a static library. I think we need more
> information to be able to help. What are the exact commands you used to
> build and link the .oct file? Have you tried something like:
> 
> mkoctfile -c  -I/path_to_your_libray/include octfile.cpp
> mkoctfile octfile.o /path_to_your_libray/lib/libraryname.a -o octfile.oct
> 
> ?
> 
> HTH,
> c.

I tried that now myself and it happened what I expected, (of course you can 
use a static library, I did not say that this is not possible but if it has to 
be built with -fPIC option), without -fPIC it gives

/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/bin/ld: 
hello.o: relocation R_X86_64_32 against `.rodata' can not be used when making 
a shared object; recompile with -fPIC
hello.o: could not read symbols: Bad value
collect2: ld returned 1 exit status

Compiled with -fPIC it works. Or did I now completely misunderstand?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]