OpenLibrary() works from IDE but not executable

Linux specific forum
User avatar
the.weavster
Addict
Addict
Posts: 1536
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

OpenLibrary() works from IDE but not executable

Post by the.weavster »

I have a shared library (created in PB[C]) that I can successfully load and call from my code in the PB IDE but when I compile my program (also PB[C]) it then fails to load the library.

Any ideas what the problem could be?

Code: Select all

Prototype Prototype_ServerStart(nPort, *sRootDir, *RouterFunction, *FreeFunction, *ErrorFunction)
Prototype Prototype_ServerStop()
Global ServerStart.Prototype_ServerStart
Global ServerStop.Prototype_ServerStop

Global sLibName.s = "appserver.so"
CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Windows
    sLibName = "appserver.dll"
CompilerEndSelect

Global server_lib = OpenLibrary(#PB_Any, sLibName)
If server_lib
  ServerStart = GetFunction(server_lib, "ServerStart")
  ServerStop  = GetFunction(server_lib, "ServerStop")
Else
  MessageRequester("Error", "Failed to load library", 0)
  End
EndIf
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: OpenLibrary() works from IDE but not executable

Post by mk-soft »

perhaps missing path to library
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
the.weavster
Addict
Addict
Posts: 1536
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: OpenLibrary() works from IDE but not executable

Post by the.weavster »

You're right.
From the IDE I can just use the library name (it's in the same folder as the code) but once compiled I have to provide the full path.
swhite
Enthusiast
Enthusiast
Posts: 726
Joined: Thu May 21, 2009 6:56 pm

Re: OpenLibrary() works from IDE but not executable

Post by swhite »

This seems to be an undocumented issue as I ran into it some years ago with the Chilkat library. You need the full path in the compiled version of your application.

Simon
Simon White
dCipher Computing
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: OpenLibrary() works from IDE but not executable

Post by luis »

the.weavster wrote: Sun Sep 25, 2022 7:30 pm From the IDE I can just use the library name (it's in the same folder as the code) but once compiled I have to provide the full path.
If the .so is in the same dir of the executable, you should be able to open it using "./" before the name instead of the full path.
I do it this way under windows and linux and it works.
Anyway using the full path is not a big problem since it can be easily obtained programmatically, so ...
"Have you tried turning it off and on again ?"
A little PureBasic review
Post Reply