-->
Page 1 of 1

How to compile c++ for xtensa?

PostPosted: Wed Apr 26, 2017 6:32 am
by invsin
Hello, i want compile simple c++ code for xtensa, but i can't.
Code: Select all#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "user_config.h"
#include "user_interface.h"
#include "espconn.h"

extern "C" void ICACHE_FLASH_ATTR
user_init()
{
    //wifi_set_opmode(i);
}


I compiled file with this command.
(This work)
Code: Select allxtensa-lx106-elf-g++ -I. -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 -o bin/user_main.o user_main.cpp

And linked with this.
Code: Select all 
xtensa-lx106-elf-gcc -L /home/esp-open-sdk/sdk/lib -T /home/esp-open-sdk/sdk/ld/eagle.app.v6.ld -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -Wl,--start-group -lgcc -lmain -lnet80211 -lwpa -llwip -lpp -lphy -lc -lupgrade -Wl,--end-group  bin/user_main.o -o bin/user_main


If any function from SDK is used in file, linking end with undefined reference errors
Code: Select allbin/user_main.o:(.irom0.text+0x0): undefined reference to `wifi_set_opmode(unsigned char)'
bin/user_main.o: In function `user_init':
/home/esp/user_main.cpp:12: undefined reference to `wifi_set_opmode(unsigned char)'
collect2: error: ld returned 1 exit status


Anybody can show minimal commands to compile and link c++ for Xtensa?
Thanks in advance!

Re: How to compile c++ for xtensa?

PostPosted: Wed Apr 26, 2017 10:28 am
by martinayotte
All SDK includes are for plain C.
So if you include any of those in a C++ file, it need to be included using extern "C" { ... }.
Otherwise, the linker will search for C++ functions, but they are not existing.