Mike Lee
Below is my custom function block. I’ve successfully imported it into OpenPLC Editor using import_tool.py , following the instructions from the OpenPLC website:
 
FUNCTION_BLOCK MY_FB
VAR_INPUT
IN1 : INT;
END_VAR
VAR_OUTPUT
OUT1 : INT;
END_VAR
{{
SetFbVar(OUT1, my_c_api(GetFbVar(IN1)));
}}
END_FUNCTION_BLOCK
 
However, during compilation I get the following error:
 
C:/Users/mikelee/OpenPLC_Editor/mingw/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:\customer\adlink\20250722\fb3\build\Res0.o:Res0.c🙁.text+0x1e3): undefined reference to `my_c_api`
C:/Users/mikelee/OpenPLC_Editor/mingw/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:\customer\adlink\20250722\fb3\build\Res0.o:Res0.c🙁.text+0x2ac): undefined reference to `my_c_api`
collect2.exe: error: ld returned 1 exit status
 
In my use case, my_c_api is a function that only exists at OpenPLC runtime. I don’t intend to link it during the build stage inside OpenPLC Editor. So I’m confused why this linker error is happening.
Is there anyone who can help me resolve this?
Thanks in advance!
Reply 0 0
thiagoralves
The editor needs to be aware of this function. As it is explained in the tutorial, there are two MatIEC copies, one for the editor and another for the runtime. If you don’t patch the editor copy, it won’t be able to compile your project. You need to include this function on the editor MatIEC even if it is blank.
Reply 0 0
Mike Lee
Hi thiagoralves,
Thank you for your reply.
I found a workaround that allows me to proceed. I declared an empty inline function for my_c_api during the build stage, so the linker no longer reports an undefined reference. At runtime, the actual implementation is provided by the OpenPLC runtime environment.
Please let me know if there’s a cleaner or more appropriate way to handle this.
 
#ifdef __cplusplus
extern "C" {
#endif
inline int my_c_api(int input){return 0;}
#ifdef __cplusplus
}
#endif
Reply 1 0
Reply