Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By jcmvbkbc
#6638
mog wrote:
Code: Select all/opt/Espressif/ESP8266_SDK/lib/libmain.a(app_main.o): In function `read_macaddr_from_otp':
(.irom0.text+0x7c): undefined reference to `wDev_ProcessFiq'
/opt/Espressif/ESP8266_SDK/lib/libmain.a(app_main.o): In function `read_macaddr_from_otp':
(.irom0.text+0x84): undefined reference to `lmacInit'

Which seem like a quite critical functions. Do you know if I should look for a different libmain or just try to figure out what other libraries I need to link?

Add pp to the list of LIBS. I've updated that Makefile gist with it.
User avatar
By mog
#6693 Thank you @jcmvbkbc

What is pp library? After adding it the linke complains that upgrade_ssl is missing and after commenting it out from LIBS in Makefile linker fails bacause of missing reference to user_init from wdt_init
Code: Select allmkdir -p build/driver
mkdir -p build/user
mkdir -p firmware
/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++ -Idriver -Iuser -Idriver/include -Iuser/include -Iinclude -I/opt/Espressif/include/ -I/opt/Espressif/ESP8266_SDK/include -I/opt/Espressif/ESP8266_SDK/include/json -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals  -D__ets__ -DICACHE_FLASH -fno-rtti -fno-exceptions  -c user/user_main.cpp -o build/user/user_main.o
/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/xtensa-lx106-elf-ar cru build/app_app.a build/user/user_main.o
/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -L/opt/Espressif/ESP8266_SDK/lib -T/opt/Espressif/ESP8266_SDK/ld/eagle.app.v6.ld -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -Wl,--start-group -lc -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lupgrade -lmain -lpp build/app_app.a -Wl,--end-group -o build/app.out
/opt/Espressif/ESP8266_SDK/lib/libmain.a(app_main.o): In function `wdt_init':
(.irom0.text+0x374): undefined reference to `user_init'
/opt/Espressif/ESP8266_SDK/lib/libmain.a(app_main.o): In function `wdt_init':
(.irom0.text+0x4cf): undefined reference to `user_init'
collect2: error: ld returned 1 exit status
make: *** [build/app.out] Error 1


Why could that be? I've got super simple source file which looks like this:

Code: Select all#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "user_config.h"
//#include <iostream>
#include <vector>

void ICACHE_FLASH_ATTR
user_init()
{
//    os_printf("user_init()\r\n");
    std::vector < int > vec;
    int x = 0;
    for( int i = 0; i < 10; i++ ){
        vec.push_back( x );
        x = x ;
    }
    for( int i = 0; i < vec.size(); i++ ){
        //os::printf(vec[i]);
        //std::cout << vec[ i ] << std::endl;
    }
}


Also if I uncomment the os_printf function call which I've used previously compiler throws the error which points to a valid user_init reference. Do you know why could these be an issue?

Code: Select allmkdir -p build/driver
mkdir -p build/user
mkdir -p firmware
/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++ -Idriver -Iuser -Idriver/include -Iuser/include -Iinclude -I/opt/Espressif/include/ -I/opt/Espressif/ESP8266_SDK/include -I/opt/Espressif/ESP8266_SDK/include/json -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals  -D__ets__ -DICACHE_FLASH -fno-rtti -fno-exceptions  -c user/user_main.cpp -o build/user/user_main.o
user/user_main.cpp: In function 'void user_init()':
user/user_main.cpp:12:32: error: 'os_printf' was not declared in this scope
     os_printf("user_init()\r\n");
                                ^
make: *** [build/user/user_main.o] Error 1
User avatar
By igrr
#6712 Looks like your user_init is defined in a cpp file. It has to be declared as extern "C", because it is referenced from libraries which expect it to be a C function.

Code: Select allextern "C" void user_init(){ ... }


Also all the SDK headers have to be put into extern "C" block:

Code: Select allextern "C" {
#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "user_config.h"
}
User avatar
By mog
#6725 Thank you @igrr
After doing what you posted I've moved forward but then I've bumped into what you posted before:
Code: Select allWhen you succeed with that part you may get a bunch of errors regarding missing _sbrk_r function. To fix those you will likely have to override new, new[], delete, and delete[] operators to use os_malloc & os_free provided in the Espressif SDK.


With the following compiler errors:
Code: Select all/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++ -Idriver -Iuser -Idriver/include -Iuser/include -Iinclude -I/opt/Espressif/include/ -I/opt/Espressif/ESP8266_SDK/include -I/opt/Espressif/ESP8266_SDK/include/json -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals  -D__ets__ -DICACHE_FLASH -fno-rtti -fno-exceptions  -c user/user_main.cpp -o build/user/user_main.o
/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/xtensa-lx106-elf-ar cru build/app_app.a build/user/user_main.o
/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc -L/opt/Espressif/ESP8266_SDK/lib -T/opt/Espressif/ESP8266_SDK/ld/eagle.app.v6.ld -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -Wl,--start-group -lc -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lupgrade -lmain -lpp build/app_app.a -Wl,--end-group -o build/app.out
build/app_app.a(user_main.o):(.text+0x0): undefined reference to `operator delete(void*)'
build/app_app.a(user_main.o): In function `user_init':
/home/user/Documents/dev/hardware/wifinoise/esp8266/tests/c_vector_test/user/user_main.cpp:19: undefined reference to `operator delete(void*)'
/home/user/Documents/dev/hardware/wifinoise/esp8266/tests/c_vector_test/user/user_main.cpp:23: undefined reference to `operator new(unsigned int)'
build/app_app.a(user_main.o): In function `operator-<int*, std::vector<int> >':
/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_iterator.h:898: undefined reference to `operator new(unsigned int)'
build/app_app.a(user_main.o): In function `__copy_m<int>':
/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algobase.h:371: undefined reference to `operator delete(void*)'
collect2: error: ld returned 1 exit status
make: *** [build/app.out] Error 1


I don't want to mess with new/delete operators while learning on working with SPI which is my initial goal. It seems like asking for trouble just from start :)