I have some function blocks in an application that I'd like to put into a library(compiled or not). These function blocks use some external variables and functions from the application. After creating the library and adding to the original application and compiling, the compiler complains about the external variables/functions of being undefined, not even standard function blocks like TON. Is this behavior normal? Because as I recall this was not a problem in Codesys V2.3. How can I resolve this?
Thanks for the help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For variables, maybe VAR_EXTERNAL does what you need, but I have no experience using it so cannot attest to this. For functions, I do not know of a way for a library to depend on code found inside a project.
That being said, you may want to consider if what you are trying to achieve is the right design. Typically, you would probably want your project to depend on your libraries, not the other way around. This might mean putting global variables in your library or, maybe better yet, not having global variables at all and using instance variables of function blocks. Global variables hinder or prevent code reuse.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have some function blocks in an application that I'd like to put into a library(compiled or not). These function blocks use some external variables and functions from the application. After creating the library and adding to the original application and compiling, the compiler complains about the external variables/functions of being undefined, not even standard function blocks like TON. Is this behavior normal? Because as I recall this was not a problem in Codesys V2.3. How can I resolve this?
Thanks for the help.
For variables, maybe VAR_EXTERNAL does what you need, but I have no experience using it so cannot attest to this. For functions, I do not know of a way for a library to depend on code found inside a project.
That being said, you may want to consider if what you are trying to achieve is the right design. Typically, you would probably want your project to depend on your libraries, not the other way around. This might mean putting global variables in your library or, maybe better yet, not having global variables at all and using instance variables of function blocks. Global variables hinder or prevent code reuse.