Steps to build and run a C program that uses SQLite database calls.
This isn't different than any other IOT2000 SDK project. In Eclipse, select File -> New -> Other -> SIMATIC IOT2000 -> SIMATIC IOT2000 Project.
Give your project a name (I used iot2020_sqlite) and select the location of the SIEMENS SDK.
Configure the project for SQLite3The SDK contains all you need to compile SQLite C/C++ programs. There's nothing to do for the includes. Just adding the include is enough:
#include <sqlite3.h>
To link in the SQLite objects, you need to make a change. You have to tell the linker to add the library. To do this, right-click on your project and select Properties -> C/C++ Build -> Settings -> IOT2000 Linker -> General.
Then add the sqlite lib (use -lsqlite3) to the Flags:
-lmraa -lsqlite3 -fno-use-linker-plugin
Write codeI've used the first example of SQLite C/C++ Tutorial. It stands out in simplicity. Can I create a database in my home folder with the SQLite API:
// ...
#include <sqlite3.h>
int main(void) {
// ...
sqlite3 *db;
int rc;
rc = sqlite3_open("test.db", &db);
if( rc ){
sqlite3_errmsg(db);
// ...
return 0;
}else{
// ...
}
sqlite3_close(db);
return 0;
}
Set up the debugger (I've written a how-to that explains how you can do that with the current IOT2000 example image and Eclipse NEON). Step through the code. After the line sqlite3_open(), there should be a file test.db with a size of 0 bytes created in your home directory.
Step in the debugger if RC is 0 after that function call. If this is OK, you have a successful test. You can now add SQL statements to your program.
Additional info: the header and library files are located in the SDK in these folders:
- Lib: SDK/iot2000-sdk-windows-2.1.2/sysroots/i586-nlp-32-poky-linux/usr/lib
- Header: SDK/iot2000-sdk-windows-2.1.2/sysroots/i586-nlp-32-poky-linux/usr/include
Comments
Please log in or sign up to comment.