Including C++ Precompiled Library in ESP-IDF C Project
Posted: Tue Apr 30, 2019 8:44 pm
I've recently tried to incorporate some C++ precompiled libraries into my IDF project, but haven't been able to get them working correctly. I've scoured this forum and StackOverflow, and seen this question asked before, but never really answered well.
My specific case is that I would like to use the C++ Protobuffer Lib. This is installed locally on my system, but I could also copy the .a file into my project if that made it easier. In the long run, having the library inside the project would probably be better anyway since it wouldn't require other developers on my team to have Protobuffers installed. I thought I would be able to do the following:
1)Write a C++ wrapper that interacted with the library through pure function calls (no public C++ specific features).
2)Link the Library I wanted in the main component.mk file using:
3)Have my C code call the functions from the C++ wrapper when they need to interact with that library (the wrapper keeps all the C++ separated from the C).
This didn't work at all and I'm sure that it is just me not knowing the correct way to go about it. Adding the CXXFLAGS made it so that headers were being found, but I was getting linking issues with errors saying "Undefined reference to function_name" about a thousand times...
Does anyone have a good example of how you would use a C++ library with C code in the IDF including how to get the component.mk file correct for it?
Thanks in advance!
Ethan
My specific case is that I would like to use the C++ Protobuffer Lib. This is installed locally on my system, but I could also copy the .a file into my project if that made it easier. In the long run, having the library inside the project would probably be better anyway since it wouldn't require other developers on my team to have Protobuffers installed. I thought I would be able to do the following:
1)Write a C++ wrapper that interacted with the library through pure function calls (no public C++ specific features).
2)Link the Library I wanted in the main component.mk file using:
Code: Select all
CXXFLAGS += -I/usr/local/include
Code: Select all
COMPONENT_ADD_LDFLAGS += -lthislibraryiwant
This didn't work at all and I'm sure that it is just me not knowing the correct way to go about it. Adding the CXXFLAGS made it so that headers were being found, but I was getting linking issues with errors saying "Undefined reference to function_name" about a thousand times...
Does anyone have a good example of how you would use a C++ library with C code in the IDF including how to get the component.mk file correct for it?
Thanks in advance!
Ethan