C++-11

188 views
Skip to first unread message

paolo achdjian

unread,
Dec 29, 2015, 12:52:21 PM12/29/15
to esp-open-rtos mailing list
Hi,
I started few days ago use esp2866 and then esp-open-rtos. 
I like C++ so I prefer use this instead of simple C, but it seems to me that there is some problem using the standard library (when I use std::string and std::ostream the linker reports me some undefined symbols and/or some weird warning about wrong relocation).
Anyway, I haven't to do a large program, so this limits can be easy bypassed.
Instead, one thing that interests to me is using the version 11 of c++, because it seems to me that it offers a lot of vantages about embedded system.

To enable the c++ 11 version,  it enough use the flag -std=c++11 but the problem is that the only way I be able to use it without problem it is modify the common.mk file as:

CXXFLAGS = $(C_CXX_FLAGS) -fno-exceptions -fno-rtti -std=c++11

because adding this flag any other variable in the project Makefile produce error when compiling simple C file.
So, I would be glad if will be added a variable only for C++, in order to be possible choice the C++ version.

Furthermore, I noticed that to use the c++11,  there is a little change to performe  in the ip_addr.h file of lwip library: it is need to add some space in the definition of ip_addr_debug_print in order to allowing the compiler to well understand the syntax .

Regards,
Paolo



Angus Gratton

unread,
Dec 29, 2015, 9:08:47 PM12/29/15
to paolo achdjian, esp-open-rtos mailing list
Hi Paolo,

Welcome to esp-open-rtos! Hopefully you find it useful for your purposes. :)

On Tue, Dec 29, 2015 at 09:52:21AM -0800, paolo achdjian wrote:
> Hi,
> I started few days ago use esp2866 and then esp-open-rtos.
> I like C++ so I prefer use this instead of simple C, but it seems to me
> that there is some problem using the standard library (when I use
> std::string and std::ostream the linker reports me some undefined symbols
> and/or some weird warning about wrong relocation).
> Anyway, I haven't to do a large program, so this limits can be easy
> bypassed.
> Instead, one thing that interests to me is using the version 11 of c++,
> because it seems to me that it offers a lot of vantages about embedded
> system.
>
> To enable the c++ 11 version, it enough use the flag -std=c++11 but the
> problem is that the only way I be able to use it without problem it is
> modify the common.mk file as:
>
> CXXFLAGS = $(C_CXX_FLAGS) -fno-exceptions -fno-rtti* -std=c++11*
>
> because adding this flag any other variable in the project Makefile produce
> error when compiling simple C file.
> So, I would be glad if will be added a variable only for C++, in order to
> be possible choice the C++ version.

There is a way to do this with the current Makefile, if you only want C++11 for your program files:

program_CXXFLAGS = $(CXXFLAGS) -std=c++11

... this way any C++ files compiled in the rest of the framework will use the default C++ standard, and only your program files are compiled as C++11. Which may be what you want.

However I also just pushed a commit that adds EXTRA_CXXFLAGS, EXTRA_CFLAGS, and also makes the top-level CFLAGS/etc overridable. So it's up to you which one to use, I guess.

> Furthermore, I noticed that to use the c++11, there is a little change to
> performe in the ip_addr.h file of lwip library: it is need to add some
> space in the definition of ip_addr_debug_print in order to allowing the
> compiler to well understand the syntax .

OK. Can you please send a pull request to https://github.com/SuperHouse/esp-lwip with whatever changes are required in order to compile with C++11? I'll merge it and update the submodule.


Angus

paolo achdjian

unread,
Dec 30, 2015, 1:50:08 AM12/30/15
to Angus Gratton, esp-open-rtos mailing list
Hi Angus, 
thank you for your ready answer

I try to do as you written but I have a weird behavior:

given that in my makefile I have the line
PROGRAM=esp-oven
I expected to add the line

esp-oven_CXXFLAGS = -std=c++11

Instead I have to add the line

PROGRAM_CXXFLAGS = -std=c++11.

