
166 Incorporation of C-Functions as CoDeSys Library
WAGO-I/O-SYSTEM 750
758-874/000-131
WAGO-I/O-IPC-C6
Manual
Version 1.0.0
#include <stdio.h>
unsigned short MyTestFunction(unsigned short value)
{
return value+=2;
}
Pos: 46.18 /Serie 758 (Funk, IPC und PFC)/Feldbuskommunikation/C-Funktionen als CoDeSys-Bibliothek @ 10\mod_1312527555987_21.doc @ 75970 @ 123333323332 @ 1
13
Incorporation of C-Functions as CoDeSys
Library
For the use of any C- or also Linux functions in CoDeSys, the import interface
described in the following is available. This can be used to load and use Linux
libraries dynamically into the CoDeSys runtime system.
13.1
Example for Linking a Dynamic Library
The following section will explain to you by means of an example the procedure
for linking a dynamic library using a C-function in CoDeSys.
13.1.1
Developing and Compiling a Linux Shared Library
Before you can use C functions within a CoDeSys program, you must develop and
compile a Linux shared library. Proceed in the following manner:
1.
Create a file with the necessary functions. In this example, the file
"libmytest.c" was created for this purpose with a "MyTestFunction"
function and "unsigned short" data types.
Figure 92: "libmytest.c" file
2.
Compile and link the file by entering the following command in the Linux
console:
gcc libmytest.c -Wall -shared -o libmytest.so
In Linux, the parameter "-shared" must be used when calling up the "gcc"
compiler.
With an error-free compilation of the file, a dynamic library "libmytest.so" is
generated with the parameter "-shared" that contains the "MyTestFunction" C-
function.
File name of the Linux libraries
The file name of the Linux libraries must begin with lib.