I am trying to call a C++ function from a C file. So I declared the function as extern "C" and declared it in C file as well. Created a object file from the cpp file let's call it cpp_object.o, then created a object file for the main.c.
It is not that obvious that I can use g++ to link them. No, the main calls some c libs so I cannot link them with g++. So I have to link them with gcc. I tried the followings:
main: main.o cpp_object.o
${CROSS}${CC} $^ -o $@ ${LDFLAGS}
It shows error that the object file cannot find the C++ stdlib. I did not know what happened. Googled it tried the following:
main: main.o get_config.o
${CROSS}${CC} $^ -o $@ ${LDFLAGS} -lstdc++
Then it worked!? Does it mean the gcc compile the code with the c++ stdlib? But I am bit confused, how do we need to compile a C code with c++ stl?
So is this actually did what I wanted? Or I missed something?