You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Flavio Castro Alves Filho <fl...@gmail.com> on 2021/03/15 10:00:03 UTC

Using C++ STL in Nuttx

Hello,

I am trying to use STL in a simple C++ Hello project and I am getting
compilation error.s

Is STL supported in NuttX? Can I use it?

Here is my sample code:

=== Hello.cpp ===
#include <stdio.h>
#include "HelloWorld.h"

CHelloWorld::CHelloWorld() {
    mSecret = 42;
    printf("Constructor: mSecret=%d\n",mSecret);
}

CHelloWorld::~CHelloWorld() {

}

bool CHelloWorld::HelloWorld(void) {
    printf("HelloWorld: mSecret=%d\n",mSecret);

    if (mSecret == 42) {
        printf("CHelloWorld: HelloWorld: Hello, world!");
        return true;
    }
    else {
        printf("CHelloWorld: HelloWorld: CONSTRUCTION FAILED!\n");
        return false;
    }
}
=========

=== Hello.h ===
class CHelloWorld
{
    public:
        CHelloWorld();
        ~CHelloWorld();
        bool HelloWorld(void);
    private:
        int mSecret;
};
=========

=== Log.cpp ===
#include "Log.h"
#include <stdio.h>
#include <string>

void Log::print(std::string_view message) {

    FILE *fp = fopen("/dev/ttyS0", "w");
    if (fp == NULL) {
        printf("Error opening serial port!\n");
        return;
    }

    std::string msgStr { message };

    /* Try to force input data on stdin */
    fwrite(msgStr.c_str(), sizeof(char), message.length(), fp);

    fclose(fp);
}
=========

=== Log.h ===
#include <string_view>

class Log {
public:
    static void print(std::string_view message);
};
=========

