View Full Version : Using a .so file (c++):?:
bartbes
January 27th, 2006, 06:02 PM
I want to use a .so (shared object/library) file in my program, one you have outside of your program and can be changed whenever you want. Does anyone knows how to do this?
toojays
January 27th, 2006, 07:23 PM
Do you mean that you want to use someone elses shared library, or that you want to make your own shared library? If it's someone elses library, and it's installed properly in Ubuntu, you just need to give gcc the correct include path and pass the -lsomelibrary flag when you link.
bartbes
January 28th, 2006, 06:21 AM
It's my own and I want to be able to REPLACE it when I want to make a different program out of it
David Marrs
January 28th, 2006, 01:43 PM
You need to use libtool to generate the config file, but I've never built one from scratch before; I've just stripped the code out of other people's. :d Google found this ebook (http://www.fifi.org/doc/autobook/html/autobook.html), which might help you.
Whoops, no you don't. That's for library objects, not shared objects.
LordHunter317
January 28th, 2006, 01:57 PM
I'm confused by waht you want to do.
If you want the ability to arbitrarily replace your .so with another, you have to code your .so and the replacement one very carefully in order for that to work. They must be in perfect API and ABI compatibilty, or it will not work.
More details, please.
bartbes
January 28th, 2006, 03:51 PM
I want to use the .so file for a function, say I have a program to read files and in different so files I have the function for different file types.. like libdoc.so for docfiles etc. something like that (hope you understand)
But I already have the so file it's just how to get it into my program now
toojays
January 28th, 2006, 06:29 PM
If you already know how to make the so file, you can either pass it to your linker command line, or use dlopen() and friends to load the library and use it.
Have a look at the Shared Libraries howto (http://www.tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html"), but don't take it as gospel---last time I tried using this, I had to do things a bit differently . . . but this doc did at least suggest which llinker options I needed to look at.
LordHunter317
January 28th, 2006, 07:33 PM
My point was, putting functions in a shared library doesn't mean you can just swap in another abritrary shared library that provides the same functions. At anyrate, to do dynamical linking, read the GCC manual.
toojays
January 28th, 2006, 08:53 PM
My point was, putting functions in a shared library doesn't mean you can just swap in another abritrary shared library that provides the same functions.
Actually, it does mean that, if that's what you want it to mean. ;)
It requires bit of up-front design work to structure things though, if you want to do this with C++ classes and not just C functions.
LordHunter317
January 28th, 2006, 08:57 PM
It requires more than that, you can't arbitrarly add virtual functions to existing classes and such or you'll break ABI compatibility.
There's a host of other issues, too.
If the documentation is still up, the Trolltech guys have some excellent documentation on how to maintain C++ ABI compatability and workarounds to avoid breaking it.
asimon
January 28th, 2006, 09:06 PM
If the documentation is still up, the Trolltech guys have some excellent documentation on how to maintain C++ ABI compatability and workarounds to avoid breaking it.
Do you mean by any chance Binary Compatibility Issues With C++ (http://developer.kde.org/documentation/other/binarycompatibility.html)? Anyway, a good reading for C++ developers.
LordHunter317
January 28th, 2006, 09:11 PM
Yes, I do, and that's just the tip of the iceberg, as it doesn't cover template considerations.
toojays
January 28th, 2006, 10:43 PM
It requires more than that, you can't arbitrarly add virtual functions to existing classes and such or you'll break ABI compatibility.
Aye, but that's not what we were talking about, which was swapping shared libraries with the same functions. I was assuming that the interfaces would be the same.
bartbes
January 29th, 2006, 05:29 AM
I done it with this site http://tldp.org/HOWTO/C++-dlopen/index.html and it worked! :D I finally got my program working! Thanks for helping\\:D/
bartbes
February 11th, 2006, 01:27 PM
I made an, well I think I have to call it a header.. Just include it in your file and use the command libloader(absolute path, called function) and in the file you are going to compile to a .so file put this in front of the function you're going to call (without single-quotes): 'extern "C"'
eg. [code]
extern "C" int main() {
code
}
EDIT: forgot to post it.. here it is
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.