Page 1 of 1

Create and use a shared library

Posted: Fri Dec 09, 2016 12:14 pm
by the.weavster
Could somebody please tell me what I'm doing wrong?

I compile this as hw.so...

Code: Select all

ProcedureCDLL hw()
  MessageRequester("Message","Hello, World!",0)
EndProcedure
...and try and call it like this (compiled as hwt):

Code: Select all

If OpenLibrary(0,"hw.so")
  CallCFunction(0,"hw")
  CloseLibrary(0)
Else
  MessageRequester("Oops","No Luck",0)
EndIf
I tried running it with the library side by side like this:
$ LD_LIBRARY_PATH=. ./hwt

that didn't work so I copied hw.so to /usr/lib, ran:
$ sudo ldconfig

but I still can't load my library.

Re: Create and use a shared library

Posted: Fri Dec 09, 2016 12:23 pm
by Mistrel
Did you try checking FileSize() to see if it's a path issue?

Re: Create and use a shared library

Posted: Fri Dec 09, 2016 1:30 pm
by the.weavster
It's to do with the library. I have copied hw.so to /usr/lib and it still doesn't work but I can open another library in that location, i.e. this one works:

Code: Select all

If OpenLibrary(0,"libxine.so")
  MessageRequester("Yes","I can open that one",0)
  CloseLibrary(0)
Else
  MessageRequester("Oops","No luck here either",0)
EndIf

Re: Create and use a shared library

Posted: Fri Dec 09, 2016 1:38 pm
by the.weavster
Got it.
I have to select 'Dynamic CPU' in the compiler options, I'd only set 'Shared .so'

And using this as my launcher:

Code: Select all

#!/usr/bin/env bash

LD_LIBRARY_PATH=. ./hwt
does make them work side by side too :D

Re: Create and use a shared library

Posted: Fri Dec 09, 2016 4:13 pm
by Fred
Dynamic CPU shouldn't do any difference, if it does there is a bug somewhere.

Re: Create and use a shared library

Posted: Fri Dec 09, 2016 4:18 pm
by the.weavster
Then there's a bug somewhere :wink:

btw it's 32 bit Xubuntu.

Re: Create and use a shared library

Posted: Tue Dec 13, 2016 7:35 pm
by the.weavster
It must have been one of those mystical problems that's fixed by a reboot because 'All CPU' works today :?