Calling dynamically linked library in Gauss 15 Macosx

Hello,

I would like to be able to call compiled C call from inside GAUSS (v. 15, Macosx Yosemite). I use the example provided in this discussion, but GAUSS crashes without any error message. Is there a way to have some debug feedback in this situation? Is there a crash file, or a messages file, that provides some feedback as to why this has happened?

Many thanks!

6 Answers



1



There is a known bug on the latest versions of Mac OSX where GAUSS will crash if it fails to load a library, instead of returning G00432 : failed to load dynamic library. This is almost certainly what is happening.

The problem in this case is that GAUSS for Mac looks for only files ending with the .so file extension. You should be able to resolve this problem by making a shared library with a .so rather than .dylib extension. (Alternatively, advanced users could make a symbolic link with: ln -s my_library.dylib my_library.so from the Mac command prompt). This should resolve your problem.

Some other considerations for linking on Mac
(I don't think the original poster will need this, but future users searching the forum might, so the following is included for completeness.)

In your case above, the shared library you create does not depend on any other shared libraries. If your library, however, is dynamically linked to any non-system shared libraries, those will also have to be available and have all of their dependencies. So if you are trying to load my_library.dylib with dlibrary into GAUSS, but it depends upon my_other_library.dylib, then you will need to make sure that my_library.dylib can find my_other_library.dylib. The Mac command line utility otool will give you a list of all libraries that your library depends on. For example:

otool -L my_library.dylib

will return a list of libraries that my_library.dylib needs to be able to run.

aptech

1,773


1



Sorry, my mistake! Mac and Linux historically start all shared libraries with a 'lib' prefix. GAUSS adds a 'lib' to the front of the name that you specify in the dlibrary statement. So, if you say: dlibrary mylib;, GAUSS will look for libmylib.so. So your problem is that GAUSS is still not finding your library and that is why it is hanging. Here is a full example with all the steps I took to make this run:

  1. Place the example code in a file named my_dlib.c.
  2. I compiled the code with this command:
    gcc -o libmylib.so -shared -fPIC -g -O3 -Wall my_dlib.c
  3. I placed the newly created libmylib.so in GAUSSHOME/dlib (which should be something like /Users/MyUserName/gauss15/dlib)
  4. Inside of GAUSS I entered:
    dlibrary mylib; 
    a = rndn(5,1); 
    b = zeros(5,1); 
    r = 5; 
    print a~b; 
    dllcall copyAtoB(a, b, r); 
    print a~b
    

aptech

1,773


0



Some follow-up comments:

a) I compile the code with the following command (assuming that the C code is in mylib.c):

>gcc -fpic -Wall -dynamiclib -o mylib.dylib mylib.c

The resulting .dylib file is

Mach-O 64-bit dynamically linked shared library x86_64

and the sysstate(40,1) output is consistent (i.e. 64-bit).

b) After transfering the .dylib file to GAUSSDIR/dlib, I invoke

dlibrary mylib

and the program crashes.



0



I have also tried to use the following Makefile for the compilation of the code:

CCOPTIONS = -g -O2 -fpic -lm -lc -shared
CC = gcc
mylib.dylib: mylib.c
$(CC) $(CCOPTIONS) -o $@ mylib.c

with the same results.



0



Many thanks for your answer! After changing the extension, GAUSS accepts the command, but it now hangs.



0



Many, many thanks for your kind help which I highly appreciate!

Your Answer

6 Answers

1

There is a known bug on the latest versions of Mac OSX where GAUSS will crash if it fails to load a library, instead of returning G00432 : failed to load dynamic library. This is almost certainly what is happening.

The problem in this case is that GAUSS for Mac looks for only files ending with the .so file extension. You should be able to resolve this problem by making a shared library with a .so rather than .dylib extension. (Alternatively, advanced users could make a symbolic link with: ln -s my_library.dylib my_library.so from the Mac command prompt). This should resolve your problem.

Some other considerations for linking on Mac
(I don't think the original poster will need this, but future users searching the forum might, so the following is included for completeness.)

In your case above, the shared library you create does not depend on any other shared libraries. If your library, however, is dynamically linked to any non-system shared libraries, those will also have to be available and have all of their dependencies. So if you are trying to load my_library.dylib with dlibrary into GAUSS, but it depends upon my_other_library.dylib, then you will need to make sure that my_library.dylib can find my_other_library.dylib. The Mac command line utility otool will give you a list of all libraries that your library depends on. For example:

otool -L my_library.dylib

will return a list of libraries that my_library.dylib needs to be able to run.

1

Sorry, my mistake! Mac and Linux historically start all shared libraries with a 'lib' prefix. GAUSS adds a 'lib' to the front of the name that you specify in the dlibrary statement. So, if you say: dlibrary mylib;, GAUSS will look for libmylib.so. So your problem is that GAUSS is still not finding your library and that is why it is hanging. Here is a full example with all the steps I took to make this run:

  1. Place the example code in a file named my_dlib.c.
  2. I compiled the code with this command:
    gcc -o libmylib.so -shared -fPIC -g -O3 -Wall my_dlib.c
  3. I placed the newly created libmylib.so in GAUSSHOME/dlib (which should be something like /Users/MyUserName/gauss15/dlib)
  4. Inside of GAUSS I entered:
    dlibrary mylib; 
    a = rndn(5,1); 
    b = zeros(5,1); 
    r = 5; 
    print a~b; 
    dllcall copyAtoB(a, b, r); 
    print a~b
    
0

Some follow-up comments:

a) I compile the code with the following command (assuming that the C code is in mylib.c):

>gcc -fpic -Wall -dynamiclib -o mylib.dylib mylib.c

The resulting .dylib file is

Mach-O 64-bit dynamically linked shared library x86_64

and the sysstate(40,1) output is consistent (i.e. 64-bit).

b) After transfering the .dylib file to GAUSSDIR/dlib, I invoke

dlibrary mylib

and the program crashes.

0

I have also tried to use the following Makefile for the compilation of the code:

CCOPTIONS = -g -O2 -fpic -lm -lc -shared
CC = gcc
mylib.dylib: mylib.c
$(CC) $(CCOPTIONS) -o $@ mylib.c

with the same results.

0

Many thanks for your answer! After changing the extension, GAUSS accepts the command, but it now hangs.

0

Many, many thanks for your kind help which I highly appreciate!


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.