How to include static librarys into esp-idf with eclipse?

MajinFoo
Posts: 9
Joined: Sun Jan 21, 2018 9:06 pm

How to include static librarys into esp-idf with eclipse?

Postby MajinFoo » Thu Feb 22, 2018 10:11 pm

Hello,

i have an external library as an .a file that i want to include into my eclipse project. I followed this guide to use esp-idf with eclipse:
https://esp-idf.readthedocs.io/en/v2.0/ ... setup.html

My project structure look like this:
Image

As you can see I have created a separate folder "src" for the external files. Besides my .a file i have also a .h file and a .c file. I have included the directory in the project settings as shown in the figure below:
Image

When I try to build the project, I get the following error message:

Code: Select all

re
21:13:42 **** Build of configuration Default for project BME680BESEC ****
make flash 
CC build/main/main.o
/home/UserName/esp/workspace/BME680BESEC/main/./main.c:21:20: fatal error: bme680.h: No such file or directory
compilation terminated.
/home/UserName/esp/esp-idf/make/component_wrapper.mk:273: die Regel für Ziel „main.o“ scheiterte
/home/UserName/esp/esp-idf/make/project.mk:449: die Regel für Ziel „component-main-build“ scheiterte
make[1]: *** [main.o] Fehler 1
make: *** [component-main-build] Fehler 2

21:13:44 Build Finished (took 1s.473ms)
Looks like the directory wasn't correctly included. If I put the files in the main folder instead and specify the main folder as an include path, then the files will be linked:

Image

Why does it only work with the main folder? If I compile now, I get the following error messages:

Code: Select all

21:31:31 **** Build of configuration Default for project BME680BESEC ****
make flash 
LD build/app-template.elf
/home/UserName/esp/workspace/BME680BESEC/build/main/libmain.a(bsec_integration.o):(.literal.bme680_bsec_update_subscription+0x0): undefined reference to `bsec_update_subscription'
/home/UserName/esp/workspace/BME680BESEC/build/main/libmain.a(bsec_integration.o):(.literal.bme680_bsec_process_data+0x4): undefined reference to `bsec_do_steps'
/home/UserName/esp/workspace/BME680BESEC/build/main/libmain.a(bsec_integration.o):(.literal.bsec_iot_init+0x0): undefined reference to `bsec_init'
/home/UserName/esp/workspace/BME680BESEC/build/main/libmain.a(bsec_integration.o):(.literal.bsec_iot_init+0x4): undefined reference to `bsec_set_configuration'
/home/UserName/esp/workspace/BME680BESEC/build/main/libmain.a(bsec_integration.o):(.literal.bsec_iot_init+0x8): undefined reference to `bsec_set_state'
/home/UserName/esp/workspace/BME680BESEC/build/main/libmain.a(bsec_integration.o):(.literal.bsec_iot_loop+0x4): undefined reference to `bsec_sensor_control'
/home/UserName/esp/workspace/BME680BESEC/build/main/libmain.a(bsec_integration.o):(.literal.bsec_iot_loop+0x8): undefined reference to `bsec_get_state'
/home/UserName/esp/workspace/BME680BESEC/build/main/libmain.a(bsec_integration.o): In function `bme680_bsec_update_subscription':
/home/UserName/esp/workspace/BME680BESEC/main/./bsec_integration.c:138: undefined reference to `bsec_update_subscription'
/home/UserName/esp/workspace/BME680BESEC/build/main/libmain.a(bsec_integration.o): In function `bme680_bsec_process_data':
/home/UserName/esp/workspace/BME680BESEC/main/./bsec_integration.c:397: undefined reference to `bsec_do_steps'
/home/UserName/esp/workspace/BME680BESEC/build/main/libmain.a(bsec_integration.o): In function `bsec_iot_init':
/home/UserName/esp/workspace/BME680BESEC/main/./bsec_integration.c:180: undefined reference to `bsec_init'
/home/UserName/esp/workspace/BME680BESEC/main/./bsec_integration.c:194: undefined reference to `bsec_set_configuration'
/home/UserName/esp/workspace/BME680BESEC/main/./bsec_integration.c:205: undefined reference to `bsec_set_state'
/home/UserName/esp/workspace/BME680BESEC/build/main/libmain.a(bsec_integration.o): In function `bsec_iot_loop':
/home/UserName/esp/workspace/BME680BESEC/main/./bsec_integration.c:481: undefined reference to `bsec_sensor_control'
/home/UserName/esp/workspace/BME680BESEC/main/./bsec_integration.c:499: undefined reference to `bsec_get_state'
/home/UserName/esp/esp-idf/make/project.mk:387: die Regel für Ziel „/home/UserName/esp/workspace/BME680BESEC/build/app-template.elf“ scheiterte
collect2: error: ld returned 1 exit status
make: *** [/home/UserName/esp/workspace/BME680BESEC/build/app-template.elf] Fehler 1

21:31:36 Build Finished (took 4s.935ms)

It looks like my .c and .h files have now been linked. But some functions cannot be called because the reference to the .a file is missing. First i try to include the .a file with eclipse. As far as I know this can be done via the project properties:

Properties --> C/C++ Build --> Settings

But here there is no possibility to include files or directories, as you can see in the picture below:

Image

In Properties --> C/C++ build I check "Generate Makefiles Automatically".

Image

After this i went back to Properties --> C/C++ Build --> Settings. Now i can include the .a file:

Image

When I compile now, I get the following error message:

Code: Select all

21:58:39 **** Build of configuration Default for project BME680BESEC ****
make flash 
make: *** No rule to create "flash".  End.
I uncheck "Generate Makefiles Automatically" and tried to find another solution. Next I tried to use the file component. mk in the main folder to include the a. file. I added the following line:

Code: Select all

COMPONENT_ADD_LDFLAGS=/home/UserName/esp/workspace/ProjectName/main/libalgobsec.a
If I compile now, I get a new error message:

Code: Select all

22:03:29 **** Build of configuration Default for project BME680BESEC ****
make flash 
CC build/main/bme680.o
CC build/main/bsec_integration.o
/home/UserName/esp/workspace/BME680BESEC/main/./bsec_integration.c: In function 'bsec_iot_init':
/home/UserName/esp/workspace/BME680BESEC/main/./bsec_integration.c:161:27: warning: unused variable 'bsec_status' [-Wunused-variable]
     bsec_library_return_t bsec_status = BSEC_OK;
                           ^
/home/UserName/esp/workspace/BME680BESEC/main/./bsec_integration.c: In function 'bme680_bsec_trigger_measurement':
/home/UserName/esp/workspace/BME680BESEC/main/./bsec_integration.c:237:12: warning: variable 'bme680_status' set but not used [-Wunused-but-set-variable]
     int8_t bme680_status = BME680_OK;
            ^
/home/UserName/esp/workspace/BME680BESEC/main/./bsec_integration.c: In function 'bme680_bsec_read_data':
/home/UserName/esp/workspace/BME680BESEC/main/./bsec_integration.c:297:12: warning: variable 'bme680_status' set but not used [-Wunused-but-set-variable]
     int8_t bme680_status = BME680_OK;
            ^
CC build/main/main.o
AR build/main/libmain.a
LD build/app-template.elf
/home/UserName/esp/workspace/BME680BESEC/build/esp32/libesp32.a(cpu_start.o):(.literal.main_task+0x18): undefined reference to `app_main'
/home/UserName/esp/workspace/BME680BESEC/build/esp32/libesp32.a(cpu_start.o): In function `main_task':
/home/UserName/esp/esp-idf/components/esp32/./cpu_start.c:445: undefined reference to `app_main'
/home/UserName/esp/esp-idf/make/project.mk:387: die Regel für Ziel „/home/UserName/esp/workspace/BME680BESEC/build/app-template.elf“ scheiterte
collect2: error: ld returned 1 exit status
make: *** [/home/UserName/esp/workspace/BME680BESEC/build/app-template.elf] Fehler 1

22:03:33 Build Finished (took 3s.862ms)
I wonder why there are error messages in the libesp32.a file, which is not related to my libalgobsec.a file.

I really have no idea how to correctly integrate the external library. Maybe my understanding of the build process in Eclipse and esp-idf is too poor to solve this problem.

I hope I could explain my problem clearly. Can anyone tell me how to integrate an external library?

Damion7
Posts: 1
Joined: Fri May 04, 2018 8:26 pm

Re: How to include static librarys into esp-idf with eclipse?

Postby Damion7 » Fri May 04, 2018 8:34 pm

I ran into the same issue with libalgobsec.a using command line tools (no eclipse). Were you able to resolve this issue?

I added the following lines to my component.mk:

COMPONENT_ADD_INCLUDEDIRS := ./lib
COMPONENT_ADD_LDFLAGS = -L$(COMPONENT_PATH)/lib/ -lalgobsec -l$(COMPONENT_NAME)


This the error I get:
/Users/home/esp/example/build/main/libmain.a(bsec_integration.o):(.literal.bsec_iot_init+0x0): undefined reference to `bsec_set_configuration'
/Users/home/esp/example/build/main/libmain.a(bsec_integration.o):(.literal.bsec_iot_init+0x4): undefined reference to `bsec_set_state'
/Users/home/esp/example/build/main/libmain.a(bsec_integration.o):(.literal.bsec_iot_loop+0x4): undefined reference to `bsec_get_state'
/Users/home/esp/example/build/main/libmain.a(bsec_integration.o): In function `bsec_iot_init':
/Users/home/esp/example/main/bsec_integration.c:194: undefined reference to `bsec_set_configuration'
/Users/home/esp/example/main/bsec_integration.c:205: undefined reference to `bsec_set_state'
/Users/home/esp/example/build/main/libmain.a(bsec_integration.o): In function `bsec_iot_loop':
/Users/home/esp/example/main/bsec_integration.c:499: undefined reference to `bsec_get_state'
collect2: error: ld returned 1 exit status
make: *** [/Users/home/esp/example/build/example.elf] Error 1

Async_Awayt
Posts: 14
Joined: Sun Feb 19, 2017 8:04 pm

Re: How to include static librarys into esp-idf with eclipse?

Postby Async_Awayt » Thu Aug 02, 2018 9:57 am

I am also having the same issue. Anyone can point me in the right direction on how to solve this?

Async_Awayt
Posts: 14
Joined: Sun Feb 19, 2017 8:04 pm

Re: How to include static librarys into esp-idf with eclipse?

Postby Async_Awayt » Fri Aug 03, 2018 10:26 am

I managed to solve the issue by:

1 - Firstly saving the libalgobsec.a file to the same folder as the component.mk file.

2 - Then, adding the following line to component.mk

Code: Select all

COMPONENT_ADD_LDFLAGS +=$(COMPONENT_PATH)/libalgobsec.a
3 - Finally I had to change the app_main declaration from void to int

Code: Select all

int app_main(void)
{
	...
	...
	...
	
	return 0;
}
That solved the issues for me. Can anybody explain why? :?: :?:

Who is online

Users browsing this forum: forrest and 159 guests