Error G0433 : 'copyAtoB' : Cannot find DLL function

Hello,

I've been trying to call C functions in GAUSS, starting with the simple example at /questions/some-tips-on-calling-c-functions-in-gauss/. I've managed to link the shared library from within GAUSS using the dlibrary command, but receive the following error when trying to actually call the function:

(0) : error G0433 : 'copyAtoB' : Cannot find DLL function

I simply tried to call the function as instructed using:

dllcall copyAtoB(A, B, nelems); 

Do you know why it may not be working for me?

Thanks!

4 Answers



1



accepted

I just successfully compiled and ran that example by compiling this code:

#include <stdlib.h> 

__declspec(dllexport) int copyAtoB(double *A, double *B, double *nelems)
{
   int i, n;

   n = (int)nelems[0];

   for (i = 0; i < n; i++)
      B[i] = A[i];

   return 0;
}

I named the file above copyatob.c. I then compiled it from the Visual Studio command prompt using these two commands. First I entered:

cl /Z7 -c copyatob.c

then I entered:

link /DEBUG /dll /out:copyatob.dll copyatob.obj

I copied the resulting file, copyatob.dll to my GAUSSHOME/dlib directory and then entered this into GAUSS:

dlibrary copyatob;

then:

a = rndn(5,1);
b = zeros(5,1);
n = 5;

dllcall copyatob(a, b, n);

Your problem could have been with name mangling as reported by the last answer, but I think it was actually due to a missing export. That is what the "__declspec(dllexport) " does.



1



Usually when this happens it is because a function is compiled with a C++ compiler that mangles function names. Instead of creating a function called simply, copyAtoB, it will create a function name that adds many different characters to to the base copyAtoB.

This can be prevented in most cases with using "extern C". Here is a link that discusses the issue and some other possible causes of name decoration.

If you are using Linux or Mac, you can use the command-line utility nm to show the actual names of the functions inside of your shared library. On Windows you can also look at this same information with Dependency Walker which can be found here.

aptech

1,773


0



Just wanted to add that I'm building the .dll file from the source .c file using Visual Studio 2013 Express, with the following commands (taken from GAUSS' help file):

cl -c -MD -GX hyp.c
link /dll /out:hyp.dll hyp.obj

I'm using cl.exe and link.exe associated with the 64-bit version (in \bin\x86_amd64), and my GAUSS install is also 64-bit.



0



Thank you guys! I didn't get a chance to fully try out Aptech's suggestion but jjones' solution worked immediately. I was able to use dllcall with no errors.

Your Answer

4 Answers

1
accepted

I just successfully compiled and ran that example by compiling this code:

#include <stdlib.h> 

__declspec(dllexport) int copyAtoB(double *A, double *B, double *nelems)
{
   int i, n;

   n = (int)nelems[0];

   for (i = 0; i < n; i++)
      B[i] = A[i];

   return 0;
}

I named the file above copyatob.c. I then compiled it from the Visual Studio command prompt using these two commands. First I entered:

cl /Z7 -c copyatob.c

then I entered:

link /DEBUG /dll /out:copyatob.dll copyatob.obj

I copied the resulting file, copyatob.dll to my GAUSSHOME/dlib directory and then entered this into GAUSS:

dlibrary copyatob;

then:

a = rndn(5,1);
b = zeros(5,1);
n = 5;

dllcall copyatob(a, b, n);

Your problem could have been with name mangling as reported by the last answer, but I think it was actually due to a missing export. That is what the "__declspec(dllexport) " does.

1

Usually when this happens it is because a function is compiled with a C++ compiler that mangles function names. Instead of creating a function called simply, copyAtoB, it will create a function name that adds many different characters to to the base copyAtoB.

This can be prevented in most cases with using "extern C". Here is a link that discusses the issue and some other possible causes of name decoration.

If you are using Linux or Mac, you can use the command-line utility nm to show the actual names of the functions inside of your shared library. On Windows you can also look at this same information with Dependency Walker which can be found here.

0

Just wanted to add that I'm building the .dll file from the source .c file using Visual Studio 2013 Express, with the following commands (taken from GAUSS' help file):

cl -c -MD -GX hyp.c
link /dll /out:hyp.dll hyp.obj

I'm using cl.exe and link.exe associated with the 64-bit version (in \bin\x86_amd64), and my GAUSS install is also 64-bit.

0

Thank you guys! I didn't get a chance to fully try out Aptech's suggestion but jjones' solution worked immediately. I was able to use dllcall with no errors.


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.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy