Changing C++ Libraries

168 views
Skip to first unread message

Brent Gibson

unread,
Jun 10, 2020, 9:55:12 PM6/10/20
to NuttX
Hi all,

I'm a CS major who just started a summer internship. I'm tasked with installing NuttX on a Nucleo-64 board and then executing some basic C++ programs through the NuttShell. I've never used Linux or NuttX before this week so I've been reading a lot of tutorials and watching a lot of YouTube videos.

I'm at the point where I can create a nuttx.bin file and write it to my board, but I run into issues anytime I try to compile bin file with any sort of C++ functionality. If I select C++ initialization in the config menu, I'll get pages of error messages that all start with the compiler trying to include header files from /usr/include/newlib/c++/...

I know we're not supposed to try to build NuttX against the newlib libraries, but I don't know how to change this.

Can someone explain to me how to tell NuttX to build against its own libraries instead of the newlib libraries?

This might be an absolute newbie questions, but I am an absolute newbie...

Thanks in advance.

Adam Feuer

unread,
Jun 10, 2020, 11:04:56 PM6/10/20
to nuttx
Brent,

Have you looked at the hellocxx example in nuttx-apps?


I think this is a very basic C++ program. It might help.

cheers
adam

--
You received this message because you are subscribed to the Google Groups "NuttX" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nuttx+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nuttx/14a54afc-8279-4a6c-bd6a-b5992ada3037o%40googlegroups.com.


--
Adam Feuer <ad...@starcat.io>

patacongo

unread,
Jun 10, 2020, 11:12:31 PM6/10/20
to NuttX

Brent Gibson

unread,
Jun 11, 2020, 4:09:04 PM6/11/20
to NuttX
Thanks for the response!

I already installed uClibc++ in the NuttX source tree and the installation was successful. However, when I choose a C++ option in the menuconfig, I get error messages when I try to compile.

For example, if I go into Application Configuration -> Testing -> [*] C++ test program,
when I try to compile I get the following types of errors:

In file included from /usr/include/newlib/c++/9.2.1/string:55,
                 from /usr/include/newlib/c++/9.2.1/bits/locale_classes.h:40,
                 from /usr/include/newlib/c++/9.2.1/bits/ios_base.h:41,
                 from /usr/include/newlib/c++/9.2.1/ios:42,
                 from /usr/include/newlib/c++/9.2.1/istream:38,
                 from /usr/include/newlib/c++/9.2.1/fstream:38,
                 from cxxtest_main.cxx:43:
/usr/include/newlib/c++/9.2.1/bits/basic_string.h: In function 'int std::__cxx11::stoi(const wstring&, std::size_t*, int)':
/usr/include/newlib/c++/9.2.1/bits/basic_string.h:6610:47: error: 'wcstol' is not a member of 'std'; did you mean 'wcstol'?
 6610 |   { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
      |                                               ^~~~~~

So my compiler is including header files from the wrong library and I don't know how to make it build against a different library.

I hope that all made sense.

Gregory Nutt

unread,
Jun 11, 2020, 4:37:11 PM6/11/20
to nu...@googlegroups.com

> For example, if I go into Application Configuration -> Testing -> [*]
> C++ test program,
> when I try to compile I get the following types of errors:
>
> ...
>                  from /usr/include/newlib/c++/9.2.1/fstream:38,
>                  from cxxtest_main.cxx:43:
> /usr/include/newlib/c++/9.2.1/bits/basic_string.h: In function 'int
> std::__cxx11::stoi(const wstring&, std::size_t*, int)':
> /usr/include/newlib/c++/9.2.1/bits/basic_string.h:6610:47: error:
> 'wcstol' is not a member of 'std'; did you mean 'wcstol'?
>  6610 |   { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi",
> __str.c_str(),
>       |                                               ^~~~~~
>
> So my compiler is including header files from the wrong library and I
> don't know how to make it build against a different library.

fstream should be provided uClibc++.  It should get installed per the
instructions in the README.txt file of the uClib++ repository.

So there are only two likely possibilities:

1. The fstream file was not properly installed.  Try `find include -name
fstream` to see if it was installed and where it was installed.

2. There is a problem with the include patch provided to GCC. Build
again with 'make V=1'  The compilation of cxxtest_main.cxx should fail
in the same way but you you can see the GCC command line and the include
path options provided to GCC.

Is the include path where fstream resides properly provided to GCC?




Brent Gibson

unread,
Jun 12, 2020, 4:51:56 PM6/12/20
to NuttX
I think you're on the right track.

I when I search for fstream, the results show that file in two locations:
/home/brent/nuttxspace/nuttx/include/uClibc++/fstream
and
/home/brent/nuttxspace/nuttx/include/libcxx/fstream

When I check the include libraries that gcc searches with 'gcc -print-search-dirs' I get a list of directories that all start with /usr/lib/gcc/x86_64-linux-gnu/9/ or just /lib/et seq. (which is a symbolic link to /usr/lib).

So fstream is on my system, but it's not in a directory that my compiler checks. Is there a way to tell my compiler to look in that directory?

Also, when I tried using 'make V=1' it seemed to execute a bash script called .version. It didn't give me any more insight into gcc's include libraries. I think gcc -print-search-dirs accomplished what I needed though.

Thanks for taking the time to help me work this out! You're a life saver.

Gregory Nutt

unread,
Jun 12, 2020, 4:53:36 PM6/12/20
to nu...@googlegroups.com

> I when I search for fstream, the results show that file in two locations:
> /home/brent/nuttxspace/nuttx/include/uClibc++/fstream
> and
> /home/brent/nuttxspace/nuttx/include/libcxx/fstream

You have both uClibc++ and libcxx installed?  Perhaps that is an issue.


patacongo

unread,
Jun 13, 2020, 10:08:32 AM6/13/20
to NuttX


Also, when I tried using 'make V=1' it seemed to execute a bash script called .version. It didn't give me any more insight into gcc's include libraries. I think gcc -print-search-dirs accomplished what I needed though.

Thanks for taking the time to help me work this out! You're a life saver.

You are probably missing the include paths in your board Make.defs file.  Take at look at these:

$ find boards -name Make.defs | xargs grep libcxx
boards/arm/imxrt/imxrt1050-evk/configs/libcxxtest/Make.defs:# boards/arm/imxrt/imxrt1050-evk/configs/libcxxtest/Make.defs
boards/arm/imxrt/imxrt1060-evk/configs/libcxxtest/Make.defs:# imxrt1060-evk/configs/libcxxtest/Make.defs
boards/arm/lpc43xx/bambino-200e/scripts/Make.defs:LIBCXXINCPATH := ${shell $(INCDIR) -s "$(CC)" $(TOPDIR)$(DELIM)include$(DELIM)libcxx}
boards/arm/sam34/arduino-due/scripts/Make.defs:LIBCXXINCPATH := ${shell $(INCDIR) -s "$(CC)" $(TOPDIR)$(DELIM)include$(DELIM)libcxx}
boards/arm/sam34/sam3u-ek/scripts/Make.defs:LIBCXXINCPATH := ${shell $(INCDIR) -s "$(CC)" $(TOPDIR)$(DELIM)include$(DELIM)libcxx}
boards/arm/stm32/stm32f4discovery/configs/testlibcxx/Make.defs:# boards/arm/stm32/stm32f4discovery/configs/testlibcxx/Make.defs
boards/arm/stm32/stm32f4discovery/configs/testlibcxx/Make.defs:LIBCXXINCPATH := ${shell $(INCDIR) -s "$(CC)" $(TOPDIR)$(DELIM)include$(DELIM)libcxx}
boards/arm/stm32l4/nucleo-l476rg/scripts/Make.defs:LIBCXXINCPATH := ${shell $(INCDIR) -s "$(CC)" $(TOPDIR)$(DELIM)include$(DELIM)libcxx}
boards/arm/stm32l4/nucleo-l476rg/scripts/Make.defs:  # supc++ is always needed with libcxx





patacongo

unread,
Jun 13, 2020, 10:12:36 AM6/13/20
to NuttX
Those are for libc++, for uClibc++:

$ find boards -name Make.defs | xargs grep uClibc++
boards/arm/stm32/stm32f4discovery/configs/cxxtest/Make.defs:UCLIBCINCPATH := ${shell $(INCDIR) -s "$(CC)" $(TOPDIR)$(DELIM)include$(DELIM)uClibc++}
boards/sim/sim/sim/configs/cxxtest/Make.defs:ARCHINCLUDESXX += ${shell $(INCDIR) -s "$(CC)" $(TOPDIR)$(DELIM)include$(DELIM)uClibc++}

Reply all
Reply to author
Forward
0 new messages