Testing LLVM LIBC++ on NuttX

Clone NuttX:

$ git clone https://bitbucket.org/nuttx/nuttx

Clone NuttX’s Apps:

$ git clone https://bitbucket.org/nuttx/apps

Clone libc++ for NuttX:

$ git clone https://bitbucket.org/acassis/libcxx

Install the libc++ on NuttX:

cd libcxx
$ ./install.sh ../nuttx/
Installing LLVM/libcxx in the NuttX source tree
Installation suceeded

Modify the HelloXX example to use sstream:

$ cd ..
$ cd apps

Download 0001-Modify-helloxx-to-test-sstream.patch: https://gist.github.com/acassis/504e86d992a2fc459784c6284aa90e53

Apply it:

$ git am 0001-Modify-helloxx-to-test-sstream.patch

Add (l)gamma to NuttX and add helloxx example:

$ cd ..
$ cd nuttx

Download 0001-Add-gamma-and-lgamma.patch: https://gist.github.com/acassis/4fc95d3ecba3c4829eac303d5704dc76

Apply it:

$ git am 0001-Add-gamma-and-lgamma.patch

Download 0001-Add-helloxx-C-example-to-STM32F4Discovery.patch: https://gist.github.com/acassis/b17e90835eeffb58a35651a4e0d0503d

Apply it:

$ git am 0001-Add-helloxx-C-example-to-STM32F4Discovery.patch

Configure NuttX to use the helloxx example:

$ cd tools
$ ./configure.sh stm32f4discovery/helloxx

Compile it:

$ cd ..
$ make

Flash it:

$ sudo openocd -f interface/stlink-v2.cfg -f target/stm32f4x.cfg -c init -c "reset halt" -c "flash write_image erase nuttx.bin 0x08000000"

Restart NuttX, you should see:

Hello World! 42                                                              
helloxx_main: Saying hello from the dynamically constructed instance         
CHelloWorld::HelloWorld: Hello, World!!                                      
Hello World! 42                                                              
helloxx_main: Saying hello from the instance constructed on the stack        
CHelloWorld::HelloWorld: Hello, World!! 
helloxx_main: Saying hello from the statically constructed instance
CHelloWorld::HelloWorld: Hello, World!! 

2 thoughts on “Testing LLVM LIBC++ on NuttX

  1. Hi Alan, I’m currently trying to use C++ standard library.
    (I’d like to use something like std::cout, std::vector and so on.)
    Is this article still work? I tried to follow these steps but I couldn’t apply these patches to my environment.

    One more question,
    I installed toolchain “gcc-arm-none-eabi” following NuttX Getting Started pages.
    So I wonder why we have to install LLVM libc++ or uClibc++.
    I guess gcc-arm-none-eabi has standard c++ library…

    /***** My Environment *****/
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=20.04
    DISTRIB_CODENAME=focal
    DISTRIB_DESCRIPTION=”Ubuntu 20.04.2 LTS”
    I built my development environment following NuttX Getting Started pages.
    I’m using Nucleo-F767ZI board.

    1. You don’t need to follow this process anymore because now NuttX support is included in the mainline of the LLVM libcxx. See: nuttx/boards/arm/stm32/stm32f4discovery/configs/testlibcxx/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s