I have an embedded IoT application that I developed for a customer 1.5 years ago. The application is quite large and written in C. It continues to work fine.
The customer asked me add an HDMI touch display along with some complex graphics. I selected Qt as the graphics framework. Qt is great, however, it is written in C++. Not wanting to re-write the C code to C++, I refactored the C code to collection of callable methods or services.
Yes, I know C should compile and execute properly in C++. However, anyone who has done that must first develop the C code with the assumptions that it will be compiled and executed in a C++ environment. Otherwise you get lots of compile errors and a lot of rewriting.
I created all of the C++ classes and C services. I first compile the C code using gcc and create c-object.o file. I used the following in my c-code header file:
#ifdef __cplusplus
extern "C" {
#endif
I first compile the C-code and generate the c-object.o. As crazy as it seems, I use Qt creator to generate the .pro files, qmake to generate the Makefile and make to compile and link.
I get all kinds of link errors because the Makefile has no reference to the C-code. However, make outputs all of its g++ commands to the display. I simply copy and paste to notepad the last make g++ command that links all of the cpp-object.o files -- the one that creates all of the link "object reference not found" errors. I then copy and paste to notepad the c-object.o files names and library names in the g++ command. I re-run the modified g++ command and everything works. chorusclient.o is the c-object.
g++ -Wl,-O1 -o AvEdgeDemo chorusclient.o main.o login.o hud.o /
sqliteservices.o driveraccess.o maintenanceaccess.o /
fleetmanagementaccess.o iotdataaccess.o keyboard.o /
moc_login.o moc_hud.o moc_driveraccess.o /
moc_maintenanceaccess.o moc_fleetmanagementaccess.o /
moc_iotdataaccess.o moc_keyboard.o /
-L/usr/lib/arm-linux-gnueabihf -lQtSql -lQtGui /
-lQtCore -lpthread -lssl -lcrypto -ljson-c
Is there a way that I can get qmake or make to recognize the C-code and properly compile and link? The cutting, pasting, and re-linking is awkward to say the least!