Message Boards Message Boards

0
|
9373 Views
|
7 Replies
|
3 Total Likes
View groups...
Share
Share this post:

problems with LibraryFunctionLoad

Posted 10 years ago

Hi, I’m trying out Mathematica to connect our shared library to Mathematika but I have problems during running functions in the shared Library. So I started with a test shared library. Some parts work fine so far. At first what worked:

1.  AppendTo[$LibraryPath,  ToFileName["/slowfs/lithop4-nb-2/egger/Mathematica/Tests"]];

2.  LibraryLoad["libtestlib"]

3.  INTTEST2 =  LibraryFunctionLoad["libtestlib", "Inttest2", {Integer, Integer}, Integer]

That worked so far. But running

INTTEST2[10, 101]

returned an error message:

LibraryFunction::rterr: An error with return code -1429266942 was encountered evaluating the function Inttest2. >>

I used Red Hat Enterprise Linux Client release 5.7 (Tikanga) and gcc version 4.1.2 20080704 (Red Hat 4.1.2-51). Building the test shared library was done by

gcc -c -g -fPIC testlib.cpp -I.

gcc -shared -o libtestlib.so testlib.o

The console output from my shared library was:

Inttest2 parameter 1 is -1429266944 and parameter 2 is 2

Inttest parameter is -1429249280

I added two attachments testlibheader.txt that contains the header file testlib.h and testlibsource.txt in unix text format.

The interesting lines of the header are:

void Inttest1(int iTest);

int Inttest2(int iTest, int iTest2);

and of the cpp file are:

void Inttest1(int iTest) { std::cerr << "Inttest parameter is " << iTest << std::endl; }

long Inttest2(long iTest, long iTest2) { std::cerr << "Inttest2 new parameter 1 is " << iTest << " and parameter 2 is " << iTest2 << std::endl; long iSum = iTest + iTest2; return iSum; }

I hope you can help me with that problem. Kind regards, Roland

Attachments:
POSTED BY: Roland
7 Replies
Posted 10 years ago

Hello,

has anybody any experience with LibraryFunctionLoad?

Kind regards,

Roland

POSTED BY: Roland

From looking at the source you posted, you haven't included the WolframLibrary.h header or the DLLEXPORT type; have you gone through the LibraryLink "User Guide"?

In general, to call a function like this, you'll need some sort of interface function like:

DLLEXPORT int demo1_I_I( WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {
    mint I0;
    mint I1;
    I0 = MArgument_getInteger(Args[0]);
    I1 = I0 + 1;
    MArgument_setInteger(Res, I1);
    return LIBRARY_NO_ERROR;
}

(this gets an integer from M, add 1 to it, and then returns it to M)

POSTED BY: Nick Lariviere

It looks like there is a misunderstanding here. LibraryFunctionLoad is not meant for loading and calling arbitrary C functions. You will need to write C functions that follow specific rules before they can be loaded using LibraryFunctionLoad. Please see the LibraryLink user guide on how to do this.

POSTED BY: Szabolcs Horvát
Posted 10 years ago

Hi Nick, thank you for your answer. That is an interesting information. I tried to look into your link http://reference.wolfram.com/language/LibraryLink/tutorial/LibraryStructure.htm but I got only "Document Not Found". [\Freaked smiley] Oops, the page you are looking for cannot be found.

I found and read: http://reference.wolfram.com/language/guide/ExternalOperations.html

Ah, now I think I found it: http://reference.wolfram.com/language/LibraryLink/tutorial/Overview.html Let's see if it helps me. If you have another link for me please send it.

Kind regards,

Roland

POSTED BY: Roland
Posted 10 years ago

Hello Szabolcs,

thank you, too. I found a tutorial link above.

http://reference.wolfram.com/language/LibraryLink/tutorial/Overview.html

If you know another interesting link for me please send it. Best regards, Roland

POSTED BY: Roland
Posted 10 years ago

Hi, I’m trying out Mathematica to connect our shared library to Mathematika but I have problems during running functions in the shared Library. So I started with a test shared library. Some parts work fine so far. At first what worked:

1.  AppendTo[$LibraryPath,  ToFileName["/slowfs/lithop4-nb-2/egger/Mathematica/Tests"]];

2.  LibraryLoad["libtestlib"]

3.  INTTEST2 =  LibraryFunctionLoad["libtestlib", "Inttest2", {Integer, Integer}, Integer]

That worked so far. But running

INTTEST2[10, 101]

returned an error message:

LibraryFunction::rterr: An error with return code -1429266942 was encountered evaluating the function Inttest2. >>

I used Red Hat Enterprise Linux Client release 5.7 (Tikanga) and gcc version 4.1.2 20080704 (Red Hat 4.1.2-51). Building the test shared library was done by

gcc -c -g -fPIC testlib.cpp -I.

gcc -shared -o libtestlib.so testlib.o

The console output from my shared library was:

Inttest2 parameter 1 is -1429266944 and parameter 2 is 2

Inttest parameter is -1429249280

I added two attachments testlibheader.txt that contains the header file testlib.h and testlibsource.txt in unix text format.

The interesting lines of the header are:

void Inttest1(int iTest);

int Inttest2(int iTest, int iTest2);

and of the cpp file are:

void Inttest1(int iTest) { std::cerr << "Inttest parameter is " << iTest << std::endl; }

long Inttest2(long iTest, long iTest2) { std::cerr << "Inttest2 new parameter 1 is " << iTest << " and parameter 2 is " << iTest2 << std::endl; long iSum = iTest + iTest2; return iSum; }

I hope you can help me with that problem. Kind regards, Roland

POSTED BY: Roland
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract