ESP32 CMake, How to add my own static library file to project? (ESPIDF v4.1dev)

pinock
Posts: 12
Joined: Thu Oct 17, 2019 12:32 pm

ESP32 CMake, How to add my own static library file to project? (ESPIDF v4.1dev)

Postby pinock » Thu Oct 17, 2019 12:35 pm

I added the following two lines to CMakeLists.txt

Code: Select all

add_library(BCXConfiguration STATIC IMPORTED)
set_property(TARGET BCXConfiguration PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libs/libBCXConfiguration.a)
but when I compile it gives the following error

Code: Select all

undefined reference to `BakelorEDK::BCXConfiguration::BCXConfiguration()'
undefined reference to `BakelorEDK::BCXConfiguration::Init()'
....
i attached simple hello world sample app. thanks in advance
Attachments
staticlib_helloworld.zip
(16.46 KiB) Downloaded 153 times

jsam589
Posts: 67
Joined: Sat Aug 17, 2019 9:31 pm

Re: ESP32 CMake, How to add my own static library file to project? (ESPIDF v4.1dev)

Postby jsam589 » Mon Oct 21, 2019 7:16 pm

Hi @pinock,

I did get success with mine. I will try to help you with your issue. Give me a day or so and I will try to replicate with your library and hello world example. I am working with v4.0-beta1 IDF and CMake. So, that should be close to what you are trying.

jsam589
Posts: 67
Joined: Sat Aug 17, 2019 9:31 pm

Re: ESP32 CMake, How to add my own static library file to project? (ESPIDF v4.1dev)

Postby jsam589 » Tue Oct 22, 2019 12:40 am

Good news! I was able to build hello world successfully with your BCX library. I am attaching a tar file of the cleaned project (idf.py fullclean). You should be able to untar it somewhere and build with idf.py build. It will create a default sdkconfig as part of the build. I did not try to make the component.mk files match since we don't care about make, only CMake.

I am using v4.0-beta1 IDF and CMake.

I started with the IDF's hello world example, then modified main to be a .cpp file and put your BCX lines into it.

I placed the library in folder components/bcx_lib/ and the special CMake commands are in CMakeLists.txt of the bcx_lib/ folder.

This is an analogous arrangement to how I got my own project to build with a prebuilt library.

To "prove" that the linkage actually works, look in the map file. I think it uses the provided *.a library file directly when linking so there is nothing new under build/ folder for the BCX library. Looking in the map file, we can see things like the following, which indicates to me successful linking:

.text._ZN10BakelorEDK16BCXConfigurationC2Ev
0x00000000400d59e4 0x1a /home/samall/ESP40_wk1/helpPinock/tryLib2/hello_world/components/bcx_lib/libBCXConfiguration.a(BCXConfiguration.cpp.obj)
0x1e (size before relaxing)
0x00000000400d59e4 _ZN10BakelorEDK16BCXConfigurationC1Ev
0x00000000400d59e4 _ZN10BakelorEDK16BCXConfigurationC2Ev
*fill* 0x00000000400d59fe 0x2
.text._ZN10BakelorEDK16BCXConfiguration4InitEv
0x00000000400d5a00 0x4c /home/samall/ESP40_wk1/helpPinock/tryLib2/hello_world/components/bcx_lib/libBCXConfiguration.a(BCXConfiguration.cpp.obj)
0x58 (size before relaxing)
0x00000000400d5a00 _ZN10BakelorEDK16BCXConfiguration4InitEv
Attachments
helloStatic2.tar
(40 KiB) Downloaded 183 times

pinock
Posts: 12
Joined: Thu Oct 17, 2019 12:32 pm

Re: ESP32 CMake, How to add my own static library file to project? (ESPIDF v4.1dev)

Postby pinock » Tue Oct 22, 2019 6:45 pm

i wil check now! thank you so much

pinock
Posts: 12
Joined: Thu Oct 17, 2019 12:32 pm

Re: ESP32 CMake, How to add my own static library file to project? (ESPIDF v4.1dev)

Postby pinock » Tue Oct 22, 2019 7:01 pm

yes linking succeed. but why give this error?
Screen Shot 2019-10-22 at 21.56.48.png
Screen Shot 2019-10-22 at 21.56.48.png (206.47 KiB) Viewed 1732 times

BCXConfiguration source attached
Attachments
BCXConfiguration.zip
(1.25 KiB) Downloaded 129 times

jsam589
Posts: 67
Joined: Sat Aug 17, 2019 9:31 pm

Re: ESP32 CMake, How to add my own static library file to project? (ESPIDF v4.1dev)

Postby jsam589 » Wed Oct 23, 2019 12:47 pm

EDIT: Is BCXConfiguration.cpp the source that you want to use to make your static library? If so, I have only tried making libraries as components within a full application. So, I am not sure of the syntax for a project that is only intended to create a library.

Original response:
I looked at it but I don't have an answer on this one. You have a REQUIRES for nvs_flash and the ESP headers all seem to have #ifdef __cplusplus to prevent name-mangling. Are the error messages from the compilation step for BCXConfiguration.cpp? It may be that the #include path isn't looking in correct places, or name-mangling is still occurring? It should be something fairly simple.

pinock
Posts: 12
Joined: Thu Oct 17, 2019 12:32 pm

Re: ESP32 CMake, How to add my own static library file to project? (ESPIDF v4.1dev)

Postby pinock » Sat Oct 26, 2019 2:15 pm

btw. thanks for your effort. im realy grateful.

I'm developing BCXConfiguration library and i want to closed source.

pinock
Posts: 12
Joined: Thu Oct 17, 2019 12:32 pm

Re: ESP32 CMake, How to add my own static library file to project? (ESPIDF v4.1dev)

Postby pinock » Tue Nov 19, 2019 8:43 am

jsam589 wrote:
Wed Oct 23, 2019 12:47 pm
EDIT: Is BCXConfiguration.cpp the source that you want to use to make your static library? If so, I have only tried making libraries as components within a full application. So, I am not sure of the syntax for a project that is only intended to create a library.

Original response:
I looked at it but I don't have an answer on this one. You have a REQUIRES for nvs_flash and the ESP headers all seem to have #ifdef __cplusplus to prevent name-mangling. Are the error messages from the compilation step for BCXConfiguration.cpp? It may be that the #include path isn't looking in correct places, or name-mangling is still occurring? It should be something fairly simple.
I have been trying for a long time but I could not find a solution. I had to write to you again.

I share the full app with you.


After build SomeSDK application, I copied the BCXConfiuration library from the following path
SomeSDK\build\esp-idf\BCXConfiguration\libBCXConfiguration.a

and i want use BCXLibrary standalone and i want to use with hellostatic app in attachment


thanks in advance
Attachments
SomeSDK&HelloStatic.zip
(33.77 KiB) Downloaded 151 times

Who is online

Users browsing this forum: No registered users and 35 guests