Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » ESP8266
ESP8266 [message #1769033] Wed, 26 July 2017 03:57 Go to next message
Thomas Thompson is currently offline Thomas ThompsonFriend
Messages: 1
Registered: July 2017
Junior Member
HI guys,

I have been using the Arduino IDE for esp8266 coding, but would like to move to a little more powerful environment. Eclipse seems to fit the bill.

However, on my first attempt to get a project working, I'm running into a lot of issues trying to get everything compiled and linked. I've chosen the hello_world_cpp example from the Espressif SDK. I've corrected a large number of issues I've run into, but can't seem to figure out how to get past this linking problem. Output is copied below after the main project code.

Can you guys give any pointers on where I might start looking on this problem? Also, let me know if there's further information that would be useful.

user_main.cpp:
/*
	The hello world c++ demo
*/

#include <ets_sys.h>
#include <osapi.h>
#include <os_type.h>
#include <gpio.h>

#define DELAY 1000 /* milliseconds */

// =============================================================================================
// C includes and declarations
// =============================================================================================
extern "C"
{
#include "driver/uart.h"
#include <user_interface.h>

void *pvPortMalloc( size_t xWantedSize );
void vPortFree( void *pv );
void *pvPortZalloc(size_t size);

// declare lib methods
extern int ets_uart_printf(const char *fmt, ...);
void ets_timer_disarm(ETSTimer *ptimer);
void ets_timer_setfn(ETSTimer *ptimer, ETSTimerFunc *pfunction, void *parg);
void ets_timer_arm_new(ETSTimer *ptimer,uint32_t milliseconds, bool repeat_flag, bool);

#define os_malloc   pvPortMalloc
#define os_free     vPortFree
#define os_zalloc   pvPortZalloc

}//extern "C"

// =============================================================================================
// These methods shall be defined anywhere.
// They are required for C++ compiler
// =============================================================================================
void *operator new(size_t size)
{
   return os_malloc(size);
}

void *operator new[](size_t size)
{
   return os_malloc(size);
}

void operator delete(void * ptr)
{
   os_free(ptr);
}

void operator delete[](void * ptr)
{
   os_free(ptr);
}

extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
extern "C" void abort()
{
   while(true); // enter an infinite loop and get reset by the WDT
}

void __cxa_pure_virtual(void) {
  abort();
}

void __cxa_deleted_virtual(void) {
  abort();
}

// =============================================================================================
// Example class. It show that the global objects shall be initialyzed by user
// (see user_init method)
// =============================================================================================

class A
{
	int a;
	int b;

public:
	A()
	: a(5)
	, b(6)
	{
	}

	A( int k, int m )
	: a(k)
	, b(m)
	{
	}

	void print()
	{
		ets_uart_printf( "a = %d, b = %d\n", a, b );
	}
};

// =============================================================================================
// global objects
// =============================================================================================

LOCAL os_timer_t hello_timer;
A a;


// =============================================================================================
// Pointers to the constructors of the global objects
// (defined in the linker script eagle.app.v6.ld)
// =============================================================================================

extern void (*__init_array_start)(void);
extern void (*__init_array_end)(void);

// Initialyzer of the global objects
static void do_global_ctors(void)
{
    void (**p)(void);
    for (p = &__init_array_start; p != &__init_array_end; ++p)
            (*p)();
}

// =============================================================================================
// User code
// =============================================================================================

LOCAL void ICACHE_FLASH_ATTR hello_cb(void *arg)
{
	static int counter = 0;
	ets_uart_printf("Hello World #%d!\r\n", counter++);
	a.print();
}


/******************************************************************************
 * FunctionName : user_rf_cal_sector_set
 * Description  : SDK just reversed 4 sectors, used for rf init data and paramters.
 *                We add this function to force users to set rf cal sector, since
 *                we don't know which sector is free in user's application.
 *                sector map for last several sectors : ABBBCDDD
 *                A : rf cal
 *                B : at parameters
 *                C : rf init data
 *                D : sdk parameters
 * Parameters   : none
 * Returns      : rf cal sector
*******************************************************************************/
extern "C" uint32 ICACHE_FLASH_ATTR user_rf_cal_sector_set(void)
{
    enum flash_size_map size_map = system_get_flash_size_map();
    uint32 rf_cal_sec = 0;

    switch (size_map) {
        case FLASH_SIZE_4M_MAP_256_256:
            rf_cal_sec = 128 - 8;
            break;

        case FLASH_SIZE_8M_MAP_512_512:
            rf_cal_sec = 256 - 5;
            break;

        case FLASH_SIZE_16M_MAP_512_512:
        case FLASH_SIZE_16M_MAP_1024_1024:
            rf_cal_sec = 512 - 5;
            break;

        case FLASH_SIZE_32M_MAP_512_512:
        case FLASH_SIZE_32M_MAP_1024_1024:
            rf_cal_sec = 1024 - 5;
            break;

        default:
            rf_cal_sec = 0;
            break;
    }

    return rf_cal_sec;
}

extern "C" void ICACHE_FLASH_ATTR user_rf_pre_init(void)
{
}

extern "C" void ICACHE_FLASH_ATTR user_init(void)
{
	do_global_ctors();
	// Configure the UART
	uart_init(BIT_RATE_115200, BIT_RATE_115200);
	ets_uart_printf("System init...\r\n");

	// Set up a timer to send the message
	// os_timer_disarm(ETSTimer *ptimer)
	os_timer_disarm(&hello_timer);
	// os_timer_setfn(ETSTimer *ptimer, ETSTimerFunc *pfunction, void *parg)
	os_timer_setfn(&hello_timer, (os_timer_func_t *)hello_cb, (void *)0);
	// void os_timer_arm(ETSTimer *ptimer,uint32_t milliseconds, bool repeat_flag)
	os_timer_arm(&hello_timer, DELAY, 1);

	ets_uart_printf("System init done.\r\n");
}


Build Output:
19:44:02 **** Rebuild of configuration Default for project hello_world_cpp ****
Info: Internal Builder is used for build
gcc -I../include "-IC:\\Espressif\\ESP8266_SDK\\include" -O2 -g -Wall -c -fmessage-length=0 -o "driver\\uart.o" "..\\driver\\uart.c" 
In file included from C:\Espressif\ESP8266_SDK\include/ets_sys.h:12:0,
                 from ..\driver\uart.c:12:
..\driver\uart.c: In function 'uart_config':
C:\Espressif\ESP8266_SDK\include/eagle_soc.h:250:38: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
                                      &  (~(PERIPHS_IO_MUX_FUNC<<PERIPHS_IO_MUX_FUNC_S))  \
                                      ^
C:\Espressif\ESP8266_SDK\include/eagle_soc.h:50:98: note: in definition of macro 'WRITE_PERI_REG'
 #define WRITE_PERI_REG(addr, val) (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val)
                                                                                                  ^~~
..\driver\uart.c:36:9: note: in expansion of macro 'PIN_FUNC_SELECT'
         PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
         ^~~~~~~~~~~~~~~
In file included from ..\driver\uart.c:12:0:
C:\Espressif\ESP8266_SDK\include/ets_sys.h:61:5: warning: implicit declaration of function 'ets_isr_attach' [-Wimplicit-function-declaration]
     ets_isr_attach(ETS_UART_INUM, (func), (void *)(arg))
     ^
..\driver\uart.c:39:9: note: in expansion of macro 'ETS_UART_INTR_ATTACH'
         ETS_UART_INTR_ATTACH(uart0_rx_intr_handler,  &(UartDev.rcv_buff));
         ^~~~~~~~~~~~~~~~~~~~
In file included from C:\Espressif\ESP8266_SDK\include/ets_sys.h:12:0,
                 from ..\driver\uart.c:12:
C:\Espressif\ESP8266_SDK\include/eagle_soc.h:250:38: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
                                      &  (~(PERIPHS_IO_MUX_FUNC<<PERIPHS_IO_MUX_FUNC_S))  \
                                      ^
C:\Espressif\ESP8266_SDK\include/eagle_soc.h:50:98: note: in definition of macro 'WRITE_PERI_REG'
 #define WRITE_PERI_REG(addr, val) (*((volatile uint32_t *)ETS_UNCACHED_ADDR(addr))) = (uint32_t)(val)
                                                                                                  ^~~
..\driver\uart.c:41:9: note: in expansion of macro 'PIN_FUNC_SELECT'
         PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD);
         ^~~~~~~~~~~~~~~
