CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Thu Jan 23, 2020 12:57 am

All times are UTC+01:00

Post new topic  Reply to topic  [ 1 post ] 
Author Message
PostPosted: Mon Jan 29, 2018 9:15 pm 

Joined: Thu Jan 18, 2018 3:48 pm
Posts: 1

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.

You do not have the required permissions to view the files attached to this post.

Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 1 post ] 

All times are UTC+01:00

Who is online

Users browsing this forum: No registered users and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited