Page 1 of 1

Adding your own library to your program.

Posted: Fri Nov 22, 2019 10:39 pm
by Palonso
I'm trying to create a library so I can clean my main code, making it shorter and easier to read.

What i've done so far is creating a folder called "components" which inside has a folder representative of what it does, inside that folder there are two folders called "source" and "include" and inside each there are thing1.c and thing1.h respectively.

in resume:
project
├── CMakeLists.txt
├── components
│   ├── lib_for_something
│   │   ├── CMakeLists.txt
│   │   ├── component.mk
│   │   ├── include
│   │   │   └── thing1.h
│   │   └── source
│   │   └── thing1.c
│   └── lib_for_another
│   ├── CMakeLists.txt
│   ├── component.mk
│   ├── include
│   │   └── thing2.h
│   └── source
│   └── thing2.c
├── main
│   ├── CMakeLists.txt
│   ├── component.mk
│   └── main.c
├── Makefile
├── sdkconfig
└── sdkconfig.old

My problem is that when i want to build that i hace the next output:

Code: Select all

Generating esp32.project.ld
LD build/main.elf
/home/$USER/.espressif/tools/xtensa-esp32-elf/esp32-2019r1-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32
-elf/bin/ld: /home/$USER/project/build/main/libmain.a(main.o):(.literal.app_main+0x48): undefined reference to `function1'
/home/$USER/.espressif/tools/xtensa-esp32-elf/esp32-2019r1-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32
-elf/bin/ld: /home/$USER/project/build/main/libmain.a(main.o): in function `app_main':
/home/$USER/project/main/main.c:47: undefined reference to `function1'
collect2: error: ld returned 1 exit status

/home/$USER/esp/esp-idf/make/project.mk:543: recipe for target '/home/$USER/project/build/main.elf' failed
make: *** [/home/$USER/project/build/main.elf] Error 1
Does someone know what's happening?

Thanks

Re: Adding your own library to your program.

Posted: Mon Nov 25, 2019 5:06 pm
by Palonso
UPDATE:

inside the library folders there's a "component.mk" file. I found that inside it says:

Code: Select all

COMPONENT_ADD_INCLUDEDIRS := include

COMPONENT_SRCDIRS := src
and I changed the SRCDIRS for "source" (the actual name of the folder) and my program worked.

The file now says:

Code: Select all

COMPONENT_ADD_INCLUDEDIRS := include

COMPONENT_SRCDIRS := source