And there the compilation error:
=========
-- Build files have been written to: /home/ubuntu/nuttx-apps/hellocpp/build
[4/4] Linking CXX executable src/hellocpp
FAILED: src/hellocpp
: && arm-none-eabi-ld --entry=__start -nostartfiles -nostdlib
-nodefaultlibs -T/home/ubuntu/nuttx-apps/hellocpp/nuttx-export-9.1.0/scripts/ld.script
-o hellocpp.elf src/CMakeFiles/hellocpp.dir/HelloWorld.cpp.o
src/CMakeFiles/hellocpp.dir/Log.cpp.o
src/CMakeFiles/hellocpp.dir/main.cpp.o
-L/home/ubuntu/nuttx-apps/hellocpp/src/hellocpp
-L/home/ubuntu/nuttx-apps/hellocpp/nuttx-export-9.1.0/libs
--start-group  -lc  -larch  -lbinfmt  -lboard  -lboards  -ldrivers
-lfs  -lmm  -lsched  -lxx  -lnet  -lsupc++
/usr/lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/libgcc.a
--end-group && cd /home/ubuntu/nuttx-apps/hellocpp/build/src &&
arm-none-eabi-objcopy -S -O binary
/home/ubuntu/nuttx-apps/hellocpp/build/hellocpp.elf
/home/ubuntu/nuttx-apps/hellocpp/build/hellocpp.bin
arm-none-eabi-ld: src/CMakeFiles/hellocpp.dir/Log.cpp.o: in function
`void std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >::_M_construct<char const*>(char const*, char
const*, std::forward_iterator_tag)':
/usr/include/newlib/c++/9.2.1/bits/basic_string.tcc:212: undefined
reference to `std::__throw_logic_error(char const*)'
arm-none-eabi-ld:
/usr/include/newlib/c++/9.2.1/bits/basic_string.tcc:219: undefined
reference to `std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >::_M_create(unsigned int&, unsigned int)'
arm-none-eabi-ld:
/usr/include/newlib/c++/9.2.1/bits/basic_string.tcc:225: undefined
reference to `std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >::_S_copy_chars(char*, char const*, char
const*)'
arm-none-eabi-ld: src/CMakeFiles/hellocpp.dir/Log.cpp.o: in function
`std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >::~basic_string()':
/usr/include/newlib/c++/9.2.1/bits/basic_string.h:658: undefined
reference to `std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >::_M_dispose()'
arm-none-eabi-ld:
/usr/include/newlib/c++/9.2.1/bits/basic_string.h:658: undefined
reference to `std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >::_M_dispose()'
ninja: build stopped: subcommand failed.
make[1]: *** [Makefile:13: _build] Error 1
make[1]: Leaving directory '/home/ubuntu/nuttx-apps/hellocpp'
make: *** [Makefile:25: default] Error 2
=========

My CMakelists:

=== CMakeLists.txt ===
cmake_minimum_required(VERSION 3.2...3.15)

project(hellocpp
    VERSION 1.0
    DESCRIPTION "Hello world C++ Nuttx"
)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 99)

set(NUTTX_PATH "${CMAKE_SOURCE_DIR}/nuttx-export-9.1.0")

include(cmake/phigw.cmake)

set(AC_COMMON_FLAGS "${AC_COMMON_FLAGS} -fno-builtin -Wall -Wshadow -Wundef -g")

set(AC_DEFINES "${AC_DEFINES} -DCONFIG_WCHAR_BUILTIN")

include_directories(
    src
    ${NUTTX_PATH}/include
    ${NUTTX_PATH}/arch/chip
)

set(EXE_NAME hellocpp)

set(CMAKE_CXX_FLAGS "${AC_HW_FLAGS} ${AC_DEFINES} ${AC_COMMON_FLAGS}
${AC_CXX_EXTRA_FLAGS}")
if (PARAM_DEBUG)
    set(CMAKE_CXX_FLAGS     "${CMAKE_CXX_FLAGS} -Os -g")
else()
    set(CMAKE_CXX_FLAGS     "${CMAKE_CXX_FLAGS} -Os")
endif()

set(CMAKE_SKIP_RPATH ON)
set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_LINKER} ${AC_LINKER_FLAGS} -o
${EXE_NAME}.elf <OBJECTS> <LINK_LIBRARIES>")

set(BUILD_SHARED_LIBS OFF)

add_subdirectory(src)
=========

=== src/CMakelists.txt ===
set(HEADER_FILES
    HelloWorld.h
    Log.h
)

set(SOURCE_FILES
    HelloWorld.cpp
    Log.cpp
)

link_directories(${EXE_NAME} ${NUTTX_PATH}/libs)

add_executable(${EXE_NAME} ${SOURCE_FILES} main.cpp ${HEADER_FILES})

add_custom_command(
    TARGET ${EXE_NAME}
    POST_BUILD
    COMMAND ${CMAKE_OBJCOPY} ARGS -S -O binary
${CMAKE_BINARY_DIR}/${EXE_NAME}.elf
${CMAKE_BINARY_DIR}/${EXE_NAME}.bin
)

target_link_libraries(${EXE_NAME} --start-group)
target_link_libraries(${EXE_NAME} c)
target_link_libraries(${EXE_NAME} arch)
target_link_libraries(${EXE_NAME} binfmt)
target_link_libraries(${EXE_NAME} board)
target_link_libraries(${EXE_NAME} boards)
target_link_libraries(${EXE_NAME} drivers)
target_link_libraries(${EXE_NAME} fs)
target_link_libraries(${EXE_NAME} mm)
target_link_libraries(${EXE_NAME} sched)
target_link_libraries(${EXE_NAME} xx)
target_link_libraries(${EXE_NAME} net)
target_link_libraries(${EXE_NAME} supc++)
target_link_libraries(${EXE_NAME}
/usr/lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/libgcc.a)
target_link_libraries(${EXE_NAME} --end-group)
=========

I am using Ubuntu 20.04 operating system and the toolchain provided
from the Ubuntu Repository.

Best regards,

Flavio




-- 
Flavio de Castro Alves Filho

flavio.alves@gmail.com
Twitter: http://twitter.com/#!/fraviofii
LinkedIn profile: www.linkedin.com/in/flaviocastroalves

Re: Using C++ STL in Nuttx

Posted by Xiang Xiao <xi...@gmail.com>.
>>
>> Again, the coding standard does currently require the .cxx extension:
>>
>> https://cwiki.apache.org/confluence/display/NUTTX/Coding+Standard#cplusplus
>>
>> I would consider that up for discussion and subject to community
>> concurrence.  Which ever is selected, the extension should be used
>> consistently.  All C++ files under apps follow the coding standard for
>> file naming EXCEPT for some ELF loadable modules and some test-releated
>> files that are currently in violation of the coding standard:
>>
>> ./examples/elf/tests/helloxx/hello++1.cpp
>> ./examples/elf/tests/helloxx/hello++2.cpp
>> ./examples/elf/tests/helloxx/hello++3.cpp
>> ./examples/elf/tests/helloxx/hello++4.cpp
>> ./examples/elf/tests/helloxx/hello++5.cpp
>> ./examples/nxflat/tests/hello++/hello++1.cpp
>> ./examples/nxflat/tests/hello++/hello++2.cpp
>> ./examples/nxflat/tests/hello++/hello++3.cpp
>> ./examples/nxflat/tests/hello++/hello++4.cpp
>> ./testing/irtest/cmd.cpp
>> ./testing/irtest/enum.cpp
>> ./testing/irtest/main.cpp
>>
>>
> All these sources can change to .cxx suffix.
>

Here is the patch: https://github.com/apache/incubator-nuttx-apps/pull/616

Re: Using C++ STL in Nuttx

Posted by Flavio Castro Alves Filho <fl...@gmail.com>.
Hello Xiang,

I found it out and created the pull request :-)

Em dom., 21 de mar. de 2021 às 12:11, Flavio Castro Alves Filho
<fl...@gmail.com> escreveu:
>
> Hello Xiang,
>
> I create the documentation in my fork:
> https://github.com/Phi-Innovations/incubator-nuttx/blob/master/Documentation/guides/cpp_cmake.rst
>
> I don't know now to to submit for the main project for revision.
>
> Best regards,
>
> Flavio
>
> Em sex., 19 de mar. de 2021 às 08:38, Flavio Castro Alves Filho
> <fl...@gmail.com> escreveu:
> >
> > Hello Xiang,
> >
> > Sorry for the late reply.
> >
> > Absolutely. I will do that.
> >
> > Best regards,
> >
> > Flavio
> >
> > Em qua., 17 de mar. de 2021 às 10:57, Xiang Xiao
> > <xi...@gmail.com> escreveu:
> > >
> > > Good news. It will be great if you can document your experience in the
> > > Documentation folder when you find some free time.
> > >
> > > On Wed, Mar 17, 2021 at 9:54 PM Flavio Castro Alves Filho <
> > > flavio.alves@gmail.com> wrote:
> > >
> > > > Hello Xiang,
> > > >
> > > > I could finally build an C++ project using CMake and exported NuttX.
> > > >   - Before that, I made a test creating the same project inside the
> > > > NuttX apps structure, and it worked fine.
> > > >
> > > > My sample project is here:
> > > > https://github.com/Phi-Innovations/nuttx-apps/tree/main/hellocpp
> > > >
> > > > I compiled JsonCpp (https://github.com/nlohmann/json) together and it
> > > > worked fine.
> > > >
> > > > Thank you for all your support.
> > > >
> > > > Best regards,
> > > >
> > > > Flavio
> > > >
> > > >
> > > > Em ter., 16 de mar. de 2021 às 21:04, Flavio Castro Alves Filho
> > > > <fl...@gmail.com> escreveu:
> > > > >
> > > > > Xiang,
> > > > >
> > > > > I believe the problem was related to something on my branch.
> > > > >
> > > > > I was using a quite old version, based on release 10 branch.
> > > > >
> > > > > Now using master as branch, the testlibcxx compiled correctly.
> > > > > Tomorrow I will try my experiments and report here.
> > > > >
> > > > > Best regards,
> > > > >
> > > > > Flavio
> > > > >
> > > > > Em ter., 16 de mar. de 2021 às 16:24, Xiang Xiao
> > > > > <xi...@gmail.com> escreveu:
> > > > > >
> > > > > > Try to remove CONFIG_ARCH_FLOAT_H
> > > > > >
> > > > > > On Tue, Mar 16, 2021 at 12:15 PM Flavio Castro Alves Filho <
> > > > > > flavio.alves@gmail.com> wrote:
> > > > > >
> > > > > > > Hello Xiang,
> > > > > > >
> > > > > > > It is still not working. The error persists.
> > > > > > >
> > > > > > > Here is my defconfig file:
> > > > > > >
> > > > > > > #
> > > > > > > # This file is autogenerated: PLEASE DO NOT EDIT IT.
> > > > > > > #
> > > > > > > # You can use "make menuconfig" to make any modifications to the
> > > > > > > installed .config file.
> > > > > > > # You can then do "make savedefconfig" to generate a new defconfig
> > > > > > > file that includes your
> > > > > > > # modifications.
> > > > > > > #
> > > > > > > # CONFIG_ARCH_FPU is not set
> > > > > > > CONFIG_ARCH="arm"
> > > > > > > CONFIG_ARCH_BOARD="stm32f4discovery"
> > > > > > > CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
> > > > > > > CONFIG_ARCH_CHIP="stm32"
> > > > > > > CONFIG_ARCH_CHIP_STM32=y
> > > > > > > CONFIG_ARCH_CHIP_STM32F407VG=y
> > > > > > > CONFIG_ARCH_FLOAT_H=y
> > > > > > > CONFIG_ARCH_STACKDUMP=y
> > > > > > > CONFIG_BOARD_LOOPSPERMSEC=16717
> > > > > > > CONFIG_BUILTIN=y
> > > > > > > CONFIG_C99_BOOL8=y
> > > > > > > CONFIG_DISABLE_MOUNTPOINT=y
> > > > > > > CONFIG_EXAMPLES_HELLOXX=y
> > > > > > > CONFIG_HAVE_CXX=y
> > > > > > > CONFIG_INTELHEX_BINARY=y
> > > > > > > CONFIG_LIBCXX=y
> > > > > > > CONFIG_LIBC_FLOATINGPOINT=y
> > > > > > > CONFIG_LIBC_LOCALTIME=y
> > > > > > > CONFIG_MAX_TASKS=16
> > > > > > > CONFIG_MM_REGIONS=2
> > > > > > > CONFIG_NFILE_DESCRIPTORS=8
> > > > > > > CONFIG_NSH_BUILTIN_APPS=y
> > > > > > > CONFIG_NSH_FILEIOSIZE=512
> > > > > > > CONFIG_PREALLOC_TIMERS=4
> > > > > > > CONFIG_RAM_SIZE=114688
> > > > > > > CONFIG_RAM_START=0x20000000
> > > > > > > CONFIG_RAW_BINARY=y
> > > > > > > CONFIG_RR_INTERVAL=200
> > > > > > > CONFIG_SCHED_ONEXIT=y
> > > > > > > CONFIG_SCHED_ONEXIT_MAX=4
> > > > > > > CONFIG_SCHED_WAITPID=y
> > > > > > > CONFIG_SDCLONE_DISABLE=y
> > > > > > > CONFIG_START_DAY=2
> > > > > > > CONFIG_START_MONTH=11
> > > > > > > CONFIG_START_YEAR=2012
> > > > > > > CONFIG_STM32_JTAG_SW_ENABLE=y
> > > > > > > CONFIG_STM32_USART2=y
> > > > > > > CONFIG_SYMTAB_ORDEREDBYNAME=y
> > > > > > > CONFIG_SYSTEM_NSH=y
> > > > > > > CONFIG_USART2_RXBUFSIZE=128
> > > > > > > CONFIG_USART2_SERIAL_CONSOLE=y
> > > > > > > CONFIG_USART2_TXBUFSIZE=128
> > > > > > > CONFIG_USER_ENTRYPOINT="nsh_main"
> > > > > > >
> > > > > > > Any idea of what is missing?
> > > > > > >
> > > > > > > Best regards,
> > > > > > >
> > > > > > > Flavio
> > > > > > >
> > > > > > > Em ter., 16 de mar. de 2021 às 14:32, Xiang Xiao
> > > > > > > <xi...@gmail.com> escreveu:
> > > > > > > >
> > > > > > > > On Tue, Mar 16, 2021 at 10:20 AM Flavio Castro Alves Filho <
> > > > > > > > flavio.alves@gmail.com> wrote:
> > > > > > > >
> > > > > > > > > Hello Xiang,
> > > > > > > > >
> > > > > > > > > Em ter., 16 de mar. de 2021 às 14:01, Xiang Xiao
> > > > > > > > > <xi...@gmail.com> escreveu:
> > > > > > > > > >
> > > > > > > > > > On Tu
> > > > > > > > > > >
> > > > > > > > > > This project use the modern C++ feature, so you must enable
> > > > llvm
> > > > > > > > > > ibc++(CONFIG_LIBCXX=y)
> > > > > > > > >
> > > > > > > > > I tried a new build, executing:
> > > > > > > > >
> > > > > > > > > $ make distclean
> > > > > > > > > $ ./tools/configure.sh -l stm32f4discovery:testlibcxx
> > > > > > > > > $ make
> > > > > > > > >
> > > > > > > > > I can see the library being downloaded from git, but it is not
> > > > > > > compiling.
> > > > > > > > >
> > > > > > > > > In file included from
> > > > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/random:1637,
> > > > > > > > >                  from libcxx/src/random.cpp:16:
> > > > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath: At global
> > > > scope:
> > > > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:321:9: error:
> > > > > > > > > '::signbit' has not been declared
> > > > > > > > >   321 | using ::signbit;
> > > > > > > > >       |         ^~~~~~~
> > > > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:322:9: error:
> > > > > > > > > '::fpclassify' has not been declared
> > > > > > > > >   322 | using ::fpclassify;
> > > > > > > > >       |         ^~~~~~~~~~
> > > > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:326:9: error:
> > > > > > > > > '::isnormal' has not been declared
> > > > > > > > >   326 | using ::isnormal;
> > > > > > > > >       |         ^~~~~~~~
> > > > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:327:9: error:
> > > > > > > > > '::isgreater' has not been declared
> > > > > > > > >   327 | using ::isgreater;
> > > > > > > > >
> > > > > > > > > How should I solve this issue?
> > > > > > > > >
> > > > > > > >
> > > > > > > > CONFIG_LIBM has to be disabled, since NuttX match library
> > > > implementation
> > > > > > > > lacks many standard defined functions which is required by the new
> > > > libc++
> > > > > > > > library.
> > > > > > > >
> > > > > > > >
> > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > You need tell compiler stop to search the toolchain provided
> > > > c++
> > > > > > > library
> > > > > > > > > > by -nostdinc++
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > > I believe it will solve my cmake issue.
> > > > > > > > >
> > > > > > > > > Best regards,
> > > > > > > > >
> > > > > > > > > Flavio
> > > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Flavio de Castro Alves Filho
> > > > > > >
> > > > > > > flavio.alves@gmail.com
> > > > > > > Twitter: http://twitter.com/#!/fraviofii
> > > > > > > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
> > > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Flavio de Castro Alves Filho
> > > > >
> > > > > flavio.alves@gmail.com
> > > > > Twitter: http://twitter.com/#!/fraviofii
> > > > > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
> > > >
> > > >
> > > >
> > > > --
> > > > Flavio de Castro Alves Filho
> > > >
> > > > flavio.alves@gmail.com
> > > > Twitter: http://twitter.com/#!/fraviofii
> > > > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
> > > >
> >
> >
> >
> > --
> > Flavio de Castro Alves Filho
> >
> > flavio.alves@gmail.com
> > Twitter: http://twitter.com/#!/fraviofii
> > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
>
>
>
> --
> Flavio de Castro Alves Filho
>
> flavio.alves@gmail.com
> Twitter: http://twitter.com/#!/fraviofii
> LinkedIn profile: www.linkedin.com/in/flaviocastroalves



-- 
Flavio de Castro Alves Filho

flavio.alves@gmail.com
Twitter: http://twitter.com/#!/fraviofii
LinkedIn profile: www.linkedin.com/in/flaviocastroalves

Re: Using C++ STL in Nuttx

Posted by Flavio Castro Alves Filho <fl...@gmail.com>.
Hello Xiang,

I create the documentation in my fork:
https://github.com/Phi-Innovations/incubator-nuttx/blob/master/Documentation/guides/cpp_cmake.rst

I don't know now to to submit for the main project for revision.

Best regards,

Flavio

Em sex., 19 de mar. de 2021 às 08:38, Flavio Castro Alves Filho
<fl...@gmail.com> escreveu:
>
> Hello Xiang,
>
> Sorry for the late reply.
>
> Absolutely. I will do that.
>
> Best regards,
>
> Flavio
>
> Em qua., 17 de mar. de 2021 às 10:57, Xiang Xiao
> <xi...@gmail.com> escreveu:
> >
> > Good news. It will be great if you can document your experience in the
> > Documentation folder when you find some free time.
> >
> > On Wed, Mar 17, 2021 at 9:54 PM Flavio Castro Alves Filho <
> > flavio.alves@gmail.com> wrote:
> >
> > > Hello Xiang,
> > >
> > > I could finally build an C++ project using CMake and exported NuttX.
> > >   - Before that, I made a test creating the same project inside the
> > > NuttX apps structure, and it worked fine.
> > >
> > > My sample project is here:
> > > https://github.com/Phi-Innovations/nuttx-apps/tree/main/hellocpp
> > >
> > > I compiled JsonCpp (https://github.com/nlohmann/json) together and it
> > > worked fine.
> > >
> > > Thank you for all your support.
> > >
> > > Best regards,
> > >
> > > Flavio
> > >
> > >
> > > Em ter., 16 de mar. de 2021 às 21:04, Flavio Castro Alves Filho
> > > <fl...@gmail.com> escreveu:
> > > >
> > > > Xiang,
> > > >
> > > > I believe the problem was related to something on my branch.
> > > >
> > > > I was using a quite old version, based on release 10 branch.
> > > >
> > > > Now using master as branch, the testlibcxx compiled correctly.
> > > > Tomorrow I will try my experiments and report here.
> > > >
> > > > Best regards,
> > > >
> > > > Flavio
> > > >
> > > > Em ter., 16 de mar. de 2021 às 16:24, Xiang Xiao
> > > > <xi...@gmail.com> escreveu:
> > > > >
> > > > > Try to remove CONFIG_ARCH_FLOAT_H
> > > > >
> > > > > On Tue, Mar 16, 2021 at 12:15 PM Flavio Castro Alves Filho <
> > > > > flavio.alves@gmail.com> wrote:
> > > > >
> > > > > > Hello Xiang,
> > > > > >
> > > > > > It is still not working. The error persists.
> > > > > >
> > > > > > Here is my defconfig file:
> > > > > >
> > > > > > #
> > > > > > # This file is autogenerated: PLEASE DO NOT EDIT IT.
> > > > > > #
> > > > > > # You can use "make menuconfig" to make any modifications to the
> > > > > > installed .config file.
> > > > > > # You can then do "make savedefconfig" to generate a new defconfig
> > > > > > file that includes your
> > > > > > # modifications.
> > > > > > #
> > > > > > # CONFIG_ARCH_FPU is not set
> > > > > > CONFIG_ARCH="arm"
> > > > > > CONFIG_ARCH_BOARD="stm32f4discovery"
> > > > > > CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
> > > > > > CONFIG_ARCH_CHIP="stm32"
> > > > > > CONFIG_ARCH_CHIP_STM32=y
> > > > > > CONFIG_ARCH_CHIP_STM32F407VG=y
> > > > > > CONFIG_ARCH_FLOAT_H=y
> > > > > > CONFIG_ARCH_STACKDUMP=y
> > > > > > CONFIG_BOARD_LOOPSPERMSEC=16717
> > > > > > CONFIG_BUILTIN=y
> > > > > > CONFIG_C99_BOOL8=y
> > > > > > CONFIG_DISABLE_MOUNTPOINT=y
> > > > > > CONFIG_EXAMPLES_HELLOXX=y
> > > > > > CONFIG_HAVE_CXX=y
> > > > > > CONFIG_INTELHEX_BINARY=y
> > > > > > CONFIG_LIBCXX=y
> > > > > > CONFIG_LIBC_FLOATINGPOINT=y
> > > > > > CONFIG_LIBC_LOCALTIME=y
> > > > > > CONFIG_MAX_TASKS=16
> > > > > > CONFIG_MM_REGIONS=2
> > > > > > CONFIG_NFILE_DESCRIPTORS=8
> > > > > > CONFIG_NSH_BUILTIN_APPS=y
> > > > > > CONFIG_NSH_FILEIOSIZE=512
> > > > > > CONFIG_PREALLOC_TIMERS=4
> > > > > > CONFIG_RAM_SIZE=114688
> > > > > > CONFIG_RAM_START=0x20000000
> > > > > > CONFIG_RAW_BINARY=y
> > > > > > CONFIG_RR_INTERVAL=200
> > > > > > CONFIG_SCHED_ONEXIT=y
> > > > > > CONFIG_SCHED_ONEXIT_MAX=4
> > > > > > CONFIG_SCHED_WAITPID=y
> > > > > > CONFIG_SDCLONE_DISABLE=y
> > > > > > CONFIG_START_DAY=2
> > > > > > CONFIG_START_MONTH=11
> > > > > > CONFIG_START_YEAR=2012
> > > > > > CONFIG_STM32_JTAG_SW_ENABLE=y
> > > > > > CONFIG_STM32_USART2=y
> > > > > > CONFIG_SYMTAB_ORDEREDBYNAME=y
> > > > > > CONFIG_SYSTEM_NSH=y
> > > > > > CONFIG_USART2_RXBUFSIZE=128
> > > > > > CONFIG_USART2_SERIAL_CONSOLE=y
> > > > > > CONFIG_USART2_TXBUFSIZE=128
> > > > > > CONFIG_USER_ENTRYPOINT="nsh_main"
> > > > > >
> > > > > > Any idea of what is missing?
> > > > > >
> > > > > > Best regards,
> > > > > >
> > > > > > Flavio
> > > > > >
> > > > > > Em ter., 16 de mar. de 2021 às 14:32, Xiang Xiao
> > > > > > <xi...@gmail.com> escreveu:
> > > > > > >
> > > > > > > On Tue, Mar 16, 2021 at 10:20 AM Flavio Castro Alves Filho <
> > > > > > > flavio.alves@gmail.com> wrote:
> > > > > > >
> > > > > > > > Hello Xiang,
> > > > > > > >
> > > > > > > > Em ter., 16 de mar. de 2021 às 14:01, Xiang Xiao
> > > > > > > > <xi...@gmail.com> escreveu:
> > > > > > > > >
> > > > > > > > > On Tu
> > > > > > > > > >
> > > > > > > > > This project use the modern C++ feature, so you must enable
> > > llvm
> > > > > > > > > ibc++(CONFIG_LIBCXX=y)
> > > > > > > >
> > > > > > > > I tried a new build, executing:
> > > > > > > >
> > > > > > > > $ make distclean
> > > > > > > > $ ./tools/configure.sh -l stm32f4discovery:testlibcxx
> > > > > > > > $ make
> > > > > > > >
> > > > > > > > I can see the library being downloaded from git, but it is not
> > > > > > compiling.
> > > > > > > >
> > > > > > > > In file included from
> > > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/random:1637,
> > > > > > > >                  from libcxx/src/random.cpp:16:
> > > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath: At global
> > > scope:
> > > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:321:9: error:
> > > > > > > > '::signbit' has not been declared
> > > > > > > >   321 | using ::signbit;
> > > > > > > >       |         ^~~~~~~
> > > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:322:9: error:
> > > > > > > > '::fpclassify' has not been declared
> > > > > > > >   322 | using ::fpclassify;
> > > > > > > >       |         ^~~~~~~~~~
> > > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:326:9: error:
> > > > > > > > '::isnormal' has not been declared
> > > > > > > >   326 | using ::isnormal;
> > > > > > > >       |         ^~~~~~~~
> > > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:327:9: error:
> > > > > > > > '::isgreater' has not been declared
> > > > > > > >   327 | using ::isgreater;
> > > > > > > >
> > > > > > > > How should I solve this issue?
> > > > > > > >
> > > > > > >
> > > > > > > CONFIG_LIBM has to be disabled, since NuttX match library
> > > implementation
> > > > > > > lacks many standard defined functions which is required by the new
> > > libc++
> > > > > > > library.
> > > > > > >
> > > > > > >
> > > > > > > >
> > > > > > > > > >
> > > > > > > > > You need tell compiler stop to search the toolchain provided
> > > c++
> > > > > > library
> > > > > > > > > by -nostdinc++
> > > > > > > > >
> > > > > > > >
> > > > > > > > I believe it will solve my cmake issue.
> > > > > > > >
> > > > > > > > Best regards,
> > > > > > > >
> > > > > > > > Flavio
> > > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Flavio de Castro Alves Filho
> > > > > >
> > > > > > flavio.alves@gmail.com
> > > > > > Twitter: http://twitter.com/#!/fraviofii
> > > > > > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
> > > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Flavio de Castro Alves Filho
> > > >
> > > > flavio.alves@gmail.com
> > > > Twitter: http://twitter.com/#!/fraviofii
> > > > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
> > >
> > >
> > >
> > > --
> > > Flavio de Castro Alves Filho
> > >
> > > flavio.alves@gmail.com
> > > Twitter: http://twitter.com/#!/fraviofii
> > > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
> > >
>
>
>
> --
> Flavio de Castro Alves Filho
>
> flavio.alves@gmail.com
> Twitter: http://twitter.com/#!/fraviofii
> LinkedIn profile: www.linkedin.com/in/flaviocastroalves



-- 
Flavio de Castro Alves Filho

flavio.alves@gmail.com
Twitter: http://twitter.com/#!/fraviofii
LinkedIn profile: www.linkedin.com/in/flaviocastroalves

Re: Using C++ STL in Nuttx

Posted by Flavio Castro Alves Filho <fl...@gmail.com>.
Hello Xiang,

Sorry for the late reply.

Absolutely. I will do that.

Best regards,

Flavio

Em qua., 17 de mar. de 2021 às 10:57, Xiang Xiao
<xi...@gmail.com> escreveu:
>
> Good news. It will be great if you can document your experience in the
> Documentation folder when you find some free time.
>
> On Wed, Mar 17, 2021 at 9:54 PM Flavio Castro Alves Filho <
> flavio.alves@gmail.com> wrote:
>
> > Hello Xiang,
> >
> > I could finally build an C++ project using CMake and exported NuttX.
> >   - Before that, I made a test creating the same project inside the
> > NuttX apps structure, and it worked fine.
> >
> > My sample project is here:
> > https://github.com/Phi-Innovations/nuttx-apps/tree/main/hellocpp
> >
> > I compiled JsonCpp (https://github.com/nlohmann/json) together and it
> > worked fine.
> >
> > Thank you for all your support.
> >
> > Best regards,
> >
> > Flavio
> >
> >
> > Em ter., 16 de mar. de 2021 às 21:04, Flavio Castro Alves Filho
> > <fl...@gmail.com> escreveu:
> > >
> > > Xiang,
> > >
> > > I believe the problem was related to something on my branch.
> > >
> > > I was using a quite old version, based on release 10 branch.
> > >
> > > Now using master as branch, the testlibcxx compiled correctly.
> > > Tomorrow I will try my experiments and report here.
> > >
> > > Best regards,
> > >
> > > Flavio
> > >
> > > Em ter., 16 de mar. de 2021 às 16:24, Xiang Xiao
> > > <xi...@gmail.com> escreveu:
> > > >
> > > > Try to remove CONFIG_ARCH_FLOAT_H
> > > >
> > > > On Tue, Mar 16, 2021 at 12:15 PM Flavio Castro Alves Filho <
> > > > flavio.alves@gmail.com> wrote:
> > > >
> > > > > Hello Xiang,
> > > > >
> > > > > It is still not working. The error persists.
> > > > >
> > > > > Here is my defconfig file:
> > > > >
> > > > > #
> > > > > # This file is autogenerated: PLEASE DO NOT EDIT IT.
> > > > > #
> > > > > # You can use "make menuconfig" to make any modifications to the
> > > > > installed .config file.
> > > > > # You can then do "make savedefconfig" to generate a new defconfig
> > > > > file that includes your
> > > > > # modifications.
> > > > > #
> > > > > # CONFIG_ARCH_FPU is not set
> > > > > CONFIG_ARCH="arm"
> > > > > CONFIG_ARCH_BOARD="stm32f4discovery"
> > > > > CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
> > > > > CONFIG_ARCH_CHIP="stm32"
> > > > > CONFIG_ARCH_CHIP_STM32=y
> > > > > CONFIG_ARCH_CHIP_STM32F407VG=y
> > > > > CONFIG_ARCH_FLOAT_H=y
> > > > > CONFIG_ARCH_STACKDUMP=y
> > > > > CONFIG_BOARD_LOOPSPERMSEC=16717
> > > > > CONFIG_BUILTIN=y
> > > > > CONFIG_C99_BOOL8=y
> > > > > CONFIG_DISABLE_MOUNTPOINT=y
> > > > > CONFIG_EXAMPLES_HELLOXX=y
> > > > > CONFIG_HAVE_CXX=y
> > > > > CONFIG_INTELHEX_BINARY=y
> > > > > CONFIG_LIBCXX=y
> > > > > CONFIG_LIBC_FLOATINGPOINT=y
> > > > > CONFIG_LIBC_LOCALTIME=y
> > > > > CONFIG_MAX_TASKS=16
> > > > > CONFIG_MM_REGIONS=2
> > > > > CONFIG_NFILE_DESCRIPTORS=8
> > > > > CONFIG_NSH_BUILTIN_APPS=y
> > > > > CONFIG_NSH_FILEIOSIZE=512
> > > > > CONFIG_PREALLOC_TIMERS=4
> > > > > CONFIG_RAM_SIZE=114688
> > > > > CONFIG_RAM_START=0x20000000
> > > > > CONFIG_RAW_BINARY=y
> > > > > CONFIG_RR_INTERVAL=200
> > > > > CONFIG_SCHED_ONEXIT=y
> > > > > CONFIG_SCHED_ONEXIT_MAX=4
> > > > > CONFIG_SCHED_WAITPID=y
> > > > > CONFIG_SDCLONE_DISABLE=y
> > > > > CONFIG_START_DAY=2
> > > > > CONFIG_START_MONTH=11
> > > > > CONFIG_START_YEAR=2012
> > > > > CONFIG_STM32_JTAG_SW_ENABLE=y
> > > > > CONFIG_STM32_USART2=y
> > > > > CONFIG_SYMTAB_ORDEREDBYNAME=y
> > > > > CONFIG_SYSTEM_NSH=y
> > > > > CONFIG_USART2_RXBUFSIZE=128
> > > > > CONFIG_USART2_SERIAL_CONSOLE=y
> > > > > CONFIG_USART2_TXBUFSIZE=128
> > > > > CONFIG_USER_ENTRYPOINT="nsh_main"
> > > > >
> > > > > Any idea of what is missing?
> > > > >
> > > > > Best regards,
> > > > >
> > > > > Flavio
> > > > >
> > > > > Em ter., 16 de mar. de 2021 às 14:32, Xiang Xiao
> > > > > <xi...@gmail.com> escreveu:
> > > > > >
> > > > > > On Tue, Mar 16, 2021 at 10:20 AM Flavio Castro Alves Filho <
> > > > > > flavio.alves@gmail.com> wrote:
> > > > > >
> > > > > > > Hello Xiang,
> > > > > > >
> > > > > > > Em ter., 16 de mar. de 2021 às 14:01, Xiang Xiao
> > > > > > > <xi...@gmail.com> escreveu:
> > > > > > > >
> > > > > > > > On Tu
> > > > > > > > >
> > > > > > > > This project use the modern C++ feature, so you must enable
> > llvm
> > > > > > > > ibc++(CONFIG_LIBCXX=y)
> > > > > > >
> > > > > > > I tried a new build, executing:
> > > > > > >
> > > > > > > $ make distclean
> > > > > > > $ ./tools/configure.sh -l stm32f4discovery:testlibcxx
> > > > > > > $ make
> > > > > > >
> > > > > > > I can see the library being downloaded from git, but it is not
> > > > > compiling.
> > > > > > >
> > > > > > > In file included from
> > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/random:1637,
> > > > > > >                  from libcxx/src/random.cpp:16:
> > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath: At global
> > scope:
> > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:321:9: error:
> > > > > > > '::signbit' has not been declared
> > > > > > >   321 | using ::signbit;
> > > > > > >       |         ^~~~~~~
> > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:322:9: error:
> > > > > > > '::fpclassify' has not been declared
> > > > > > >   322 | using ::fpclassify;
> > > > > > >       |         ^~~~~~~~~~
> > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:326:9: error:
> > > > > > > '::isnormal' has not been declared
> > > > > > >   326 | using ::isnormal;
> > > > > > >       |         ^~~~~~~~
> > > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:327:9: error:
> > > > > > > '::isgreater' has not been declared
> > > > > > >   327 | using ::isgreater;
> > > > > > >
> > > > > > > How should I solve this issue?
> > > > > > >
> > > > > >
> > > > > > CONFIG_LIBM has to be disabled, since NuttX match library
> > implementation
> > > > > > lacks many standard defined functions which is required by the new
> > libc++
> > > > > > library.
> > > > > >
> > > > > >
> > > > > > >
> > > > > > > > >
> > > > > > > > You need tell compiler stop to search the toolchain provided
> > c++
> > > > > library
> > > > > > > > by -nostdinc++
> > > > > > > >
> > > > > > >
> > > > > > > I believe it will solve my cmake issue.
> > > > > > >
> > > > > > > Best regards,
> > > > > > >
> > > > > > > Flavio
> > > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Flavio de Castro Alves Filho
> > > > >
> > > > > flavio.alves@gmail.com
> > > > > Twitter: http://twitter.com/#!/fraviofii
> > > > > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
> > > > >
> > >
> > >
> > >
> > > --
> > > Flavio de Castro Alves Filho
> > >
> > > flavio.alves@gmail.com
> > > Twitter: http://twitter.com/#!/fraviofii
> > > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
> >
> >
> >
> > --
> > Flavio de Castro Alves Filho
> >
> > flavio.alves@gmail.com
> > Twitter: http://twitter.com/#!/fraviofii
> > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
> >



-- 
Flavio de Castro Alves Filho

flavio.alves@gmail.com
Twitter: http://twitter.com/#!/fraviofii
LinkedIn profile: www.linkedin.com/in/flaviocastroalves

Re: Using C++ STL in Nuttx

Posted by Xiang Xiao <xi...@gmail.com>.
Good news. It will be great if you can document your experience in the
Documentation folder when you find some free time.

On Wed, Mar 17, 2021 at 9:54 PM Flavio Castro Alves Filho <
flavio.alves@gmail.com> wrote:

> Hello Xiang,
>
> I could finally build an C++ project using CMake and exported NuttX.
>   - Before that, I made a test creating the same project inside the
> NuttX apps structure, and it worked fine.
>
> My sample project is here:
> https://github.com/Phi-Innovations/nuttx-apps/tree/main/hellocpp
>
> I compiled JsonCpp (https://github.com/nlohmann/json) together and it
> worked fine.
>
> Thank you for all your support.
>
> Best regards,
>
> Flavio
>
>
> Em ter., 16 de mar. de 2021 às 21:04, Flavio Castro Alves Filho
> <fl...@gmail.com> escreveu:
> >
> > Xiang,
> >
> > I believe the problem was related to something on my branch.
> >
> > I was using a quite old version, based on release 10 branch.
> >
> > Now using master as branch, the testlibcxx compiled correctly.
> > Tomorrow I will try my experiments and report here.
> >
> > Best regards,
> >
> > Flavio
> >
> > Em ter., 16 de mar. de 2021 às 16:24, Xiang Xiao
> > <xi...@gmail.com> escreveu:
> > >
> > > Try to remove CONFIG_ARCH_FLOAT_H
> > >
> > > On Tue, Mar 16, 2021 at 12:15 PM Flavio Castro Alves Filho <
> > > flavio.alves@gmail.com> wrote:
> > >
> > > > Hello Xiang,
> > > >
> > > > It is still not working. The error persists.
> > > >
> > > > Here is my defconfig file:
> > > >
> > > > #
> > > > # This file is autogenerated: PLEASE DO NOT EDIT IT.
> > > > #
> > > > # You can use "make menuconfig" to make any modifications to the
> > > > installed .config file.
> > > > # You can then do "make savedefconfig" to generate a new defconfig
> > > > file that includes your
> > > > # modifications.
> > > > #
> > > > # CONFIG_ARCH_FPU is not set
> > > > CONFIG_ARCH="arm"
> > > > CONFIG_ARCH_BOARD="stm32f4discovery"
> > > > CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
> > > > CONFIG_ARCH_CHIP="stm32"
> > > > CONFIG_ARCH_CHIP_STM32=y
> > > > CONFIG_ARCH_CHIP_STM32F407VG=y
> > > > CONFIG_ARCH_FLOAT_H=y
> > > > CONFIG_ARCH_STACKDUMP=y
> > > > CONFIG_BOARD_LOOPSPERMSEC=16717
> > > > CONFIG_BUILTIN=y
> > > > CONFIG_C99_BOOL8=y
> > > > CONFIG_DISABLE_MOUNTPOINT=y
> > > > CONFIG_EXAMPLES_HELLOXX=y
> > > > CONFIG_HAVE_CXX=y
> > > > CONFIG_INTELHEX_BINARY=y
> > > > CONFIG_LIBCXX=y
> > > > CONFIG_LIBC_FLOATINGPOINT=y
> > > > CONFIG_LIBC_LOCALTIME=y
> > > > CONFIG_MAX_TASKS=16
> > > > CONFIG_MM_REGIONS=2
> > > > CONFIG_NFILE_DESCRIPTORS=8
> > > > CONFIG_NSH_BUILTIN_APPS=y
> > > > CONFIG_NSH_FILEIOSIZE=512
> > > > CONFIG_PREALLOC_TIMERS=4
> > > > CONFIG_RAM_SIZE=114688
> > > > CONFIG_RAM_START=0x20000000
> > > > CONFIG_RAW_BINARY=y
> > > > CONFIG_RR_INTERVAL=200
> > > > CONFIG_SCHED_ONEXIT=y
> > > > CONFIG_SCHED_ONEXIT_MAX=4
> > > > CONFIG_SCHED_WAITPID=y
> > > > CONFIG_SDCLONE_DISABLE=y
> > > > CONFIG_START_DAY=2
> > > > CONFIG_START_MONTH=11
> > > > CONFIG_START_YEAR=2012
> > > > CONFIG_STM32_JTAG_SW_ENABLE=y
> > > > CONFIG_STM32_USART2=y
> > > > CONFIG_SYMTAB_ORDEREDBYNAME=y
> > > > CONFIG_SYSTEM_NSH=y
> > > > CONFIG_USART2_RXBUFSIZE=128
> > > > CONFIG_USART2_SERIAL_CONSOLE=y
> > > > CONFIG_USART2_TXBUFSIZE=128
> > > > CONFIG_USER_ENTRYPOINT="nsh_main"
> > > >
> > > > Any idea of what is missing?
> > > >
> > > > Best regards,
> > > >
> > > > Flavio
> > > >
> > > > Em ter., 16 de mar. de 2021 às 14:32, Xiang Xiao
> > > > <xi...@gmail.com> escreveu:
> > > > >
> > > > > On Tue, Mar 16, 2021 at 10:20 AM Flavio Castro Alves Filho <
> > > > > flavio.alves@gmail.com> wrote:
> > > > >
> > > > > > Hello Xiang,
> > > > > >
> > > > > > Em ter., 16 de mar. de 2021 às 14:01, Xiang Xiao
> > > > > > <xi...@gmail.com> escreveu:
> > > > > > >
> > > > > > > On Tu
> > > > > > > >
> > > > > > > This project use the modern C++ feature, so you must enable
> llvm
> > > > > > > ibc++(CONFIG_LIBCXX=y)
> > > > > >
> > > > > > I tried a new build, executing:
> > > > > >
> > > > > > $ make distclean
> > > > > > $ ./tools/configure.sh -l stm32f4discovery:testlibcxx
> > > > > > $ make
> > > > > >
> > > > > > I can see the library being downloaded from git, but it is not
> > > > compiling.
> > > > > >
> > > > > > In file included from
> > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/random:1637,
> > > > > >                  from libcxx/src/random.cpp:16:
> > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath: At global
> scope:
> > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:321:9: error:
> > > > > > '::signbit' has not been declared
> > > > > >   321 | using ::signbit;
> > > > > >       |         ^~~~~~~
> > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:322:9: error:
> > > > > > '::fpclassify' has not been declared
> > > > > >   322 | using ::fpclassify;
> > > > > >       |         ^~~~~~~~~~
> > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:326:9: error:
> > > > > > '::isnormal' has not been declared
> > > > > >   326 | using ::isnormal;
> > > > > >       |         ^~~~~~~~
> > > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:327:9: error:
> > > > > > '::isgreater' has not been declared
> > > > > >   327 | using ::isgreater;
> > > > > >
> > > > > > How should I solve this issue?
> > > > > >
> > > > >
> > > > > CONFIG_LIBM has to be disabled, since NuttX match library
> implementation
> > > > > lacks many standard defined functions which is required by the new
> libc++
> > > > > library.
> > > > >
> > > > >
> > > > > >
> > > > > > > >
> > > > > > > You need tell compiler stop to search the toolchain provided
> c++
> > > > library
> > > > > > > by -nostdinc++
> > > > > > >
> > > > > >
> > > > > > I believe it will solve my cmake issue.
> > > > > >
> > > > > > Best regards,
> > > > > >
> > > > > > Flavio
> > > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Flavio de Castro Alves Filho
> > > >
> > > > flavio.alves@gmail.com
> > > > Twitter: http://twitter.com/#!/fraviofii
> > > > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
> > > >
> >
> >
> >
> > --
> > Flavio de Castro Alves Filho
> >
> > flavio.alves@gmail.com
> > Twitter: http://twitter.com/#!/fraviofii
> > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
>
>
>
> --
> Flavio de Castro Alves Filho
>
> flavio.alves@gmail.com
> Twitter: http://twitter.com/#!/fraviofii
> LinkedIn profile: www.linkedin.com/in/flaviocastroalves
>

Re: Using C++ STL in Nuttx

Posted by Flavio Castro Alves Filho <fl...@gmail.com>.
Hello Xiang,

I could finally build an C++ project using CMake and exported NuttX.
  - Before that, I made a test creating the same project inside the
NuttX apps structure, and it worked fine.

My sample project is here:
https://github.com/Phi-Innovations/nuttx-apps/tree/main/hellocpp

I compiled JsonCpp (https://github.com/nlohmann/json) together and it
worked fine.

Thank you for all your support.

Best regards,

Flavio


Em ter., 16 de mar. de 2021 às 21:04, Flavio Castro Alves Filho
<fl...@gmail.com> escreveu:
>
> Xiang,
>
> I believe the problem was related to something on my branch.
>
> I was using a quite old version, based on release 10 branch.
>
> Now using master as branch, the testlibcxx compiled correctly.
> Tomorrow I will try my experiments and report here.
>
> Best regards,
>
> Flavio
>
> Em ter., 16 de mar. de 2021 às 16:24, Xiang Xiao
> <xi...@gmail.com> escreveu:
> >
> > Try to remove CONFIG_ARCH_FLOAT_H
> >
> > On Tue, Mar 16, 2021 at 12:15 PM Flavio Castro Alves Filho <
> > flavio.alves@gmail.com> wrote:
> >
> > > Hello Xiang,
> > >
> > > It is still not working. The error persists.
> > >
> > > Here is my defconfig file:
> > >
> > > #
> > > # This file is autogenerated: PLEASE DO NOT EDIT IT.
> > > #
> > > # You can use "make menuconfig" to make any modifications to the
> > > installed .config file.
> > > # You can then do "make savedefconfig" to generate a new defconfig
> > > file that includes your
> > > # modifications.
> > > #
> > > # CONFIG_ARCH_FPU is not set
> > > CONFIG_ARCH="arm"
> > > CONFIG_ARCH_BOARD="stm32f4discovery"
> > > CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
> > > CONFIG_ARCH_CHIP="stm32"
> > > CONFIG_ARCH_CHIP_STM32=y
> > > CONFIG_ARCH_CHIP_STM32F407VG=y
> > > CONFIG_ARCH_FLOAT_H=y
> > > CONFIG_ARCH_STACKDUMP=y
> > > CONFIG_BOARD_LOOPSPERMSEC=16717
> > > CONFIG_BUILTIN=y
> > > CONFIG_C99_BOOL8=y
> > > CONFIG_DISABLE_MOUNTPOINT=y
> > > CONFIG_EXAMPLES_HELLOXX=y
> > > CONFIG_HAVE_CXX=y
> > > CONFIG_INTELHEX_BINARY=y
> > > CONFIG_LIBCXX=y
> > > CONFIG_LIBC_FLOATINGPOINT=y
> > > CONFIG_LIBC_LOCALTIME=y
> > > CONFIG_MAX_TASKS=16
> > > CONFIG_MM_REGIONS=2
> > > CONFIG_NFILE_DESCRIPTORS=8
> > > CONFIG_NSH_BUILTIN_APPS=y
> > > CONFIG_NSH_FILEIOSIZE=512
> > > CONFIG_PREALLOC_TIMERS=4
> > > CONFIG_RAM_SIZE=114688
> > > CONFIG_RAM_START=0x20000000
> > > CONFIG_RAW_BINARY=y
> > > CONFIG_RR_INTERVAL=200
> > > CONFIG_SCHED_ONEXIT=y
> > > CONFIG_SCHED_ONEXIT_MAX=4
> > > CONFIG_SCHED_WAITPID=y
> > > CONFIG_SDCLONE_DISABLE=y
> > > CONFIG_START_DAY=2
> > > CONFIG_START_MONTH=11
> > > CONFIG_START_YEAR=2012
> > > CONFIG_STM32_JTAG_SW_ENABLE=y
> > > CONFIG_STM32_USART2=y
> > > CONFIG_SYMTAB_ORDEREDBYNAME=y
> > > CONFIG_SYSTEM_NSH=y
> > > CONFIG_USART2_RXBUFSIZE=128
> > > CONFIG_USART2_SERIAL_CONSOLE=y
> > > CONFIG_USART2_TXBUFSIZE=128
> > > CONFIG_USER_ENTRYPOINT="nsh_main"
> > >
> > > Any idea of what is missing?
> > >
> > > Best regards,
> > >
> > > Flavio
> > >
> > > Em ter., 16 de mar. de 2021 às 14:32, Xiang Xiao
> > > <xi...@gmail.com> escreveu:
> > > >
> > > > On Tue, Mar 16, 2021 at 10:20 AM Flavio Castro Alves Filho <
> > > > flavio.alves@gmail.com> wrote:
> > > >
> > > > > Hello Xiang,
> > > > >
> > > > > Em ter., 16 de mar. de 2021 às 14:01, Xiang Xiao
> > > > > <xi...@gmail.com> escreveu:
> > > > > >
> > > > > > On Tu
> > > > > > >
> > > > > > This project use the modern C++ feature, so you must enable llvm
> > > > > > ibc++(CONFIG_LIBCXX=y)
> > > > >
> > > > > I tried a new build, executing:
> > > > >
> > > > > $ make distclean
> > > > > $ ./tools/configure.sh -l stm32f4discovery:testlibcxx
> > > > > $ make
> > > > >
> > > > > I can see the library being downloaded from git, but it is not
> > > compiling.
> > > > >
> > > > > In file included from
> > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/random:1637,
> > > > >                  from libcxx/src/random.cpp:16:
> > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath: At global scope:
> > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:321:9: error:
> > > > > '::signbit' has not been declared
> > > > >   321 | using ::signbit;
> > > > >       |         ^~~~~~~
> > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:322:9: error:
> > > > > '::fpclassify' has not been declared
> > > > >   322 | using ::fpclassify;
> > > > >       |         ^~~~~~~~~~
> > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:326:9: error:
> > > > > '::isnormal' has not been declared
> > > > >   326 | using ::isnormal;
> > > > >       |         ^~~~~~~~
> > > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:327:9: error:
> > > > > '::isgreater' has not been declared
> > > > >   327 | using ::isgreater;
> > > > >
> > > > > How should I solve this issue?
> > > > >
> > > >
> > > > CONFIG_LIBM has to be disabled, since NuttX match library implementation
> > > > lacks many standard defined functions which is required by the new libc++
> > > > library.
> > > >
> > > >
> > > > >
> > > > > > >
> > > > > > You need tell compiler stop to search the toolchain provided c++
> > > library
> > > > > > by -nostdinc++
> > > > > >
> > > > >
> > > > > I believe it will solve my cmake issue.
> > > > >
> > > > > Best regards,
> > > > >
> > > > > Flavio
> > > > >
> > >
> > >
> > >
> > > --
> > > Flavio de Castro Alves Filho
> > >
> > > flavio.alves@gmail.com
> > > Twitter: http://twitter.com/#!/fraviofii
> > > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
> > >
>
>
>
> --
> Flavio de Castro Alves Filho
>
> flavio.alves@gmail.com
> Twitter: http://twitter.com/#!/fraviofii
> LinkedIn profile: www.linkedin.com/in/flaviocastroalves



-- 
Flavio de Castro Alves Filho

flavio.alves@gmail.com
Twitter: http://twitter.com/#!/fraviofii
LinkedIn profile: www.linkedin.com/in/flaviocastroalves

Re: Using C++ STL in Nuttx

Posted by Flavio Castro Alves Filho <fl...@gmail.com>.
Xiang,

I believe the problem was related to something on my branch.

I was using a quite old version, based on release 10 branch.

Now using master as branch, the testlibcxx compiled correctly.
Tomorrow I will try my experiments and report here.

Best regards,

Flavio

Em ter., 16 de mar. de 2021 às 16:24, Xiang Xiao
<xi...@gmail.com> escreveu:
>
> Try to remove CONFIG_ARCH_FLOAT_H
>
> On Tue, Mar 16, 2021 at 12:15 PM Flavio Castro Alves Filho <
> flavio.alves@gmail.com> wrote:
>
> > Hello Xiang,
> >
> > It is still not working. The error persists.
> >
> > Here is my defconfig file:
> >
> > #
> > # This file is autogenerated: PLEASE DO NOT EDIT IT.
> > #
> > # You can use "make menuconfig" to make any modifications to the
> > installed .config file.
> > # You can then do "make savedefconfig" to generate a new defconfig
> > file that includes your
> > # modifications.
> > #
> > # CONFIG_ARCH_FPU is not set
> > CONFIG_ARCH="arm"
> > CONFIG_ARCH_BOARD="stm32f4discovery"
> > CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
> > CONFIG_ARCH_CHIP="stm32"
> > CONFIG_ARCH_CHIP_STM32=y
> > CONFIG_ARCH_CHIP_STM32F407VG=y
> > CONFIG_ARCH_FLOAT_H=y
> > CONFIG_ARCH_STACKDUMP=y
> > CONFIG_BOARD_LOOPSPERMSEC=16717
> > CONFIG_BUILTIN=y
> > CONFIG_C99_BOOL8=y
> > CONFIG_DISABLE_MOUNTPOINT=y
> > CONFIG_EXAMPLES_HELLOXX=y
> > CONFIG_HAVE_CXX=y
> > CONFIG_INTELHEX_BINARY=y
> > CONFIG_LIBCXX=y
> > CONFIG_LIBC_FLOATINGPOINT=y
> > CONFIG_LIBC_LOCALTIME=y
> > CONFIG_MAX_TASKS=16
> > CONFIG_MM_REGIONS=2
> > CONFIG_NFILE_DESCRIPTORS=8
> > CONFIG_NSH_BUILTIN_APPS=y
> > CONFIG_NSH_FILEIOSIZE=512
> > CONFIG_PREALLOC_TIMERS=4
> > CONFIG_RAM_SIZE=114688
> > CONFIG_RAM_START=0x20000000
> > CONFIG_RAW_BINARY=y
> > CONFIG_RR_INTERVAL=200
> > CONFIG_SCHED_ONEXIT=y
> > CONFIG_SCHED_ONEXIT_MAX=4
> > CONFIG_SCHED_WAITPID=y
> > CONFIG_SDCLONE_DISABLE=y
> > CONFIG_START_DAY=2
> > CONFIG_START_MONTH=11
> > CONFIG_START_YEAR=2012
> > CONFIG_STM32_JTAG_SW_ENABLE=y
> > CONFIG_STM32_USART2=y
> > CONFIG_SYMTAB_ORDEREDBYNAME=y
> > CONFIG_SYSTEM_NSH=y
> > CONFIG_USART2_RXBUFSIZE=128
> > CONFIG_USART2_SERIAL_CONSOLE=y
> > CONFIG_USART2_TXBUFSIZE=128
> > CONFIG_USER_ENTRYPOINT="nsh_main"
> >
> > Any idea of what is missing?
> >
> > Best regards,
> >
> > Flavio
> >
> > Em ter., 16 de mar. de 2021 às 14:32, Xiang Xiao
> > <xi...@gmail.com> escreveu:
> > >
> > > On Tue, Mar 16, 2021 at 10:20 AM Flavio Castro Alves Filho <
> > > flavio.alves@gmail.com> wrote:
> > >
> > > > Hello Xiang,
> > > >
> > > > Em ter., 16 de mar. de 2021 às 14:01, Xiang Xiao
> > > > <xi...@gmail.com> escreveu:
> > > > >
> > > > > On Tu
> > > > > >
> > > > > This project use the modern C++ feature, so you must enable llvm
> > > > > ibc++(CONFIG_LIBCXX=y)
> > > >
> > > > I tried a new build, executing:
> > > >
> > > > $ make distclean
> > > > $ ./tools/configure.sh -l stm32f4discovery:testlibcxx
> > > > $ make
> > > >
> > > > I can see the library being downloaded from git, but it is not
> > compiling.
> > > >
> > > > In file included from
> > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/random:1637,
> > > >                  from libcxx/src/random.cpp:16:
> > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath: At global scope:
> > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:321:9: error:
> > > > '::signbit' has not been declared
> > > >   321 | using ::signbit;
> > > >       |         ^~~~~~~
> > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:322:9: error:
> > > > '::fpclassify' has not been declared
> > > >   322 | using ::fpclassify;
> > > >       |         ^~~~~~~~~~
> > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:326:9: error:
> > > > '::isnormal' has not been declared
> > > >   326 | using ::isnormal;
> > > >       |         ^~~~~~~~
> > > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:327:9: error:
> > > > '::isgreater' has not been declared
> > > >   327 | using ::isgreater;
> > > >
> > > > How should I solve this issue?
> > > >
> > >
> > > CONFIG_LIBM has to be disabled, since NuttX match library implementation
> > > lacks many standard defined functions which is required by the new libc++
> > > library.
> > >
> > >
> > > >
> > > > > >
> > > > > You need tell compiler stop to search the toolchain provided c++
> > library
> > > > > by -nostdinc++
> > > > >
> > > >
> > > > I believe it will solve my cmake issue.
> > > >
> > > > Best regards,
> > > >
> > > > Flavio
> > > >
> >
> >
> >
> > --
> > Flavio de Castro Alves Filho
> >
> > flavio.alves@gmail.com
> > Twitter: http://twitter.com/#!/fraviofii
> > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
> >



-- 
Flavio de Castro Alves Filho

flavio.alves@gmail.com
Twitter: http://twitter.com/#!/fraviofii
LinkedIn profile: www.linkedin.com/in/flaviocastroalves

Re: Using C++ STL in Nuttx

Posted by Xiang Xiao <xi...@gmail.com>.
Try to remove CONFIG_ARCH_FLOAT_H

On Tue, Mar 16, 2021 at 12:15 PM Flavio Castro Alves Filho <
flavio.alves@gmail.com> wrote:

> Hello Xiang,
>
> It is still not working. The error persists.
>
> Here is my defconfig file:
>
> #
> # This file is autogenerated: PLEASE DO NOT EDIT IT.
> #
> # You can use "make menuconfig" to make any modifications to the
> installed .config file.
> # You can then do "make savedefconfig" to generate a new defconfig
> file that includes your
> # modifications.
> #
> # CONFIG_ARCH_FPU is not set
> CONFIG_ARCH="arm"
> CONFIG_ARCH_BOARD="stm32f4discovery"
> CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
> CONFIG_ARCH_CHIP="stm32"
> CONFIG_ARCH_CHIP_STM32=y
> CONFIG_ARCH_CHIP_STM32F407VG=y
> CONFIG_ARCH_FLOAT_H=y
> CONFIG_ARCH_STACKDUMP=y
> CONFIG_BOARD_LOOPSPERMSEC=16717
> CONFIG_BUILTIN=y
> CONFIG_C99_BOOL8=y
> CONFIG_DISABLE_MOUNTPOINT=y
> CONFIG_EXAMPLES_HELLOXX=y
> CONFIG_HAVE_CXX=y
> CONFIG_INTELHEX_BINARY=y
> CONFIG_LIBCXX=y
> CONFIG_LIBC_FLOATINGPOINT=y
> CONFIG_LIBC_LOCALTIME=y
> CONFIG_MAX_TASKS=16
> CONFIG_MM_REGIONS=2
> CONFIG_NFILE_DESCRIPTORS=8
> CONFIG_NSH_BUILTIN_APPS=y
> CONFIG_NSH_FILEIOSIZE=512
> CONFIG_PREALLOC_TIMERS=4
> CONFIG_RAM_SIZE=114688
> CONFIG_RAM_START=0x20000000
> CONFIG_RAW_BINARY=y
> CONFIG_RR_INTERVAL=200
> CONFIG_SCHED_ONEXIT=y
> CONFIG_SCHED_ONEXIT_MAX=4
> CONFIG_SCHED_WAITPID=y
> CONFIG_SDCLONE_DISABLE=y
> CONFIG_START_DAY=2
> CONFIG_START_MONTH=11
> CONFIG_START_YEAR=2012
> CONFIG_STM32_JTAG_SW_ENABLE=y
> CONFIG_STM32_USART2=y
> CONFIG_SYMTAB_ORDEREDBYNAME=y
> CONFIG_SYSTEM_NSH=y
> CONFIG_USART2_RXBUFSIZE=128
> CONFIG_USART2_SERIAL_CONSOLE=y
> CONFIG_USART2_TXBUFSIZE=128
> CONFIG_USER_ENTRYPOINT="nsh_main"
>
> Any idea of what is missing?
>
> Best regards,
>
> Flavio
>
> Em ter., 16 de mar. de 2021 às 14:32, Xiang Xiao
> <xi...@gmail.com> escreveu:
> >
> > On Tue, Mar 16, 2021 at 10:20 AM Flavio Castro Alves Filho <
> > flavio.alves@gmail.com> wrote:
> >
> > > Hello Xiang,
> > >
> > > Em ter., 16 de mar. de 2021 às 14:01, Xiang Xiao
> > > <xi...@gmail.com> escreveu:
> > > >
> > > > On Tu
> > > > >
> > > > This project use the modern C++ feature, so you must enable llvm
> > > > ibc++(CONFIG_LIBCXX=y)
> > >
> > > I tried a new build, executing:
> > >
> > > $ make distclean
> > > $ ./tools/configure.sh -l stm32f4discovery:testlibcxx
> > > $ make
> > >
> > > I can see the library being downloaded from git, but it is not
> compiling.
> > >
> > > In file included from
> > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/random:1637,
> > >                  from libcxx/src/random.cpp:16:
> > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath: At global scope:
> > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:321:9: error:
> > > '::signbit' has not been declared
> > >   321 | using ::signbit;
> > >       |         ^~~~~~~
> > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:322:9: error:
> > > '::fpclassify' has not been declared
> > >   322 | using ::fpclassify;
> > >       |         ^~~~~~~~~~
> > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:326:9: error:
> > > '::isnormal' has not been declared
> > >   326 | using ::isnormal;
> > >       |         ^~~~~~~~
> > > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:327:9: error:
> > > '::isgreater' has not been declared
> > >   327 | using ::isgreater;
> > >
> > > How should I solve this issue?
> > >
> >
> > CONFIG_LIBM has to be disabled, since NuttX match library implementation
> > lacks many standard defined functions which is required by the new libc++
> > library.
> >
> >
> > >
> > > > >
> > > > You need tell compiler stop to search the toolchain provided c++
> library
> > > > by -nostdinc++
> > > >
> > >
> > > I believe it will solve my cmake issue.
> > >
> > > Best regards,
> > >
> > > Flavio
> > >
>
>
>
> --
> Flavio de Castro Alves Filho
>
> flavio.alves@gmail.com
> Twitter: http://twitter.com/#!/fraviofii
> LinkedIn profile: www.linkedin.com/in/flaviocastroalves
>

Re: Using C++ STL in Nuttx

Posted by Flavio Castro Alves Filho <fl...@gmail.com>.
Hello Xiang,

It is still not working. The error persists.

Here is my defconfig file:

#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the
installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig
file that includes your
# modifications.
#
# CONFIG_ARCH_FPU is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="stm32f4discovery"
CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
CONFIG_ARCH_CHIP="stm32"
CONFIG_ARCH_CHIP_STM32=y
CONFIG_ARCH_CHIP_STM32F407VG=y
CONFIG_ARCH_FLOAT_H=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_BUILTIN=y
CONFIG_C99_BOOL8=y
CONFIG_DISABLE_MOUNTPOINT=y
CONFIG_EXAMPLES_HELLOXX=y
CONFIG_HAVE_CXX=y
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBCXX=y
CONFIG_LIBC_FLOATINGPOINT=y
CONFIG_LIBC_LOCALTIME=y
CONFIG_MAX_TASKS=16
CONFIG_MM_REGIONS=2
CONFIG_NFILE_DESCRIPTORS=8
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_PREALLOC_TIMERS=4
CONFIG_RAM_SIZE=114688
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_ONEXIT=y
CONFIG_SCHED_ONEXIT_MAX=4
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_START_DAY=2
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2012
CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_USART2=y
CONFIG_SYMTAB_ORDEREDBYNAME=y
CONFIG_SYSTEM_NSH=y
CONFIG_USART2_RXBUFSIZE=128
CONFIG_USART2_SERIAL_CONSOLE=y
CONFIG_USART2_TXBUFSIZE=128
CONFIG_USER_ENTRYPOINT="nsh_main"

Any idea of what is missing?

Best regards,

Flavio

Em ter., 16 de mar. de 2021 às 14:32, Xiang Xiao
<xi...@gmail.com> escreveu:
>
> On Tue, Mar 16, 2021 at 10:20 AM Flavio Castro Alves Filho <
> flavio.alves@gmail.com> wrote:
>
> > Hello Xiang,
> >
> > Em ter., 16 de mar. de 2021 às 14:01, Xiang Xiao
> > <xi...@gmail.com> escreveu:
> > >
> > > On Tu
> > > >
> > > This project use the modern C++ feature, so you must enable llvm
> > > ibc++(CONFIG_LIBCXX=y)
> >
> > I tried a new build, executing:
> >
> > $ make distclean
> > $ ./tools/configure.sh -l stm32f4discovery:testlibcxx
> > $ make
> >
> > I can see the library being downloaded from git, but it is not compiling.
> >
> > In file included from
> > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/random:1637,
> >                  from libcxx/src/random.cpp:16:
> > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath: At global scope:
> > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:321:9: error:
> > '::signbit' has not been declared
> >   321 | using ::signbit;
> >       |         ^~~~~~~
> > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:322:9: error:
> > '::fpclassify' has not been declared
> >   322 | using ::fpclassify;
> >       |         ^~~~~~~~~~
> > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:326:9: error:
> > '::isnormal' has not been declared
> >   326 | using ::isnormal;
> >       |         ^~~~~~~~
> > /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:327:9: error:
> > '::isgreater' has not been declared
> >   327 | using ::isgreater;
> >
> > How should I solve this issue?
> >
>
> CONFIG_LIBM has to be disabled, since NuttX match library implementation
> lacks many standard defined functions which is required by the new libc++
> library.
>
>
> >
> > > >
> > > You need tell compiler stop to search the toolchain provided c++ library
> > > by -nostdinc++
> > >
> >
> > I believe it will solve my cmake issue.
> >
> > Best regards,
> >
> > Flavio
> >



-- 
Flavio de Castro Alves Filho

flavio.alves@gmail.com
Twitter: http://twitter.com/#!/fraviofii
LinkedIn profile: www.linkedin.com/in/flaviocastroalves

Re: Using C++ STL in Nuttx

Posted by Xiang Xiao <xi...@gmail.com>.
On Tue, Mar 16, 2021 at 10:20 AM Flavio Castro Alves Filho <
flavio.alves@gmail.com> wrote:

> Hello Xiang,
>
> Em ter., 16 de mar. de 2021 às 14:01, Xiang Xiao
> <xi...@gmail.com> escreveu:
> >
> > On Tu
> > >
> > This project use the modern C++ feature, so you must enable llvm
> > ibc++(CONFIG_LIBCXX=y)
>
> I tried a new build, executing:
>
> $ make distclean
> $ ./tools/configure.sh -l stm32f4discovery:testlibcxx
> $ make
>
> I can see the library being downloaded from git, but it is not compiling.
>
> In file included from
> /home/ubuntu/nuttx_ws/nuttx/include/libcxx/random:1637,
>                  from libcxx/src/random.cpp:16:
> /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath: At global scope:
> /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:321:9: error:
> '::signbit' has not been declared
>   321 | using ::signbit;
>       |         ^~~~~~~
> /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:322:9: error:
> '::fpclassify' has not been declared
>   322 | using ::fpclassify;
>       |         ^~~~~~~~~~
> /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:326:9: error:
> '::isnormal' has not been declared
>   326 | using ::isnormal;
>       |         ^~~~~~~~
> /home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:327:9: error:
> '::isgreater' has not been declared
>   327 | using ::isgreater;
>
> How should I solve this issue?
>

CONFIG_LIBM has to be disabled, since NuttX match library implementation
lacks many standard defined functions which is required by the new libc++
library.


>
> > >
> > You need tell compiler stop to search the toolchain provided c++ library
> > by -nostdinc++
> >
>
> I believe it will solve my cmake issue.
>
> Best regards,
>
> Flavio
>

Re: Using C++ STL in Nuttx

Posted by Flavio Castro Alves Filho <fl...@gmail.com>.
Hello Xiang,

Em ter., 16 de mar. de 2021 às 14:01, Xiang Xiao
<xi...@gmail.com> escreveu:
>
> On Tu
> >
> This project use the modern C++ feature, so you must enable llvm
> ibc++(CONFIG_LIBCXX=y)

I tried a new build, executing:

$ make distclean
$ ./tools/configure.sh -l stm32f4discovery:testlibcxx
$ make

I can see the library being downloaded from git, but it is not compiling.

In file included from /home/ubuntu/nuttx_ws/nuttx/include/libcxx/random:1637,
                 from libcxx/src/random.cpp:16:
/home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath: At global scope:
/home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:321:9: error:
'::signbit' has not been declared
  321 | using ::signbit;
      |         ^~~~~~~
/home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:322:9: error:
'::fpclassify' has not been declared
  322 | using ::fpclassify;
      |         ^~~~~~~~~~
/home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:326:9: error:
'::isnormal' has not been declared
  326 | using ::isnormal;
      |         ^~~~~~~~
/home/ubuntu/nuttx_ws/nuttx/include/libcxx/cmath:327:9: error:
'::isgreater' has not been declared
  327 | using ::isgreater;

How should I solve this issue?

> >
> You need tell compiler stop to search the toolchain provided c++ library
> by -nostdinc++
>

I believe it will solve my cmake issue.

Best regards,

Flavio

Re: Using C++ STL in Nuttx

Posted by Xiang Xiao <xi...@gmail.com>.
On Tue, Mar 16, 2021 at 9:12 AM Flavio Castro Alves Filho <
flavio.alves@gmail.com> wrote:

> Concerning cxx or cpp ... I have to tell you that I was not used for
> cxx ... but it is not a problem anyway.
>
> What is disturbing me now is that there are problems regarding newlib
> c++ and uClib++.
>
> I tried to add this json project: https://github.com/nlohmann/json, in
> single header mode.
>
>
This project use the modern C++ feature, so you must enable llvm
ibc++(CONFIG_LIBCXX=y)


> I am facing the following error:
>
> CXX:  Log.cxx
> make[1]: 'libc.a' is up to date.
> make[1]: Leaving directory '/home/ubuntu/nuttx_ws/nuttx/libs/libc'
> make[3]: Nothing to be done for 'all'.
> make[3]: Leaving directory '/home/ubuntu/nuttx_ws/apps/platform'
> In file included from
> /usr/include/newlib/c++/9.2.1/bits/hashtable_policy.h:35,
>                  from /usr/include/newlib/c++/9.2.1/bits/hashtable.h:35,
>                  from /usr/include/newlib/c++/9.2.1/unordered_map:46,
>                  from json.hpp:70,
>                  from Log.cxx:2:
> /home/ubuntu/nuttx_ws/nuttx/include/uClibc++/limits:24:2: warning:
> #warning limits header is nowhere complete or accurate [-Wcpp]
>    24 | #warning limits header is nowhere complete or accurate
>       |  ^~~~~~~
> In file included from /usr/include/newlib/c++/9.2.1/bits/stl_algobase.h:61,
>                  from /usr/include/newlib/c++/9.2.1/array:40,
>                  from json.hpp:62,
>                  from Log.cxx:2:
> /usr/include/newlib/c++/9.2.1/bits/cpp_type_traits.h:73:10: error:
> redefinition of 'struct std::__true_type'
>    73 |   struct __true_type { };
>       |          ^~~~~~~~~~~
> In file included from
> /home/ubuntu/nuttx_ws/nuttx/include/uClibc++/vector:26,
>                  from
> /home/ubuntu/nuttx_ws/nuttx/include/uClibc++/string:25,
>                  from
> /home/ubuntu/nuttx_ws/nuttx/include/uClibc++/locale:22,
>                  from /home/ubuntu/nuttx_ws/nuttx/include/uClibc++/ios:22,
>                  from
> /home/ubuntu/nuttx_ws/nuttx/include/uClibc++/iostream:26,
>                  from Log.h:4,
>                  from Log.cxx:1:
>
>
you shouldn't select CONFIG_UCLIBCXX=y


> How should I address this kind of problem?
>
>
You need tell compiler stop to search the toolchain provided c++ library
by -nostdinc++


> Best regards,
>
> Flavio
>
> Em ter., 16 de mar. de 2021 às 12:34, Xiang Xiao
> <xi...@gmail.com> escreveu:
> >
> > On Tue, Mar 16, 2021 at 11:24 PM Gregory Nutt <sp...@gmail.com>
> wrote:
> >
> > >
> > > >> I had to change my file names, from cpp to cxx. Is it mandatory to
> > > >> change the file extension to use C++?
> > > >>
> > > > No, .cxx is just the default extension. You can change the default
> value
> > > in
> > > > Makefile like this:
> > > > CXXEXT=.cpp
> > > > But this feature just exists in Makefile under the apps folder.
> > >
> > > Again, the coding standard does currently require the .cxx extension:
> > >
> https://cwiki.apache.org/confluence/display/NUTTX/Coding+Standard#cplusplus
> > >
> > > I would consider that up for discussion and subject to community
> > > concurrence.  Which ever is selected, the extension should be used
> > > consistently.  All C++ files under apps follow the coding standard for
> > > file naming EXCEPT for some ELF loadable modules and some test-releated
> > > files that are currently in violation of the coding standard:
> > >
> > > ./examples/elf/tests/helloxx/hello++1.cpp
> > > ./examples/elf/tests/helloxx/hello++2.cpp
> > > ./examples/elf/tests/helloxx/hello++3.cpp
> > > ./examples/elf/tests/helloxx/hello++4.cpp
> > > ./examples/elf/tests/helloxx/hello++5.cpp
> > > ./examples/nxflat/tests/hello++/hello++1.cpp
> > > ./examples/nxflat/tests/hello++/hello++2.cpp
> > > ./examples/nxflat/tests/hello++/hello++3.cpp
> > > ./examples/nxflat/tests/hello++/hello++4.cpp
> > > ./testing/irtest/cmd.cpp
> > > ./testing/irtest/enum.cpp
> > > ./testing/irtest/main.cpp
> > >
> > >
> > All these sources can change to .cxx suffix.
> >
> >
> > > We do require strong motivation before any changes are made to the
> > > coding stardard.  We want to avoid the case where the coding standard
> is
> > > changed to meet the preferences a single person or a single
> > > organization.  Any changes must have a broad community mandate.
> > >
> > >
> > CXXEXT is for code which doesn't plan to be upstreamed. Actually, after
> > joining Apache, I don't think we can freely include 3rd party code into
> > repo like before even with the compatible license and not in active
> > development. So
>
>
>
> --
> Flavio de Castro Alves Filho
>
> flavio.alves@gmail.com
> Twitter: http://twitter.com/#!/fraviofii
> LinkedIn profile: www.linkedin.com/in/flaviocastroalves
>

Re: Using C++ STL in Nuttx

Posted by Flavio Castro Alves Filho <fl...@gmail.com>.
Concerning cxx or cpp ... I have to tell you that I was not used for
cxx ... but it is not a problem anyway.

What is disturbing me now is that there are problems regarding newlib
c++ and uClib++.

I tried to add this json project: https://github.com/nlohmann/json, in
single header mode.

I am facing the following error:

CXX:  Log.cxx
make[1]: 'libc.a' is up to date.
make[1]: Leaving directory '/home/ubuntu/nuttx_ws/nuttx/libs/libc'
make[3]: Nothing to be done for 'all'.
make[3]: Leaving directory '/home/ubuntu/nuttx_ws/apps/platform'
In file included from /usr/include/newlib/c++/9.2.1/bits/hashtable_policy.h:35,
                 from /usr/include/newlib/c++/9.2.1/bits/hashtable.h:35,
                 from /usr/include/newlib/c++/9.2.1/unordered_map:46,
                 from json.hpp:70,
                 from Log.cxx:2:
/home/ubuntu/nuttx_ws/nuttx/include/uClibc++/limits:24:2: warning:
#warning limits header is nowhere complete or accurate [-Wcpp]
   24 | #warning limits header is nowhere complete or accurate
      |  ^~~~~~~
In file included from /usr/include/newlib/c++/9.2.1/bits/stl_algobase.h:61,
                 from /usr/include/newlib/c++/9.2.1/array:40,
                 from json.hpp:62,
                 from Log.cxx:2:
/usr/include/newlib/c++/9.2.1/bits/cpp_type_traits.h:73:10: error:
redefinition of 'struct std::__true_type'
   73 |   struct __true_type { };
      |          ^~~~~~~~~~~
In file included from /home/ubuntu/nuttx_ws/nuttx/include/uClibc++/vector:26,
                 from /home/ubuntu/nuttx_ws/nuttx/include/uClibc++/string:25,
                 from /home/ubuntu/nuttx_ws/nuttx/include/uClibc++/locale:22,
                 from /home/ubuntu/nuttx_ws/nuttx/include/uClibc++/ios:22,
                 from /home/ubuntu/nuttx_ws/nuttx/include/uClibc++/iostream:26,
                 from Log.h:4,
                 from Log.cxx:1:

How should I address this kind of problem?

Best regards,

Flavio

Em ter., 16 de mar. de 2021 às 12:34, Xiang Xiao
<xi...@gmail.com> escreveu:
>
> On Tue, Mar 16, 2021 at 11:24 PM Gregory Nutt <sp...@gmail.com> wrote:
>
> >
> > >> I had to change my file names, from cpp to cxx. Is it mandatory to
> > >> change the file extension to use C++?
> > >>
> > > No, .cxx is just the default extension. You can change the default value
> > in
> > > Makefile like this:
> > > CXXEXT=.cpp
> > > But this feature just exists in Makefile under the apps folder.
> >
> > Again, the coding standard does currently require the .cxx extension:
> > https://cwiki.apache.org/confluence/display/NUTTX/Coding+Standard#cplusplus
> >
> > I would consider that up for discussion and subject to community
> > concurrence.  Which ever is selected, the extension should be used
> > consistently.  All C++ files under apps follow the coding standard for
> > file naming EXCEPT for some ELF loadable modules and some test-releated
> > files that are currently in violation of the coding standard:
> >
> > ./examples/elf/tests/helloxx/hello++1.cpp
> > ./examples/elf/tests/helloxx/hello++2.cpp
> > ./examples/elf/tests/helloxx/hello++3.cpp
> > ./examples/elf/tests/helloxx/hello++4.cpp
> > ./examples/elf/tests/helloxx/hello++5.cpp
> > ./examples/nxflat/tests/hello++/hello++1.cpp
> > ./examples/nxflat/tests/hello++/hello++2.cpp
> > ./examples/nxflat/tests/hello++/hello++3.cpp
> > ./examples/nxflat/tests/hello++/hello++4.cpp
> > ./testing/irtest/cmd.cpp
> > ./testing/irtest/enum.cpp
> > ./testing/irtest/main.cpp
> >
> >
> All these sources can change to .cxx suffix.
>
>
> > We do require strong motivation before any changes are made to the
> > coding stardard.  We want to avoid the case where the coding standard is
> > changed to meet the preferences a single person or a single
> > organization.  Any changes must have a broad community mandate.
> >
> >
> CXXEXT is for code which doesn't plan to be upstreamed. Actually, after
> joining Apache, I don't think we can freely include 3rd party code into
> repo like before even with the compatible license and not in active
> development. So



-- 
Flavio de Castro Alves Filho

flavio.alves@gmail.com
Twitter: http://twitter.com/#!/fraviofii
LinkedIn profile: www.linkedin.com/in/flaviocastroalves

Re: Using C++ STL in Nuttx

Posted by Xiang Xiao <xi...@gmail.com>.
On Tue, Mar 16, 2021 at 11:24 PM Gregory Nutt <sp...@gmail.com> wrote:

>
> >> I had to change my file names, from cpp to cxx. Is it mandatory to
> >> change the file extension to use C++?
> >>
> > No, .cxx is just the default extension. You can change the default value
> in
> > Makefile like this:
> > CXXEXT=.cpp
> > But this feature just exists in Makefile under the apps folder.
>
> Again, the coding standard does currently require the .cxx extension:
> https://cwiki.apache.org/confluence/display/NUTTX/Coding+Standard#cplusplus
>
> I would consider that up for discussion and subject to community
> concurrence.  Which ever is selected, the extension should be used
> consistently.  All C++ files under apps follow the coding standard for
> file naming EXCEPT for some ELF loadable modules and some test-releated
> files that are currently in violation of the coding standard:
>
> ./examples/elf/tests/helloxx/hello++1.cpp
> ./examples/elf/tests/helloxx/hello++2.cpp
> ./examples/elf/tests/helloxx/hello++3.cpp
> ./examples/elf/tests/helloxx/hello++4.cpp
> ./examples/elf/tests/helloxx/hello++5.cpp
> ./examples/nxflat/tests/hello++/hello++1.cpp
> ./examples/nxflat/tests/hello++/hello++2.cpp
> ./examples/nxflat/tests/hello++/hello++3.cpp
> ./examples/nxflat/tests/hello++/hello++4.cpp
> ./testing/irtest/cmd.cpp
> ./testing/irtest/enum.cpp
> ./testing/irtest/main.cpp
>
>
All these sources can change to .cxx suffix.


> We do require strong motivation before any changes are made to the
> coding stardard.  We want to avoid the case where the coding standard is
> changed to meet the preferences a single person or a single
> organization.  Any changes must have a broad community mandate.
>
>
CXXEXT is for code which doesn't plan to be upstreamed. Actually, after
joining Apache, I don't think we can freely include 3rd party code into
repo like before even with the compatible license and not in active
development. So

Re: Using C++ STL in Nuttx

Posted by Alan Carvalho de Assis <ac...@gmail.com>.
On 3/16/21, Gregory Nutt <sp...@gmail.com> wrote:
>
>>> I had to change my file names, from cpp to cxx. Is it mandatory to
>>> change the file extension to use C++?
>>>
>> No, .cxx is just the default extension. You can change the default value
>> in
>> Makefile like this:
>> CXXEXT=.cpp
>> But this feature just exists in Makefile under the apps folder.
>
> Again, the coding standard does currently require the .cxx extension:
> https://cwiki.apache.org/confluence/display/NUTTX/Coding+Standard#cplusplus
>
> I would consider that up for discussion and subject to community
> concurrence.  Which ever is selected, the extension should be used
> consistently.  All C++ files under apps follow the coding standard for
> file naming EXCEPT for some ELF loadable modules and some test-releated
> files that are currently in violation of the coding standard:
>
> ./examples/elf/tests/helloxx/hello++1.cpp
> ./examples/elf/tests/helloxx/hello++2.cpp
> ./examples/elf/tests/helloxx/hello++3.cpp
> ./examples/elf/tests/helloxx/hello++4.cpp
> ./examples/elf/tests/helloxx/hello++5.cpp
> ./examples/nxflat/tests/hello++/hello++1.cpp
> ./examples/nxflat/tests/hello++/hello++2.cpp
> ./examples/nxflat/tests/hello++/hello++3.cpp
> ./examples/nxflat/tests/hello++/hello++4.cpp
> ./testing/irtest/cmd.cpp
> ./testing/irtest/enum.cpp
> ./testing/irtest/main.cpp
>
> We do require strong motivation before any changes are made to the
> coding stardard.  We want to avoid the case where the coding standard is
> changed to meet the preferences a single person or a single
> organization.  Any changes must have a broad community mandate.
>

I found a small discussion here:

https://forums.codeguru.com/showthread.php?397010-What-s-with-*-cxx-files-instead-of-*-cpp

In general: cpp is from Windows side and .cxx is from Unix side. I
think we are in the Unix side! :-)

The .cpp extension is more known, but it could be confused with the C
or C++ Pre-Processor extension.

BR,

Alan

Re: Using C++ STL in Nuttx

Posted by Gregory Nutt <sp...@gmail.com>.
>> I had to change my file names, from cpp to cxx. Is it mandatory to
>> change the file extension to use C++?
>>
> No, .cxx is just the default extension. You can change the default value in
> Makefile like this:
> CXXEXT=.cpp
> But this feature just exists in Makefile under the apps folder.

Again, the coding standard does currently require the .cxx extension: 
https://cwiki.apache.org/confluence/display/NUTTX/Coding+Standard#cplusplus

I would consider that up for discussion and subject to community 
concurrence.  Which ever is selected, the extension should be used 
consistently.  All C++ files under apps follow the coding standard for 
file naming EXCEPT for some ELF loadable modules and some test-releated 
files that are currently in violation of the coding standard:

./examples/elf/tests/helloxx/hello++1.cpp
./examples/elf/tests/helloxx/hello++2.cpp
./examples/elf/tests/helloxx/hello++3.cpp
./examples/elf/tests/helloxx/hello++4.cpp
./examples/elf/tests/helloxx/hello++5.cpp
./examples/nxflat/tests/hello++/hello++1.cpp
./examples/nxflat/tests/hello++/hello++2.cpp
./examples/nxflat/tests/hello++/hello++3.cpp
./examples/nxflat/tests/hello++/hello++4.cpp
./testing/irtest/cmd.cpp
./testing/irtest/enum.cpp
./testing/irtest/main.cpp

We do require strong motivation before any changes are made to the 
coding stardard.  We want to avoid the case where the coding standard is 
changed to meet the preferences a single person or a single 
organization.  Any changes must have a broad community mandate.



Re: Using C++ STL in Nuttx

Posted by Xiang Xiao <xi...@gmail.com>.
On Tue, Mar 16, 2021 at 10:37 PM Flavio Castro Alves Filho <
flavio.alves@gmail.com> wrote:

> Hello Xiang,
>
> I could execute my example inside the NuttX infrastructure.
>
> I had to change my file names, from cpp to cxx. Is it mandatory to
> change the file extension to use C++?
>
>
No, .cxx is just the default extension. You can change the default value in
Makefile like this:
CXXEXT=.cpp
But this feature just exists in Makefile under the apps folder.


> Reviewing my cmake file, it seems that it is not using uClibc++ to
> build, but newlib ... probably that's the reason for the linking
> error. I need to figure out how to address this. If you have any
> suggestions, please let me know.
>
> Best regards,
>
> Flavio
>
>
> Em seg., 15 de mar. de 2021 às 08:24, Flavio Castro Alves Filho
> <fl...@gmail.com> escreveu:
> >
> > Hello Xiang,
> >
> > Thank you for your fast response.
> >
> > I was trying to build out of the NuttX structure, using NuttX as a
> library.
> >
> > I tested and checked what you showed and it worked.
> >
> > I exported the configuration (running make export and uncompressing
> > the zip file into my environment) and tried to build again and I it is
> > still not compiling.
> >
> > Finally, I added the '#include <nuttx/config.h> and it is still not
> working.
> >
> > I wil test now inside the NuttX structure.
> >
> > Thank you very much.
> >
> > Best regards,
> >
> > Flavio
> >
> > Em seg., 15 de mar. de 2021 às 07:14, Xiang Xiao
> > <xi...@gmail.com> escreveu:
> > >
> > > On Mon, Mar 15, 2021 at 6:00 PM Flavio Castro Alves Filho <
> > > flavio.alves@gmail.com> wrote:
> > >
> > > > Hello,
> > > >
> > > > I am trying to use STL in a simple C++ Hello project and I am getting
> > > > compilation error.s
> > > >
> > > > Is STL supported in NuttX? Can I use it?
> > > >
> > > >
> > > Yes, you can. Please reference the following config and Make.defs to
> setup
> > > your C++ environment:
> > > nuttx/boards/arm/stm32/stm32f4discovery/configs/cxxtest/defconfig
> > > nuttx/boards/sim/sim/sim/configs/cxxtest/defconfig
> > > nuttx/nuttx/boards/sim/sim/sim/configs/libcxxtest/defconfig
> > >
> > >
> > > > Here is my sample code:
> > > >
> > > > === Hello.cpp ===
> > > > #include <stdio.h>
> > > > #include "HelloWorld.h"
> > > >
> > > > CHelloWorld::CHelloWorld() {
> > > >     mSecret = 42;
> > > >     printf("Constructor: mSecret=%d\n",mSecret);
> > > > }
> > > >
> > > > CHelloWorld::~CHelloWorld() {
> > > >
> > > > }
> > > >
> > > > bool CHelloWorld::HelloWorld(void) {
> > > >     printf("HelloWorld: mSecret=%d\n",mSecret);
> > > >
> > > >     if (mSecret == 42) {
> > > >         printf("CHelloWorld: HelloWorld: Hello, world!");
> > > >         return true;
> > > >     }
> > > >     else {
> > > >         printf("CHelloWorld: HelloWorld: CONSTRUCTION FAILED!\n");
> > > >         return false;
> > > >     }
> > > > }
> > > > =========
> > > >
> > > > === Hello.h ===
> > > > class CHelloWorld
> > > > {
> > > >     public:
> > > >         CHelloWorld();
> > > >         ~CHelloWorld();
> > > >         bool HelloWorld(void);
> > > >     private:
> > > >         int mSecret;
> > > > };
> > > > =========
> > > >
> > > > === Log.cpp ===
> > > > #include "Log.h"
> > > > #include <stdio.h>
> > > > #include <string>
> > > >
> > > > void Log::print(std::string_view message) {
> > > >
> > > >     FILE *fp = fopen("/dev/ttyS0", "w");
> > > >     if (fp == NULL) {
> > > >         printf("Error opening serial port!\n");
> > > >         return;
> > > >     }
> > > >
> > > >     std::string msgStr { message };
> > > >
> > > >     /* Try to force input data on stdin */
> > > >     fwrite(msgStr.c_str(), sizeof(char), message.length(), fp);
> > > >
> > > >     fclose(fp);
> > > > }
> > > > =========
> > > >
> > > > === Log.h ===
> > > > #include <string_view>
> > > >
> > > > class Log {
> > > > public:
> > > >     static void print(std::string_view message);
> > > > };
> > > > =========
> > > >
> > > > And there the compilation error:
> > > > =========
> > > > -- Build files have been written to:
> /home/ubuntu/nuttx-apps/hellocpp/build
> > > > [4/4] Linking CXX executable src/hellocpp
> > > > FAILED: src/hellocpp
> > > > : && arm-none-eabi-ld --entry=__start -nostartfiles -nostdlib
> > > > -nodefaultlibs
> > > >
> -T/home/ubuntu/nuttx-apps/hellocpp/nuttx-export-9.1.0/scripts/ld.script
> > > > -o hellocpp.elf src/CMakeFiles/hellocpp.dir/HelloWorld.cpp.o
> > > > src/CMakeFiles/hellocpp.dir/Log.cpp.o
> > > > src/CMakeFiles/hellocpp.dir/main.cpp.o
> > > > -L/home/ubuntu/nuttx-apps/hellocpp/src/hellocpp
> > > > -L/home/ubuntu/nuttx-apps/hellocpp/nuttx-export-9.1.0/libs
> > > > --start-group  -lc  -larch  -lbinfmt  -lboard  -lboards  -ldrivers
> > > > -lfs  -lmm  -lsched  -lxx  -lnet  -lsupc++
> > > > /usr/lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/libgcc.a
> > > > --end-group && cd /home/ubuntu/nuttx-apps/hellocpp/build/src &&
> > > > arm-none-eabi-objcopy -S -O binary
> > > > /home/ubuntu/nuttx-apps/hellocpp/build/hellocpp.elf
> > > > /home/ubuntu/nuttx-apps/hellocpp/build/hellocpp.bin
> > > > arm-none-eabi-ld: src/CMakeFiles/hellocpp.dir/Log.cpp.o: in function
> > > > `void std::__cxx11::basic_string<char, std::char_traits<char>,
> > > > std::allocator<char> >::_M_construct<char const*>(char const*, char
> > > > const*, std::forward_iterator_tag)':
> > > > /usr/include/newlib/c++/9.2.1/bits/basic_string.tcc:212: undefined
> > > > reference to `std::__throw_logic_error(char const*)'
> > > > arm-none-eabi-ld:
> > > > /usr/include/newlib/c++/9.2.1/bits/basic_string.tcc:219: undefined
> > > > reference to `std::__cxx11::basic_string<char,
> std::char_traits<char>,
> > > > std::allocator<char> >::_M_create(unsigned int&, unsigned int)'
> > > > arm-none-eabi-ld:
> > > > /usr/include/newlib/c++/9.2.1/bits/basic_string.tcc:225: undefined
> > > > reference to `std::__cxx11::basic_string<char,
> std::char_traits<char>,
> > > > std::allocator<char> >::_S_copy_chars(char*, char const*, char
> > > > const*)'
> > > > arm-none-eabi-ld: src/CMakeFiles/hellocpp.dir/Log.cpp.o: in function
> > > > `std::__cxx11::basic_string<char, std::char_traits<char>,
> > > > std::allocator<char> >::~basic_string()':
> > > > /usr/include/newlib/c++/9.2.1/bits/basic_string.h:658: undefined
> > > > reference to `std::__cxx11::basic_string<char,
> std::char_traits<char>,
> > > > std::allocator<char> >::_M_dispose()'
> > > > arm-none-eabi-ld:
> > > > /usr/include/newlib/c++/9.2.1/bits/basic_string.h:658: undefined
> > > > reference to `std::__cxx11::basic_string<char,
> std::char_traits<char>,
> > > > std::allocator<char> >::_M_dispose()'
> > > > ninja: build stopped: subcommand failed.
> > > > make[1]: *** [Makefile:13: _build] Error 1
> > > > make[1]: Leaving directory '/home/ubuntu/nuttx-apps/hellocpp'
> > > > make: *** [Makefile:25: default] Error 2
> > > > =========
> > > >
> > > > My CMakelists:
> > > >
> > > > === CMakeLists.txt ===
> > > > cmake_minimum_required(VERSION 3.2...3.15)
> > > >
> > > > project(hellocpp
> > > >     VERSION 1.0
> > > >     DESCRIPTION "Hello world C++ Nuttx"
> > > > )
> > > >
> > > > set(CMAKE_CXX_STANDARD 17)
> > > > set(CMAKE_CXX_STANDARD_REQUIRED ON)
> > > > set(CMAKE_C_STANDARD 99)
> > > >
> > > > set(NUTTX_PATH "${CMAKE_SOURCE_DIR}/nuttx-export-9.1.0")
> > > >
> > > > include(cmake/phigw.cmake)
> > > >
> > > > set(AC_COMMON_FLAGS "${AC_COMMON_FLAGS} -fno-builtin -Wall -Wshadow
> > > > -Wundef -g")
> > > >
> > > > set(AC_DEFINES "${AC_DEFINES} -DCONFIG_WCHAR_BUILTIN")
> > > >
> > > > include_directories(
> > > >     src
> > > >     ${NUTTX_PATH}/include
> > > >     ${NUTTX_PATH}/arch/chip
> > > > )
> > > >
> > > > set(EXE_NAME hellocpp)
> > > >
> > > > set(CMAKE_CXX_FLAGS "${AC_HW_FLAGS} ${AC_DEFINES} ${AC_COMMON_FLAGS}
> > > > ${AC_CXX_EXTRA_FLAGS}")
> > > > if (PARAM_DEBUG)
> > > >     set(CMAKE_CXX_FLAGS     "${CMAKE_CXX_FLAGS} -Os -g")
> > > > else()
> > > >     set(CMAKE_CXX_FLAGS     "${CMAKE_CXX_FLAGS} -Os")
> > > > endif()
> > > >
> > > > set(CMAKE_SKIP_RPATH ON)
> > > > set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_LINKER} ${AC_LINKER_FLAGS} -o
> > > > ${EXE_NAME}.elf <OBJECTS> <LINK_LIBRARIES>")
> > > >
> > > > set(BUILD_SHARED_LIBS OFF)
> > > >
> > > > add_subdirectory(src)
> > > > =========
> > > >
> > > > === src/CMakelists.txt ===
> > > > set(HEADER_FILES
> > > >     HelloWorld.h
> > > >     Log.h
> > > > )
> > > >
> > > > set(SOURCE_FILES
> > > >     HelloWorld.cpp
> > > >     Log.cpp
> > > > )
> > > >
> > > > link_directories(${EXE_NAME} ${NUTTX_PATH}/libs)
> > > >
> > > > add_executable(${EXE_NAME} ${SOURCE_FILES} main.cpp ${HEADER_FILES})
> > > >
> > > > add_custom_command(
> > > >     TARGET ${EXE_NAME}
> > > >     POST_BUILD
> > > >     COMMAND ${CMAKE_OBJCOPY} ARGS -S -O binary
> > > > ${CMAKE_BINARY_DIR}/${EXE_NAME}.elf
> > > > ${CMAKE_BINARY_DIR}/${EXE_NAME}.bin
> > > > )
> > > >
> > > > target_link_libraries(${EXE_NAME} --start-group)
> > > > target_link_libraries(${EXE_NAME} c)
> > > > target_link_libraries(${EXE_NAME} arch)
> > > > target_link_libraries(${EXE_NAME} binfmt)
> > > > target_link_libraries(${EXE_NAME} board)
> > > > target_link_libraries(${EXE_NAME} boards)
> > > > target_link_libraries(${EXE_NAME} drivers)
> > > > target_link_libraries(${EXE_NAME} fs)
> > > > target_link_libraries(${EXE_NAME} mm)
> > > > target_link_libraries(${EXE_NAME} sched)
> > > > target_link_libraries(${EXE_NAME} xx)
> > > > target_link_libraries(${EXE_NAME} net)
> > > > target_link_libraries(${EXE_NAME} supc++)
> > > > target_link_libraries(${EXE_NAME}
> > > > /usr/lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/libgcc.a)
> > > > target_link_libraries(${EXE_NAME} --end-group)
> > > > =========
> > > >
> > > > I am using Ubuntu 20.04 operating system and the toolchain provided
> > > > from the Ubuntu Repository.
> > > >
> > > > Best regards,
> > > >
> > > > Flavio
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Flavio de Castro Alves Filho
> > > >
> > > > flavio.alves@gmail.com
> > > > Twitter: http://twitter.com/#!/fraviofii
> > > > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
> > > >
> >
> >
> >
> > --
> > Flavio de Castro Alves Filho
> >
> > flavio.alves@gmail.com
> > Twitter: http://twitter.com/#!/fraviofii
> > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
>
>
>
> --
> Flavio de Castro Alves Filho
>
> flavio.alves@gmail.com
> Twitter: http://twitter.com/#!/fraviofii
> LinkedIn profile: www.linkedin.com/in/flaviocastroalves
>

Re: Using C++ STL in Nuttx

Posted by Gregory Nutt <sp...@gmail.com>.
> I had to change my file names, from cpp to cxx. Is it mandatory to
> change the file extension to use C++?
Currently, the .cxx extension is specified in the coding standard: 
*https://cwiki.apache.org/confluence/display/NUTTX/Coding+Standard#cplusplus*

Re: Using C++ STL in Nuttx

Posted by Flavio Castro Alves Filho <fl...@gmail.com>.
Hello Xiang,

I could execute my example inside the NuttX infrastructure.

I had to change my file names, from cpp to cxx. Is it mandatory to
change the file extension to use C++?

Reviewing my cmake file, it seems that it is not using uClibc++ to
build, but newlib ... probably that's the reason for the linking
error. I need to figure out how to address this. If you have any
suggestions, please let me know.

Best regards,

Flavio


Em seg., 15 de mar. de 2021 às 08:24, Flavio Castro Alves Filho
<fl...@gmail.com> escreveu:
>
> Hello Xiang,
>
> Thank you for your fast response.
>
> I was trying to build out of the NuttX structure, using NuttX as a library.
>
> I tested and checked what you showed and it worked.
>
> I exported the configuration (running make export and uncompressing
> the zip file into my environment) and tried to build again and I it is
> still not compiling.
>
> Finally, I added the '#include <nuttx/config.h> and it is still not working.
>
> I wil test now inside the NuttX structure.
>
> Thank you very much.
>
> Best regards,
>
> Flavio
>
> Em seg., 15 de mar. de 2021 às 07:14, Xiang Xiao
> <xi...@gmail.com> escreveu:
> >
> > On Mon, Mar 15, 2021 at 6:00 PM Flavio Castro Alves Filho <
> > flavio.alves@gmail.com> wrote:
> >
> > > Hello,
> > >
> > > I am trying to use STL in a simple C++ Hello project and I am getting
> > > compilation error.s
> > >
> > > Is STL supported in NuttX? Can I use it?
> > >
> > >
> > Yes, you can. Please reference the following config and Make.defs to setup
> > your C++ environment:
> > nuttx/boards/arm/stm32/stm32f4discovery/configs/cxxtest/defconfig
> > nuttx/boards/sim/sim/sim/configs/cxxtest/defconfig
> > nuttx/nuttx/boards/sim/sim/sim/configs/libcxxtest/defconfig
> >
> >
> > > Here is my sample code:
> > >
> > > === Hello.cpp ===
> > > #include <stdio.h>
> > > #include "HelloWorld.h"
> > >
> > > CHelloWorld::CHelloWorld() {
> > >     mSecret = 42;
> > >     printf("Constructor: mSecret=%d\n",mSecret);
> > > }
> > >
> > > CHelloWorld::~CHelloWorld() {
> > >
> > > }
> > >
> > > bool CHelloWorld::HelloWorld(void) {
> > >     printf("HelloWorld: mSecret=%d\n",mSecret);
> > >
> > >     if (mSecret == 42) {
> > >         printf("CHelloWorld: HelloWorld: Hello, world!");
> > >         return true;
> > >     }
> > >     else {
> > >         printf("CHelloWorld: HelloWorld: CONSTRUCTION FAILED!\n");
> > >         return false;
> > >     }
> > > }
> > > =========
> > >
> > > === Hello.h ===
> > > class CHelloWorld
> > > {
> > >     public:
> > >         CHelloWorld();
> > >         ~CHelloWorld();
> > >         bool HelloWorld(void);
> > >     private:
> > >         int mSecret;
> > > };
> > > =========
> > >
> > > === Log.cpp ===
> > > #include "Log.h"
> > > #include <stdio.h>
> > > #include <string>
> > >
> > > void Log::print(std::string_view message) {
> > >
> > >     FILE *fp = fopen("/dev/ttyS0", "w");
> > >     if (fp == NULL) {
> > >         printf("Error opening serial port!\n");
> > >         return;
> > >     }
> > >
> > >     std::string msgStr { message };
> > >
> > >     /* Try to force input data on stdin */
> > >     fwrite(msgStr.c_str(), sizeof(char), message.length(), fp);
> > >
> > >     fclose(fp);
> > > }
> > > =========
> > >
> > > === Log.h ===
> > > #include <string_view>
> > >
> > > class Log {
> > > public:
> > >     static void print(std::string_view message);
> > > };
> > > =========
> > >
> > > And there the compilation error:
> > > =========
> > > -- Build files have been written to: /home/ubuntu/nuttx-apps/hellocpp/build
> > > [4/4] Linking CXX executable src/hellocpp
> > > FAILED: src/hellocpp
> > > : && arm-none-eabi-ld --entry=__start -nostartfiles -nostdlib
> > > -nodefaultlibs
> > > -T/home/ubuntu/nuttx-apps/hellocpp/nuttx-export-9.1.0/scripts/ld.script
> > > -o hellocpp.elf src/CMakeFiles/hellocpp.dir/HelloWorld.cpp.o
> > > src/CMakeFiles/hellocpp.dir/Log.cpp.o
> > > src/CMakeFiles/hellocpp.dir/main.cpp.o
> > > -L/home/ubuntu/nuttx-apps/hellocpp/src/hellocpp
> > > -L/home/ubuntu/nuttx-apps/hellocpp/nuttx-export-9.1.0/libs
> > > --start-group  -lc  -larch  -lbinfmt  -lboard  -lboards  -ldrivers
> > > -lfs  -lmm  -lsched  -lxx  -lnet  -lsupc++
> > > /usr/lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/libgcc.a
> > > --end-group && cd /home/ubuntu/nuttx-apps/hellocpp/build/src &&
> > > arm-none-eabi-objcopy -S -O binary
> > > /home/ubuntu/nuttx-apps/hellocpp/build/hellocpp.elf
> > > /home/ubuntu/nuttx-apps/hellocpp/build/hellocpp.bin
> > > arm-none-eabi-ld: src/CMakeFiles/hellocpp.dir/Log.cpp.o: in function
> > > `void std::__cxx11::basic_string<char, std::char_traits<char>,
> > > std::allocator<char> >::_M_construct<char const*>(char const*, char
> > > const*, std::forward_iterator_tag)':
> > > /usr/include/newlib/c++/9.2.1/bits/basic_string.tcc:212: undefined
> > > reference to `std::__throw_logic_error(char const*)'
> > > arm-none-eabi-ld:
> > > /usr/include/newlib/c++/9.2.1/bits/basic_string.tcc:219: undefined
> > > reference to `std::__cxx11::basic_string<char, std::char_traits<char>,
> > > std::allocator<char> >::_M_create(unsigned int&, unsigned int)'
> > > arm-none-eabi-ld:
> > > /usr/include/newlib/c++/9.2.1/bits/basic_string.tcc:225: undefined
> > > reference to `std::__cxx11::basic_string<char, std::char_traits<char>,
> > > std::allocator<char> >::_S_copy_chars(char*, char const*, char
> > > const*)'
> > > arm-none-eabi-ld: src/CMakeFiles/hellocpp.dir/Log.cpp.o: in function
> > > `std::__cxx11::basic_string<char, std::char_traits<char>,
> > > std::allocator<char> >::~basic_string()':
> > > /usr/include/newlib/c++/9.2.1/bits/basic_string.h:658: undefined
> > > reference to `std::__cxx11::basic_string<char, std::char_traits<char>,
> > > std::allocator<char> >::_M_dispose()'
> > > arm-none-eabi-ld:
> > > /usr/include/newlib/c++/9.2.1/bits/basic_string.h:658: undefined
> > > reference to `std::__cxx11::basic_string<char, std::char_traits<char>,
> > > std::allocator<char> >::_M_dispose()'
> > > ninja: build stopped: subcommand failed.
> > > make[1]: *** [Makefile:13: _build] Error 1
> > > make[1]: Leaving directory '/home/ubuntu/nuttx-apps/hellocpp'
> > > make: *** [Makefile:25: default] Error 2
> > > =========
> > >
> > > My CMakelists:
> > >
> > > === CMakeLists.txt ===
> > > cmake_minimum_required(VERSION 3.2...3.15)
> > >
> > > project(hellocpp
> > >     VERSION 1.0
> > >     DESCRIPTION "Hello world C++ Nuttx"
> > > )
> > >
> > > set(CMAKE_CXX_STANDARD 17)
> > > set(CMAKE_CXX_STANDARD_REQUIRED ON)
> > > set(CMAKE_C_STANDARD 99)
> > >
> > > set(NUTTX_PATH "${CMAKE_SOURCE_DIR}/nuttx-export-9.1.0")
> > >
> > > include(cmake/phigw.cmake)
> > >
> > > set(AC_COMMON_FLAGS "${AC_COMMON_FLAGS} -fno-builtin -Wall -Wshadow
> > > -Wundef -g")
> > >
> > > set(AC_DEFINES "${AC_DEFINES} -DCONFIG_WCHAR_BUILTIN")
> > >
> > > include_directories(
> > >     src
> > >     ${NUTTX_PATH}/include
> > >     ${NUTTX_PATH}/arch/chip
> > > )
> > >
> > > set(EXE_NAME hellocpp)
> > >
> > > set(CMAKE_CXX_FLAGS "${AC_HW_FLAGS} ${AC_DEFINES} ${AC_COMMON_FLAGS}
> > > ${AC_CXX_EXTRA_FLAGS}")
> > > if (PARAM_DEBUG)
> > >     set(CMAKE_CXX_FLAGS     "${CMAKE_CXX_FLAGS} -Os -g")
> > > else()
> > >     set(CMAKE_CXX_FLAGS     "${CMAKE_CXX_FLAGS} -Os")
> > > endif()
> > >
> > > set(CMAKE_SKIP_RPATH ON)
> > > set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_LINKER} ${AC_LINKER_FLAGS} -o
> > > ${EXE_NAME}.elf <OBJECTS> <LINK_LIBRARIES>")
> > >
> > > set(BUILD_SHARED_LIBS OFF)
> > >
> > > add_subdirectory(src)
> > > =========
> > >
> > > === src/CMakelists.txt ===
> > > set(HEADER_FILES
> > >     HelloWorld.h
> > >     Log.h
> > > )
> > >
> > > set(SOURCE_FILES
> > >     HelloWorld.cpp
> > >     Log.cpp
> > > )
> > >
> > > link_directories(${EXE_NAME} ${NUTTX_PATH}/libs)
> > >
> > > add_executable(${EXE_NAME} ${SOURCE_FILES} main.cpp ${HEADER_FILES})
> > >
> > > add_custom_command(
> > >     TARGET ${EXE_NAME}
> > >     POST_BUILD
> > >     COMMAND ${CMAKE_OBJCOPY} ARGS -S -O binary
> > > ${CMAKE_BINARY_DIR}/${EXE_NAME}.elf
> > > ${CMAKE_BINARY_DIR}/${EXE_NAME}.bin
> > > )
> > >
> > > target_link_libraries(${EXE_NAME} --start-group)
> > > target_link_libraries(${EXE_NAME} c)
> > > target_link_libraries(${EXE_NAME} arch)
> > > target_link_libraries(${EXE_NAME} binfmt)
> > > target_link_libraries(${EXE_NAME} board)
> > > target_link_libraries(${EXE_NAME} boards)
> > > target_link_libraries(${EXE_NAME} drivers)
> > > target_link_libraries(${EXE_NAME} fs)
> > > target_link_libraries(${EXE_NAME} mm)
> > > target_link_libraries(${EXE_NAME} sched)
> > > target_link_libraries(${EXE_NAME} xx)
> > > target_link_libraries(${EXE_NAME} net)
> > > target_link_libraries(${EXE_NAME} supc++)
> > > target_link_libraries(${EXE_NAME}
> > > /usr/lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/libgcc.a)
> > > target_link_libraries(${EXE_NAME} --end-group)
> > > =========
> > >
> > > I am using Ubuntu 20.04 operating system and the toolchain provided
> > > from the Ubuntu Repository.
> > >
> > > Best regards,
> > >
> > > Flavio
> > >
> > >
> > >
> > >
> > > --
> > > Flavio de Castro Alves Filho
> > >
> > > flavio.alves@gmail.com
> > > Twitter: http://twitter.com/#!/fraviofii
> > > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
> > >
>
>
>
> --
> Flavio de Castro Alves Filho
>
> flavio.alves@gmail.com
> Twitter: http://twitter.com/#!/fraviofii
> LinkedIn profile: www.linkedin.com/in/flaviocastroalves



--
Flavio de Castro Alves Filho

flavio.alves@gmail.com
Twitter: http://twitter.com/#!/fraviofii
LinkedIn profile: www.linkedin.com/in/flaviocastroalves

Re: Using C++ STL in Nuttx

Posted by Flavio Castro Alves Filho <fl...@gmail.com>.
Hello Xiang,

Thank you for your fast response.

I was trying to build out of the NuttX structure, using NuttX as a library.

I tested and checked what you showed and it worked.

I exported the configuration (running make export and uncompressing
the zip file into my environment) and tried to build again and I it is
still not compiling.

Finally, I added the '#include <nuttx/config.h> and it is still not working.

I wil test now inside the NuttX structure.

Thank you very much.

Best regards,

Flavio

Em seg., 15 de mar. de 2021 às 07:14, Xiang Xiao
<xi...@gmail.com> escreveu:
>
> On Mon, Mar 15, 2021 at 6:00 PM Flavio Castro Alves Filho <
> flavio.alves@gmail.com> wrote:
>
> > Hello,
> >
> > I am trying to use STL in a simple C++ Hello project and I am getting
> > compilation error.s
> >
> > Is STL supported in NuttX? Can I use it?
> >
> >
> Yes, you can. Please reference the following config and Make.defs to setup
> your C++ environment:
> nuttx/boards/arm/stm32/stm32f4discovery/configs/cxxtest/defconfig
> nuttx/boards/sim/sim/sim/configs/cxxtest/defconfig
> nuttx/nuttx/boards/sim/sim/sim/configs/libcxxtest/defconfig
>
>
> > Here is my sample code:
> >
> > === Hello.cpp ===
> > #include <stdio.h>
> > #include "HelloWorld.h"
> >
> > CHelloWorld::CHelloWorld() {
> >     mSecret = 42;
> >     printf("Constructor: mSecret=%d\n",mSecret);
> > }
> >
> > CHelloWorld::~CHelloWorld() {
> >
> > }
> >
> > bool CHelloWorld::HelloWorld(void) {
> >     printf("HelloWorld: mSecret=%d\n",mSecret);
> >
> >     if (mSecret == 42) {
> >         printf("CHelloWorld: HelloWorld: Hello, world!");
> >         return true;
> >     }
> >     else {
> >         printf("CHelloWorld: HelloWorld: CONSTRUCTION FAILED!\n");
> >         return false;
> >     }
> > }
> > =========
> >
> > === Hello.h ===
> > class CHelloWorld
> > {
> >     public:
> >         CHelloWorld();
> >         ~CHelloWorld();
> >         bool HelloWorld(void);
> >     private:
> >         int mSecret;
> > };
> > =========
> >
> > === Log.cpp ===
> > #include "Log.h"
> > #include <stdio.h>
> > #include <string>
> >
> > void Log::print(std::string_view message) {
> >
> >     FILE *fp = fopen("/dev/ttyS0", "w");
> >     if (fp == NULL) {
> >         printf("Error opening serial port!\n");
> >         return;
> >     }
> >
> >     std::string msgStr { message };
> >
> >     /* Try to force input data on stdin */
> >     fwrite(msgStr.c_str(), sizeof(char), message.length(), fp);
> >
> >     fclose(fp);
> > }
> > =========
> >
> > === Log.h ===
> > #include <string_view>
> >
> > class Log {
> > public:
> >     static void print(std::string_view message);
> > };
> > =========
> >
> > And there the compilation error:
> > =========
> > -- Build files have been written to: /home/ubuntu/nuttx-apps/hellocpp/build
> > [4/4] Linking CXX executable src/hellocpp
> > FAILED: src/hellocpp
> > : && arm-none-eabi-ld --entry=__start -nostartfiles -nostdlib
> > -nodefaultlibs
> > -T/home/ubuntu/nuttx-apps/hellocpp/nuttx-export-9.1.0/scripts/ld.script
> > -o hellocpp.elf src/CMakeFiles/hellocpp.dir/HelloWorld.cpp.o
> > src/CMakeFiles/hellocpp.dir/Log.cpp.o
> > src/CMakeFiles/hellocpp.dir/main.cpp.o
> > -L/home/ubuntu/nuttx-apps/hellocpp/src/hellocpp
> > -L/home/ubuntu/nuttx-apps/hellocpp/nuttx-export-9.1.0/libs
> > --start-group  -lc  -larch  -lbinfmt  -lboard  -lboards  -ldrivers
> > -lfs  -lmm  -lsched  -lxx  -lnet  -lsupc++
> > /usr/lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/libgcc.a
> > --end-group && cd /home/ubuntu/nuttx-apps/hellocpp/build/src &&
> > arm-none-eabi-objcopy -S -O binary
> > /home/ubuntu/nuttx-apps/hellocpp/build/hellocpp.elf
> > /home/ubuntu/nuttx-apps/hellocpp/build/hellocpp.bin
> > arm-none-eabi-ld: src/CMakeFiles/hellocpp.dir/Log.cpp.o: in function
> > `void std::__cxx11::basic_string<char, std::char_traits<char>,
> > std::allocator<char> >::_M_construct<char const*>(char const*, char
> > const*, std::forward_iterator_tag)':
> > /usr/include/newlib/c++/9.2.1/bits/basic_string.tcc:212: undefined
> > reference to `std::__throw_logic_error(char const*)'
> > arm-none-eabi-ld:
> > /usr/include/newlib/c++/9.2.1/bits/basic_string.tcc:219: undefined
> > reference to `std::__cxx11::basic_string<char, std::char_traits<char>,
> > std::allocator<char> >::_M_create(unsigned int&, unsigned int)'
> > arm-none-eabi-ld:
> > /usr/include/newlib/c++/9.2.1/bits/basic_string.tcc:225: undefined
> > reference to `std::__cxx11::basic_string<char, std::char_traits<char>,
> > std::allocator<char> >::_S_copy_chars(char*, char const*, char
> > const*)'
> > arm-none-eabi-ld: src/CMakeFiles/hellocpp.dir/Log.cpp.o: in function
> > `std::__cxx11::basic_string<char, std::char_traits<char>,
> > std::allocator<char> >::~basic_string()':
> > /usr/include/newlib/c++/9.2.1/bits/basic_string.h:658: undefined
> > reference to `std::__cxx11::basic_string<char, std::char_traits<char>,
> > std::allocator<char> >::_M_dispose()'
> > arm-none-eabi-ld:
> > /usr/include/newlib/c++/9.2.1/bits/basic_string.h:658: undefined
> > reference to `std::__cxx11::basic_string<char, std::char_traits<char>,
> > std::allocator<char> >::_M_dispose()'
> > ninja: build stopped: subcommand failed.
> > make[1]: *** [Makefile:13: _build] Error 1
> > make[1]: Leaving directory '/home/ubuntu/nuttx-apps/hellocpp'
> > make: *** [Makefile:25: default] Error 2
> > =========
> >
> > My CMakelists:
> >
> > === CMakeLists.txt ===
> > cmake_minimum_required(VERSION 3.2...3.15)
> >
> > project(hellocpp
> >     VERSION 1.0
> >     DESCRIPTION "Hello world C++ Nuttx"
> > )
> >
> > set(CMAKE_CXX_STANDARD 17)
> > set(CMAKE_CXX_STANDARD_REQUIRED ON)
> > set(CMAKE_C_STANDARD 99)
> >
> > set(NUTTX_PATH "${CMAKE_SOURCE_DIR}/nuttx-export-9.1.0")
> >
> > include(cmake/phigw.cmake)
> >
> > set(AC_COMMON_FLAGS "${AC_COMMON_FLAGS} -fno-builtin -Wall -Wshadow
> > -Wundef -g")
> >
> > set(AC_DEFINES "${AC_DEFINES} -DCONFIG_WCHAR_BUILTIN")
> >
> > include_directories(
> >     src
> >     ${NUTTX_PATH}/include
> >     ${NUTTX_PATH}/arch/chip
> > )
> >
> > set(EXE_NAME hellocpp)
> >
> > set(CMAKE_CXX_FLAGS "${AC_HW_FLAGS} ${AC_DEFINES} ${AC_COMMON_FLAGS}
> > ${AC_CXX_EXTRA_FLAGS}")
> > if (PARAM_DEBUG)
> >     set(CMAKE_CXX_FLAGS     "${CMAKE_CXX_FLAGS} -Os -g")
> > else()
> >     set(CMAKE_CXX_FLAGS     "${CMAKE_CXX_FLAGS} -Os")
> > endif()
> >
> > set(CMAKE_SKIP_RPATH ON)
> > set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_LINKER} ${AC_LINKER_FLAGS} -o
> > ${EXE_NAME}.elf <OBJECTS> <LINK_LIBRARIES>")
> >
> > set(BUILD_SHARED_LIBS OFF)
> >
> > add_subdirectory(src)
> > =========
> >
> > === src/CMakelists.txt ===
> > set(HEADER_FILES
> >     HelloWorld.h
> >     Log.h
> > )
> >
> > set(SOURCE_FILES
> >     HelloWorld.cpp
> >     Log.cpp
> > )
> >
> > link_directories(${EXE_NAME} ${NUTTX_PATH}/libs)
> >
> > add_executable(${EXE_NAME} ${SOURCE_FILES} main.cpp ${HEADER_FILES})
> >
> > add_custom_command(
> >     TARGET ${EXE_NAME}
> >     POST_BUILD
> >     COMMAND ${CMAKE_OBJCOPY} ARGS -S -O binary
> > ${CMAKE_BINARY_DIR}/${EXE_NAME}.elf
> > ${CMAKE_BINARY_DIR}/${EXE_NAME}.bin
> > )
> >
> > target_link_libraries(${EXE_NAME} --start-group)
> > target_link_libraries(${EXE_NAME} c)
> > target_link_libraries(${EXE_NAME} arch)
> > target_link_libraries(${EXE_NAME} binfmt)
> > target_link_libraries(${EXE_NAME} board)
> > target_link_libraries(${EXE_NAME} boards)
> > target_link_libraries(${EXE_NAME} drivers)
> > target_link_libraries(${EXE_NAME} fs)
> > target_link_libraries(${EXE_NAME} mm)
> > target_link_libraries(${EXE_NAME} sched)
> > target_link_libraries(${EXE_NAME} xx)
> > target_link_libraries(${EXE_NAME} net)
> > target_link_libraries(${EXE_NAME} supc++)
> > target_link_libraries(${EXE_NAME}
> > /usr/lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/libgcc.a)
> > target_link_libraries(${EXE_NAME} --end-group)
> > =========
> >
> > I am using Ubuntu 20.04 operating system and the toolchain provided
> > from the Ubuntu Repository.
> >
> > Best regards,
> >
> > Flavio
> >
> >
> >
> >
> > --
> > Flavio de Castro Alves Filho
> >
> > flavio.alves@gmail.com
> > Twitter: http://twitter.com/#!/fraviofii
> > LinkedIn profile: www.linkedin.com/in/flaviocastroalves
> >



-- 
Flavio de Castro Alves Filho

flavio.alves@gmail.com
Twitter: http://twitter.com/#!/fraviofii
LinkedIn profile: www.linkedin.com/in/flaviocastroalves

Re: Using C++ STL in Nuttx

Posted by Xiang Xiao <xi...@gmail.com>.
On Mon, Mar 15, 2021 at 6:00 PM Flavio Castro Alves Filho <
flavio.alves@gmail.com> wrote:

> Hello,
>
> I am trying to use STL in a simple C++ Hello project and I am getting
> compilation error.s
>
> Is STL supported in NuttX? Can I use it?
>
>
Yes, you can. Please reference the following config and Make.defs to setup
your C++ environment:
nuttx/boards/arm/stm32/stm32f4discovery/configs/cxxtest/defconfig
nuttx/boards/sim/sim/sim/configs/cxxtest/defconfig
nuttx/nuttx/boards/sim/sim/sim/configs/libcxxtest/defconfig


> Here is my sample code:
>
> === Hello.cpp ===
> #include <stdio.h>
> #include "HelloWorld.h"
>
> CHelloWorld::CHelloWorld() {
>     mSecret = 42;
>     printf("Constructor: mSecret=%d\n",mSecret);
> }
>
> CHelloWorld::~CHelloWorld() {
>
> }
>
> bool CHelloWorld::HelloWorld(void) {
>     printf("HelloWorld: mSecret=%d\n",mSecret);
>
>     if (mSecret == 42) {
>         printf("CHelloWorld: HelloWorld: Hello, world!");
>         return true;
>     }
>     else {
>         printf("CHelloWorld: HelloWorld: CONSTRUCTION FAILED!\n");
>         return false;
>     }
> }
> =========
>
> === Hello.h ===
> class CHelloWorld
> {
>     public:
>         CHelloWorld();
>         ~CHelloWorld();
>         bool HelloWorld(void);
>     private:
>         int mSecret;
> };
> =========
>
> === Log.cpp ===
> #include "Log.h"
> #include <stdio.h>
> #include <string>
>
> void Log::print(std::string_view message) {
>
>     FILE *fp = fopen("/dev/ttyS0", "w");
>     if (fp == NULL) {
>         printf("Error opening serial port!\n");
>         return;
>     }
>
>     std::string msgStr { message };
>
>     /* Try to force input data on stdin */
>     fwrite(msgStr.c_str(), sizeof(char), message.length(), fp);
>
>     fclose(fp);
> }
> =========
>
> === Log.h ===
> #include <string_view>
>
> class Log {
> public:
>     static void print(std::string_view message);
> };
> =========
>
> And there the compilation error:
> =========
> -- Build files have been written to: /home/ubuntu/nuttx-apps/hellocpp/build
> [4/4] Linking CXX executable src/hellocpp
> FAILED: src/hellocpp
> : && arm-none-eabi-ld --entry=__start -nostartfiles -nostdlib
> -nodefaultlibs
> -T/home/ubuntu/nuttx-apps/hellocpp/nuttx-export-9.1.0/scripts/ld.script
> -o hellocpp.elf src/CMakeFiles/hellocpp.dir/HelloWorld.cpp.o
> src/CMakeFiles/hellocpp.dir/Log.cpp.o
> src/CMakeFiles/hellocpp.dir/main.cpp.o
> -L/home/ubuntu/nuttx-apps/hellocpp/src/hellocpp
> -L/home/ubuntu/nuttx-apps/hellocpp/nuttx-export-9.1.0/libs
> --start-group  -lc  -larch  -lbinfmt  -lboard  -lboards  -ldrivers
> -lfs  -lmm  -lsched  -lxx  -lnet  -lsupc++
> /usr/lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/libgcc.a
> --end-group && cd /home/ubuntu/nuttx-apps/hellocpp/build/src &&
> arm-none-eabi-objcopy -S -O binary
> /home/ubuntu/nuttx-apps/hellocpp/build/hellocpp.elf
> /home/ubuntu/nuttx-apps/hellocpp/build/hellocpp.bin
> arm-none-eabi-ld: src/CMakeFiles/hellocpp.dir/Log.cpp.o: in function
> `void std::__cxx11::basic_string<char, std::char_traits<char>,
> std::allocator<char> >::_M_construct<char const*>(char const*, char
> const*, std::forward_iterator_tag)':
> /usr/include/newlib/c++/9.2.1/bits/basic_string.tcc:212: undefined
> reference to `std::__throw_logic_error(char const*)'
> arm-none-eabi-ld:
> /usr/include/newlib/c++/9.2.1/bits/basic_string.tcc:219: undefined
> reference to `std::__cxx11::basic_string<char, std::char_traits<char>,
> std::allocator<char> >::_M_create(unsigned int&, unsigned int)'
> arm-none-eabi-ld:
> /usr/include/newlib/c++/9.2.1/bits/basic_string.tcc:225: undefined
> reference to `std::__cxx11::basic_string<char, std::char_traits<char>,
> std::allocator<char> >::_S_copy_chars(char*, char const*, char
> const*)'
> arm-none-eabi-ld: src/CMakeFiles/hellocpp.dir/Log.cpp.o: in function
> `std::__cxx11::basic_string<char, std::char_traits<char>,
> std::allocator<char> >::~basic_string()':
> /usr/include/newlib/c++/9.2.1/bits/basic_string.h:658: undefined
> reference to `std::__cxx11::basic_string<char, std::char_traits<char>,
> std::allocator<char> >::_M_dispose()'
> arm-none-eabi-ld:
> /usr/include/newlib/c++/9.2.1/bits/basic_string.h:658: undefined
> reference to `std::__cxx11::basic_string<char, std::char_traits<char>,
> std::allocator<char> >::_M_dispose()'
> ninja: build stopped: subcommand failed.
> make[1]: *** [Makefile:13: _build] Error 1
> make[1]: Leaving directory '/home/ubuntu/nuttx-apps/hellocpp'
> make: *** [Makefile:25: default] Error 2
> =========
>
> My CMakelists:
>
> === CMakeLists.txt ===
> cmake_minimum_required(VERSION 3.2...3.15)
>
> project(hellocpp
>     VERSION 1.0
>     DESCRIPTION "Hello world C++ Nuttx"
> )
>
> set(CMAKE_CXX_STANDARD 17)
> set(CMAKE_CXX_STANDARD_REQUIRED ON)
> set(CMAKE_C_STANDARD 99)
>
> set(NUTTX_PATH "${CMAKE_SOURCE_DIR}/nuttx-export-9.1.0")
>
> include(cmake/phigw.cmake)
>
> set(AC_COMMON_FLAGS "${AC_COMMON_FLAGS} -fno-builtin -Wall -Wshadow
> -Wundef -g")
>
> set(AC_DEFINES "${AC_DEFINES} -DCONFIG_WCHAR_BUILTIN")
>
> include_directories(
>     src
>     ${NUTTX_PATH}/include
>     ${NUTTX_PATH}/arch/chip
> )
>
> set(EXE_NAME hellocpp)
>
> set(CMAKE_CXX_FLAGS "${AC_HW_FLAGS} ${AC_DEFINES} ${AC_COMMON_FLAGS}
> ${AC_CXX_EXTRA_FLAGS}")
> if (PARAM_DEBUG)
>     set(CMAKE_CXX_FLAGS     "${CMAKE_CXX_FLAGS} -Os -g")
> else()
>     set(CMAKE_CXX_FLAGS     "${CMAKE_CXX_FLAGS} -Os")
> endif()
>
> set(CMAKE_SKIP_RPATH ON)
> set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_LINKER} ${AC_LINKER_FLAGS} -o
> ${EXE_NAME}.elf <OBJECTS> <LINK_LIBRARIES>")
>
> set(BUILD_SHARED_LIBS OFF)
>
> add_subdirectory(src)
> =========
>
> === src/CMakelists.txt ===
> set(HEADER_FILES
>     HelloWorld.h
>     Log.h
> )
>
> set(SOURCE_FILES
>     HelloWorld.cpp
>     Log.cpp
> )
>
> link_directories(${EXE_NAME} ${NUTTX_PATH}/libs)
>
> add_executable(${EXE_NAME} ${SOURCE_FILES} main.cpp ${HEADER_FILES})
>
> add_custom_command(
>     TARGET ${EXE_NAME}
>     POST_BUILD
>     COMMAND ${CMAKE_OBJCOPY} ARGS -S -O binary
> ${CMAKE_BINARY_DIR}/${EXE_NAME}.elf
> ${CMAKE_BINARY_DIR}/${EXE_NAME}.bin
> )
>
> target_link_libraries(${EXE_NAME} --start-group)
> target_link_libraries(${EXE_NAME} c)
> target_link_libraries(${EXE_NAME} arch)
> target_link_libraries(${EXE_NAME} binfmt)
> target_link_libraries(${EXE_NAME} board)
> target_link_libraries(${EXE_NAME} boards)
> target_link_libraries(${EXE_NAME} drivers)
> target_link_libraries(${EXE_NAME} fs)
> target_link_libraries(${EXE_NAME} mm)
> target_link_libraries(${EXE_NAME} sched)
> target_link_libraries(${EXE_NAME} xx)
> target_link_libraries(${EXE_NAME} net)
> target_link_libraries(${EXE_NAME} supc++)
> target_link_libraries(${EXE_NAME}
> /usr/lib/gcc/arm-none-eabi/9.2.1/thumb/v7e-m/nofp/libgcc.a)
> target_link_libraries(${EXE_NAME} --end-group)
> =========
>
> I am using Ubuntu 20.04 operating system and the toolchain provided
> from the Ubuntu Repository.
>
> Best regards,
>
> Flavio
>
>
>
>
> --
> Flavio de Castro Alves Filho
>
> flavio.alves@gmail.com
> Twitter: http://twitter.com/#!/fraviofii
> LinkedIn profile: www.linkedin.com/in/flaviocastroalves
>