Hi,
I've a library in cpp and some libs in c.
Exist a way to compile a mixed project?
I tried to rename the C files in cpp, but I'm submerged from errors.
For me, convert the cpp libs in C is very difficult, but convert C files in cpp is even more difficult.
The interested libs are espmqtt (writed in C) and this https://github.com/imxieyi/esp32-i2c-mpu6050 (writed in C++),
Thanks.
Stefano
Mixed project c and c++ -> possible?
Re: Mixed project c and c++ -> possible?
To the best of my knowledge, you can freely mix C and C++ object files. A common problem is to realize that if you have a source file called a.cpp which define
You can't simply call it from a source file called b.c as:
Instead, you will have to define aFunc() as a C function with the following in a.cpp
Code: Select all
void aFunc() {
}
Code: Select all
extern void aFunc() {
}
void bFunc() {
aFunc();
}
Code: Select all
extern "C" void aFunc() {
}
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: Mixed project c and c++ -> possible?
Depends... If you want to call C code from C++, then no problem. Simply surround the C dot H includes with....
extern "C"
{
#include "myC.h"
#include "myotherC.h"
}
The other way around isn't practical. But if I say it can't be done then someone will come in and show how to do it. The exported names of C++ functions aren't the same as they appear. They are "mangled". Also C++ functions have the hidden "this" parameter. All of this makes calling C++ from C a problem.
John
extern "C"
{
#include "myC.h"
#include "myotherC.h"
}
The other way around isn't practical. But if I say it can't be done then someone will come in and show how to do it. The exported names of C++ functions aren't the same as they appear. They are "mangled". Also C++ functions have the hidden "this" parameter. All of this makes calling C++ from C a problem.
John
Who is online
Users browsing this forum: Baidu [Spider], Gaston1980 and 111 guests