Jump to content
OMRON Forums

Creating a User C Library


Omron Forums Support
 Share

Recommended Posts

This is a post on how to create a C Library common to all background programs (i.e. a library whose functions all background C programs can use) in case some of you do not yet know how to do that. Note that for the time being, the library can not be used by CPLCs, only background programs. In the future (in the December release of the IDE, hopefully) CPLCs will be able to link to the libraries.

 

First, in the Solution Explorer of your project in the IDE, right click "Libraries", then "Add a new C Library Project". Name your project whatever you want, e.g., MyLibrary:

 

1.png.cb977eb595c73f93408bc486ddde7a29.png

 

This will automatically create a source file in that folder of the same name but all lower-case, e.g., mylibrary.c. Now right click on the folder (e.g. MyLibrary) and click "Add New Item":

 

2.png.be477fc1a40a197c2062ad08c9dfa4d7.png

 

Click "Background C Header" and name it the same thing as your source file, but with a ".h" extension instead of ".c":

 

3.png.cb5d8a1a6965a58ffca96a7e96f6b44f.png

 

Put all the functions you want to be in your library into the ".c" source code file, and then make sure you copy prototypes of those functions into the ".h" header file.

 

Now in your Background C Program, you can just add this line to include your header file (using the MyLibrary example):

 

#include "../../Libraries/MyLibrary/mylibrary.h"

 

Attached is an example project that has one function (a simple function that just increments a variable whose address is passed to it) in the mylibrary.c source code, the prototype of that function in the mylibrary.h header file, and a Background C Program (capp1.c) that includes the mylibrary.h header file and uses the function.

 

If you have any questions about this, please feel free to post them.

LibraryExample.zip

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted Images

Guest
This topic is now closed to further replies.
 Share


×
×
  • Create New...