..\driver\uart.c:44:5: warning: implicit declaration of function 'uart_div_modify' [-Wimplicit-function-declaration]
     uart_div_modify(uart_no, UART_CLK_FREQ / (UartDev.baut_rate));
     ^~~~~~~~~~~~~~~
..\driver\uart.c: In function 'uart0_tx_buffer':
..\driver\uart.c:163:9: warning: implicit declaration of function 'uart_tx_one_char' [-Wimplicit-function-declaration]
         uart_tx_one_char(buf[i]);
         ^~~~~~~~~~~~~~~~
In file included from ..\driver\uart.c:12:0:
..\driver\uart.c: In function 'uart_init':
C:\Espressif\ESP8266_SDK\include/ets_sys.h:67:5: warning: implicit declaration of function 'ets_isr_unmask' [-Wimplicit-function-declaration]
     ets_isr_unmask((1<<inum))
     ^
C:\Espressif\ESP8266_SDK\include/ets_sys.h:76:5: note: in expansion of macro 'ETS_INTR_ENABLE'
     ETS_INTR_ENABLE(ETS_UART_INUM)
     ^~~~~~~~~~~~~~~
..\driver\uart.c:182:5: note: in expansion of macro 'ETS_UART_INTR_ENABLE'
     ETS_UART_INTR_ENABLE();
     ^~~~~~~~~~~~~~~~~~~~
