pfguenette - 2018-01-29


I'm following the instructions in the attached document for creating an external C library, but I'm having issues. I've created a library with only one function - testFunc, which takes one INT and returns an INT.

Saving as an external library generates a header (.h) file and a source (.c) file. After fixing the INT -> int16_t issues, I compile with MSVC / Visual Studio, which generates a .obj file. I place that file and the .lib in the same directory, and import the .lib into my Codesys project. I can then call the library function by calling testFunc(), either via ST or CFC. That all works, and it compiles and uploads to the controller. But the values I get back are just garbage. For example, I wrote my function to be:

   inVal: INT;
int16_t testFunc(int16_t inVal){
   return inVal * 2;

I send the value 10, and get back the value -24569. Sending different values doesn't change the return value, but calling it in a different place seems to.

Does anyone have any idea why this would happen?

EDIT: I just realized that even if the .obj isn't in the folder, I get the same value.

C_IN_32Bit_E.pdf [179.98 KiB]