Compile C files with C++ compiler while building native extension (DEF-3084)


#1

I tried to create a native extension to access sqlite databases in lua module. I know there would be buildin sqlite support on some platforms (for example iOS / macOS) , just need to link the sqlite lib would be fine. But for other platforms, I have to include sqlite3.c in the src folder and compile it with the extension.

It seems Defold cloud build system compile .C files with C++ compiler, I got lots of errors when I built the sqlite3.c (Please see the attached screenshot for more detail)

Could please anyone help me out of this? Did I miss some build flags?


How to create a Windows release build?
Permissive flag for native extension (DEF-3127) (SOLVED)
#2

Hmm, it seems that’s something to improve upon. I’ve added it as DEF-3084

In the meantime, I would suggest building your static libraries “offline”, and add those to the /libs/ folder.
No need really to build static libs all the time.


#3

Thanks @Mathias_Westerdahl, I’ll go with the static libs workaround. BTW, is HTML5 bundle support static libs? If the answer is YES, what kind of libs should I provide?


#4

BTW, it is amzing the forum is so active, glade to meet so many nice people here, thanks to all for your kind help.


#5

The HTML5 builds support regular c/c++ libraries, built with Emscripten.
Or you can have javascript “libraries”, modified to support Emscripten.

See our HTML5 example for an example, and also the Emscripten documentation for more info


#6

Got it, thanks @Mathias_Westerdahl !


#7

Don’t we have to use extern "C" { } for defining C functions in a C++ program ?

Long time since last time i’ve written C, but i would bet it has something to do with name mangling.


#8

Yes, I used extern “C” { } for the c functions declaration. This problem is not about the name mangling, it is caused by compiling C files with C++ compiler, which is more rigorous than C compiler, and think some C warnings as errors.