Create and use a shared library

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

Create and use a shared library

Post 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.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Create and use a shared library

Post by Mistrel »

Did you try checking FileSize() to see if it's a path issue?
User avatar
the.weavster
Addict
Addict
Posts: 1537
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: Create and use a shared library

Post 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
User avatar
the.weavster
Addict
Addict
Posts: 1537
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: Create and use a shared library

Post 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
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Create and use a shared library

Post by Fred »

Dynamic CPU shouldn't do any difference, if it does there is a bug somewhere.
User avatar
the.weavster
Addict
Addict
Posts: 1537
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: Create and use a shared library

Post by the.weavster »

Then there's a bug somewhere :wink:

btw it's 32 bit Xubuntu.
User avatar
the.weavster
Addict
Addict
Posts: 1537
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: Create and use a shared library

Post by the.weavster »

It must have been one of those mystical problems that's fixed by a reboot because 'All CPU' works today :?
Post Reply