In file included from ..\driver\uart.c:13:0:
C:\Espressif\ESP8266_SDK\include/osapi.h:13:26: warning: implicit declaration of function 'ets_install_putc1' [-Wimplicit-function-declaration]
 #define os_install_putc1 ets_install_putc1
                          ^
..\driver\uart.c:185:5: note: in expansion of macro 'os_install_putc1'
     os_install_putc1((void *)uart1_write_char);
     ^~~~~~~~~~~~~~~~
g++ "-IC:\\Espressif\\ESP8266_SDK\\include\\" -I../include -O2 -g -Wall -c -fmessage-length=0 -o "user\\user_main.o" "..\\user\\user_main.cpp" 
g++ -Lc:/MinGW/msys/1.0/lib "-LF:\\Espressif\\lib" -o hello_world_cpp "driver\\uart.o" "user\\user_main.o" 
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: skipping incompatible F:\Espressif\lib/libgcc.a when searching for -lgcc
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: skipping incompatible F:\Espressif\lib\libgcc.a when searching for -lgcc
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: skipping incompatible F:\Espressif\lib/libgcc.a when searching for -lgcc
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: skipping incompatible F:\Espressif\lib\libgcc.a when searching for -lgcc
driver\uart.o: In function `uart_config':
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../driver/uart.c:39: undefined reference to `UartDev'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../driver/uart.c:39: undefined reference to `ets_isr_attach'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../driver/uart.c:44: undefined reference to `UartDev'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../driver/uart.c:44: undefined reference to `uart_div_modify'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../driver/uart.c:46: undefined reference to `UartDev'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../driver/uart.c:46: undefined reference to `UartDev'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../driver/uart.c:46: undefined reference to `UartDev'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../driver/uart.c:46: undefined reference to `UartDev'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../driver/uart.c:57: undefined reference to `UartDev'
driver\uart.o: In function `uart0_tx_buffer':
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../driver/uart.c:163: undefined reference to `uart_tx_one_char'
driver\uart.o: In function `uart_init':
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../driver/uart.c:178: undefined reference to `UartDev'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../driver/uart.c:180: undefined reference to `UartDev'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../driver/uart.c:182: undefined reference to `ets_isr_unmask'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../driver/uart.c:185: undefined reference to `ets_install_putc1'
user\user_main.o: In function `hello_cb':
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../user/user_main.cpp:135: undefined reference to `ets_uart_printf'
user\user_main.o: In function `ZN1A5printEv':
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../user/user_main.cpp:100: undefined reference to `ets_uart_printf'
user\user_main.o: In function `user_rf_cal_sector_set':
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../user/user_main.cpp:155: undefined reference to `system_get_flash_size_map'
user\user_main.o: In function `do_global_ctors':
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../user/user_main.cpp:124: undefined reference to `__init_array_start'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../user/user_main.cpp:124: undefined reference to `__init_array_end'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../user/user_main.cpp:124: undefined reference to `__init_array_end'
user\user_main.o: In function `user_init':
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../user/user_main.cpp:194: undefined reference to `ets_uart_printf'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../user/user_main.cpp:198: undefined reference to `ets_timer_disarm'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../user/user_main.cpp:200: undefined reference to `ets_timer_setfn'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../user/user_main.cpp:202: undefined reference to `ets_timer_arm_new'
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../user/user_main.cpp:204: undefined reference to `ets_uart_printf'
user\user_main.o:C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../user/user_main.cpp:137: undefined reference to `pvPortMalloc'
user\user_main.o: In function `Znaj':
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../user/user_main.cpp:47: undefined reference to `pvPortMalloc'
user\user_main.o:C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../user/user_main.cpp:47: undefined reference to `vPortFree'
user\user_main.o: In function `ZdaPv':
C:\Espressif\examples\ESP8266\hello_world_cpp\Default/../user/user_main.cpp:57: undefined reference to `vPortFree'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status

19:44:03 Build Finished (took 890ms)

Re: ESP8266 [message #1769151 is a reply to message #1769033] Thu, 27 July 2017 07:06 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
You're attempting to compile C++ with a plain C compiler. Try g++ instead of gcc.

--

Tauno Voipio
Re: ESP8266 [message #1769169 is a reply to message #1769151] Thu, 27 July 2017 08:52 Go to previous message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 416
Registered: June 2014
Senior Member
This is the same question asked on https://stackoverflow.com/a/45321756/2796832

I share my same answer:

It appears CDT is running gcc for host development as opposed to the gcc cross-compiler needed for generating code for your Arduino board.

Are you using "vanilla" CDT, or have you using Arduino plug-ins for Eclipse.

Two to consider:

http://eclipse.baeyens.it/
https://marketplace.eclipse.org/content/eclipse-c-ide-arduino
Previous Topic:Running C++ sample "hello world".
Next Topic:Debug my own class - How to display a variable/function value
Goto Forum:
  


Current Time: Fri Apr 26 11:25:25 GMT 2024

Powered by FUDForum. Page generated in 2.20065 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top