[SOLVED]: .so file on Linux Topic is solved

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4152
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

[SOLVED]: .so file on Linux

Post by ONEEYEMAN » Mon Aug 22, 2005 6:36 pm

Hi, ALL,
Do I have to link my application with my shared .so file?

I am using "LoadLibrary()" to load the file, but no luck yet... :(

Library and application compiles fine, but LoadLibrary fails!

Using KDevelop 3.2.1/KDE 3.4.1 as development environment.

It's wxGTK 2-6-1

Thank you in advance.
Last edited by ONEEYEMAN on Fri Oct 21, 2005 7:09 pm, edited 1 time in total.

heda
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sun Jul 10, 2005 1:11 pm

Post by heda » Tue Aug 23, 2005 3:22 am

Hi,
LoadLibrary() is part of Windows API and doesn't work under Linux. If you want to load a shared library by your program (without linking it with the shared library on linking process), you can use wxDynamicLibrary which works on different platforms. ( Linux's native function is dlopen() )

Good Luck,
Hedayat

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4152
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Post by ONEEYEMAN » Tue Aug 23, 2005 4:10 am

Thank you for the reply, heda.
I am actually using the wxDynamicLibrary.LoadLibrary(), but wondering if I have to link the app against the .so file?
I am using the KDevelop 3.2.1 with the wxWidgets support.

Thank you

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Tue Aug 23, 2005 7:25 am

You don't need to link with the .so (you never would have to, it's a shared object...) or the corresponding .a file.

Use wxDynamicLibrary::Load() and check if it returned true. You can then use GetSymbol() to get the actual functions. Be sure to either create wxDynamicLibrary on the heap, or use wxDynamicLibrary::Detach() and call wxDynamicLibrary::Unload() later, as the library will be unloaded by the destructor of wxDynamicLibrary.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4152
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Post by ONEEYEMAN » Wed Aug 24, 2005 1:56 am

As far as I remember, if the file name is "libdialogs.so", all I should pass is "dialogs", right?

Thank you.

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Wed Aug 24, 2005 7:11 am

ONEEYEMAN wrote:As far as I remember, if the file name is "libdialogs.so", all I should pass is "dialogs", right?
???
If it was libdialogs.a and you want to link it in using gcc the parameter would be -ldialogs, correct. But it's a shared object, like DLL in windows. You don't link with it. Use the full name / path when loading it.
Not sure about Linux, but on Windows a DLL would be searched for in several places in this order:
1. The directory from which the application loaded.
2. The current directory.
3. The system directory. Use the GetSystemDirectory function to get the path of this directory.
4 .The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
6. The directories that are listed in the PATH environment variable.

I suppose there's something similar in Unix, so maybe only wxDynamicLibrary::Load("libdialogs.so") would do the trick.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

Post Reply