Recent

Author Topic: Using a .so file via a external function call  (Read 12296 times)

windy

  • Full Member
  • ***
  • Posts: 186
Using a .so file via a external function call
« on: September 03, 2007, 12:45:11 pm »
Hi all
I got myself a Mac Mini and have lazarus installed (after lots of searching for problems that cropped up along the way) and have created a simple hello world program and have that running from x windows too :)
Now, need help with using a .so file via a function
I did find this thread:
http://www.lazarus.freepascal.org/index.php?name=PNphpBB2&file=viewtopic&t=2736

now,the .so file works ok in lazarus on linux
now, the error i get with lazarus on the mac mini is error about symbols

some questions:
does the .so file need to be compiled into a .dylib file?
i do have the souce code (make files and c++ code)
(if so, how?)
or do i need to have the .so file in a certain directory?
or?

thanks for any help !!
:) :)

ovidius

  • New Member
  • *
  • Posts: 21
Re: Using a .so file via a external function call
« Reply #1 on: September 03, 2007, 08:24:02 pm »
Quote from: "windy"

some questions:
does the .so file need to be compiled into a .dylib file?
i do have the souce code (make files and c++ code)
(if so, how?)
or do i need to have the .so file in a certain directory?


Short answer. Compile everything and the Makefile should produce a .dylib library. In Mac OS X the dynamic libraries are called .dylib instead of .so.

Long answer: Consult the Apple Documentation on dynamic libraries:
http://developer.apple.com/documentation/DeveloperTools/Conceptual/DynamicLibraries/index.html#//apple_ref/doc/uid/TP40001869

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Using a .so file via a external function call
« Reply #2 on: September 03, 2007, 10:15:40 pm »
Quote from: "ovidius"
Quote from: "windy"

some questions:
does the .so file need to be compiled into a .dylib file?
i do have the souce code (make files and c++ code)
(if so, how?)
or do i need to have the .so file in a certain directory?


Short answer. Compile everything and the Makefile should produce a .dylib library. In Mac OS X the dynamic libraries are called .dylib instead of .so.


The extension has nothing to do with it.

Just be sure to include the -dynamiclib switch to GCC when you compile your C++ code. That will create the library you want.

For example:

g++ mycode.cpp -o mycode.dylib -dynamiclib

You can specify any file name and extension you want with -o. The convention is to use .dylib with OS X.

Thanks.

-Phil

windy

  • Full Member
  • ***
  • Posts: 186
Using a .so file via a external function call
« Reply #3 on: September 04, 2007, 12:34:28 am »
Hi
i discovered that I could just go make from a terminal
and then the Makefile is used (and i changed it to create a .dylib instead of a .so file

but there are some .h header files missing from linux
so trying to work my way through that

update:
i managed to compile using xcode, and instructions here:
http://www.nilobject.com/?p=184
and now lazarus compiles
testing now...

windy

  • Full Member
  • ***
  • Posts: 186
Using a .so file via a external function call
« Reply #4 on: September 04, 2007, 06:05:38 am »
Hi
ok, good, i got this format to work:
g++ mycode.cpp -o mycode.dylib -dynamiclib

but I get an error , when I use the .dynlib file as a function in lazarus Intel Macmini):

symbol _fnmatch used from dynamic library /sw/lib//libgtk-1.2.0.dylib(fnmatch.lo) not from earlier dynamic library /usr/lib/libSystem.B.dylib(fnmatch.So)
Error: Error while linking

ovidius

  • New Member
  • *
  • Posts: 21
Using a .so file via a external function call
« Reply #5 on: September 04, 2007, 08:45:25 am »
Quote from: "windy"
Hi
ok, good, i got this format to work:
g++ mycode.cpp -o mycode.dylib -dynamiclib

but I get an error , when I use the .dynlib file as a function in lazarus Intel Macmini):

symbol _fnmatch used from dynamic library /sw/lib//libgtk-1.2.0.dylib(fnmatch.lo) not from earlier dynamic library /usr/lib/libSystem.B.dylib(fnmatch.So)
Error: Error while linking

The symbol _fnmatch is not the cause of the problem. This is just a warning. There should be something above this line in the output.

Can you post the complete result?

windy

  • Full Member
  • ***
  • Posts: 186
Using a .so file via a external function call
« Reply #6 on: September 04, 2007, 12:25:14 pm »
update:
i managed to compile using xcode, and instructions here:
http://www.nilobject.com/?p=184
and now lazarus compiles
testing now...

ok, latest problem:
the program runs but then stops straight away
with an error about cant find the library file
i have copied my succesfully compiled .dylib file to /sw/local/lib/  and /usr/local/lib/
do i need to use
export DYLD_LIBRARY_PATH=/sw/local/lib/
or similar?

thanks!

windy

  • Full Member
  • ***
  • Posts: 186
Using a .so file via a external function call
« Reply #7 on: September 04, 2007, 12:41:16 pm »
if i dont use the {$linllib
then i do see this error when compiling
Linking project1
/usr/bin/ld: warning suggest use of -bind_at_load, as lazy binding may result in errors or different symbols being used
/usr/bin/ld: Undefined symbols:

that must be a clue

windy

  • Full Member
  • ***
  • Posts: 186
Using a .so file via a external function call
« Reply #8 on: September 04, 2007, 01:12:56 pm »
i seem to be making progress now
my first xcode .dlib test file the test program keeps on wanting to access, so just had to rename the correct one to the test one

so, progress now!

Phil

  • Hero Member
  • *****
  • Posts: 2737
Using a .so file via a external function call
« Reply #9 on: September 04, 2007, 03:42:48 pm »
Quote from: "windy"
the program runs but then stops straight away
with an error about cant find the library file
i have copied my succesfully compiled .dylib file to /sw/local/lib/  and /usr/local/lib/
do i need to use
export DYLD_LIBRARY_PATH=/sw/local/lib/
or similar?


Use otool -L on you executable to find where it's looking for the .dylib.

You can use install_name_tool -change to change where it looks for the library.

Thanks.

-Phil

 

TinyPortal © 2005-2018