Page 1 of 1

OpenLibrary() works from IDE but not executable

Posted: Sun Sep 25, 2022 7:17 pm
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

Re: OpenLibrary() works from IDE but not executable

Posted: Sun Sep 25, 2022 7:20 pm
by mk-soft
perhaps missing path to library

Re: OpenLibrary() works from IDE but not executable

Posted: Sun Sep 25, 2022 7:30 pm
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.

Re: OpenLibrary() works from IDE but not executable

Posted: Tue Sep 27, 2022 12:58 pm
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

Re: OpenLibrary() works from IDE but not executable

Posted: Fri Mar 03, 2023 8:57 pm
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 ...