and really putting as debug line into the common.mk file, (where it execute the g++ command, line 265) as 
echo $(1)
$(1) result set as PROGRAM.

I try also using a example program and the result is the same: $(1) is set to PROGRAM.

Regards,
Paolo



paolo achdjian

unread,
Dec 30, 2015, 2:12:24 AM12/30/15
to Angus Gratton, esp-open-rtos mailing list
Hi,
I notice that if I limit the flag  -std=c++11 only to my file, there is some problem at linking time (a lot of weird message about undefined reference to some lib and relocation error). I think because in rtos core there is a c++ file (cpluplus_operators.cpp) the it is compile without flags. But I don't know how to fix this without modify the common.mk file

Regards,
Paolo

Angus Gratton

unread,
Dec 30, 2015, 3:18:06 AM12/30/15
to paolo achdjian, esp-open-rtos mailing list
On Wed, Dec 30, 2015 at 07:50:08AM +0100, paolo achdjian wrote:
> and really putting as debug line into the common.mk file, (where it execute
> the g++ command, line 265) as
> echo $(1)
> $(1) result set as PROGRAM.
>
> I try also using a example program and the result is the same: $(1) is set
> to PROGRAM.
>

Hi Paolo,

This is intentional, even though I know that it's weird. In the esp-open-rtos Makefile system the various "library" components of the system all have names (like lwip, etc.) And then there's one "dummy" component called PROGRAM, which is your program (even though it has a different name set in the PROGRAM variable).

So PROGRAM_CXXFLAGS is exactly what you should be setting. Sorry I mis-capitalised it when I replied earlier.

I guess we could change it to $(PROGRAM), that might be more intuitive to use the name that was set to the variable. Really what we want to do eventually is split the Makefile process so that building the "library" and building the "program" are separate - there's an issue discussing that plan here - https://github.com/SuperHouse/esp-open-rtos/issues/28

There's also a full explanation of how the "components" system works on the wiki:
https://github.com/SuperHouse/esp-open-rtos/wiki/Build-Process#source-components

... please let me know if there's anything I can explain better.


Angus

paolo achdjian

unread,
Dec 30, 2015, 3:24:45 AM12/30/15
to Angus Gratton, esp-open-rtos mailing list
Hi Angus,

now it is more clear. 
I misunderstood because PROGRAM is also the variable that contains the name of the program so it seems as it is need to perform a variable substitution.

Thank a lot for your explanation.

Paolo

Narasing Sarwade

unread,
Oct 21, 2016, 6:39:37 AM10/21/16
to esp-open-rtos mailing list
Hi Paolo,
I'm new to esp-open-rtos and also i want to use c++ instead of c.
So if you have any ESP-OPEN-RTOS based c++ example with you then please mail it to me i will refer it and start some implementation.
Thanks.

paolo achdjian

unread,
Oct 21, 2016, 6:52:02 AM10/21/16
to Narasing Sarwade, esp-open-rtos mailing list
Hi Narasing,

it's a lot of time I used ESP-OPEN-RTOS.
I used it to make a oven controller and put it on gihub

https://github.com/paoloach/ESP-oven

Anyway, if you need some help I will be glad to help you, if I can.

Regards,
Paolo



--
You received this message because you are subscribed to a topic in the Google Groups "esp-open-rtos mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/esp-open-rtos/NtUbeOjDL9E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to esp-open-rtos+unsubscribe@googlegroups.com.
To post to this group, send email to esp-op...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/esp-open-rtos/58256e64-1725-4553-9411-536269640e64%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Malachi Burke

unread,
Jan 3, 2017, 5:53:22 PM1/3/17
to esp-open-rtos mailing list
Thanks for this guys, C++ is important to me as well.  Paolo, are you able to get C++ compiling and linking with std::string without touching common.mk now?

Fernando Governatore

unread,
Aug 9, 2017, 10:04:03 PM8/9/17
to esp-open-rtos mailing list
I've used:

EXTRA_CXXFLAGS=-std=c++11

Reply all
Reply to author
Forward
0 new messages