Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

C++ on uClinux on Nios II ?

Can you use C++ on uClinux on Nios II? I tried building the C++ test application available in menuconfig, but STL doesn't build:

Code:

Do I need to install something else to get pthread support? What about the other errors? Has anybody had any luck building other C++ libraries or applications?

10 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    AFAIK, with NIOS2-nommu, you can use C++ but you can't use shared libraries (what you seemingly want to do as your "dll" naming suggests). Before trying to port an application you should first try to compile and run a simple "hallo world" c++ program .

    With NIOS2-mmu you can use shared libraries.

    While I did not yet try c++ and did not try to create a shared library or a program that uses one, I did try to do threads via the pthread library.

    With NIOS2-nommu this does work, but the debugger does not support threads. Moreover the compiler does not support the "__thread" keywords (static thread specific varibles). Both issues hould be solved with the NIOS2-mmu distribution.

    -Michael
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    make: Entering directory `/data/nios/nios2-linux/uClinux-dist/lib/STLport/build/lib'                                                         
    nios2-linux-uclibc-g++   -pthread -fexceptions -fident  -fPIC -O2 -fuse-cxa-atexit  -D_STLP_REAL_LOCALE_IMPLEMENTED -D_GNU_SOURCE  -I/data/nios/nios2-linux/uClinux-dist/include/STLport -I/data/nios/nios2-linux/uClinux-dist/include  -c -o obj/gcc/shared/dll_main.o ../../src/dll_main.cpp

    The C++ is supported on nios2.

    But I build the applicaiotn without the menuconfig, I build the applicaiotn with my Makefile.

    I have build the MiniGUI and C++ applicaiotn.

     -pthread or -lpthread  ???
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I changed -pthread to -lpthread and no longer get that error, but there are still the not found includes

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Fixed includes and a couple of other things in STLport, now on to compiling and linking helloworld:

    make: Entering directory `/data/nios/nios2-linux/uClinux-dist/user/cxxtest/helloworld'                                                       
    nios2-linux-uclibc-g++  -L/data/nios/nios2-linux/uClinux-dist/lib/STLport/lib -o cxx_helloworld helloworld.o -lm -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic                                                                                                                                            
    helloworld.o(.text+0x20): In function `std::__verify_grouping(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)&#39;:                                                                                                                      
    : undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const&#39;                                 
    helloworld.o(.text+0x80): In function `std::__verify_grouping(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)&#39;:                                                                                                                      
    : undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator(unsigned long) const&#39;              
    helloworld.o(.text+0xdc): In function `std::__verify_grouping(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)&#39;:                                                                                                                      
    : undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator(unsigned long) const&#39;              
    helloworld.o(.text+0x114): In function `std::__verify_grouping(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)&#39;:                                                                                                                     
    : undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator(unsigned long) const&#39;              
    helloworld.o(.text+0x188): In function `main&#39;:                                                                                                  
    : undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)&#39;                                                                                                        
    /data/nios/nios2-linux/uClinux-dist/lib/STLport/lib/libstdc++.a(iostream.o)(.text+0x3b8): In function `std::_Stl_create_wfilebuf(__STDIO_FILE_STRUCT*, int)&#39;:                                                                                                                                   
    : undefined reference to `__gxx_personality_sj0&#39;

    and so on...
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    STLport is not needed and the cxxtest apps is not ported. You can build the c++ apps with simply,

    nios2-linux-uclibc-g++ helloworld.cxx -o helloworld -elf2flt

    - Hippo
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    <div class='quotetop'>QUOTE (hippo @ Sep 1 2009, 12:32 AM) <{post_snapback}> (index.php?act=findpost&pid=23713)</div>

    --- Quote Start ---

    STLport is not needed and the cxxtest apps is not ported. You can build the c++ apps with simply,

    nios2-linux-uclibc-g++ helloworld.cxx -o helloworld -elf2flt

    - Hippo[/b]

    --- Quote End ---

    Is STL already in the toolchain then? Is there any advantage to using STLport now that I do have it built (sort of, trouble linking the app as above)?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    <div class='quotetop'>QUOTE (tehfury87 @ Sep 1 2009, 09:50 PM) <{post_snapback}> (index.php?act=findpost&pid=23724)</div>

    --- Quote Start ---

    Is STL already in the toolchain then? Is there any advantage to using STLport now that I do have it built (sort of, trouble linking the app as above)?[/b]

    --- Quote End ---

    No. STL is not used in the toolchain. We use libstdc++ come with gcc. I don&#39;t know if there is any advantage to use STLport.

    - Hippo
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Can you use C++ on uClinux on Nios II? I tried building the C++ test application available in menuconfig, but STL doesn't build:

    Do I need to install something else to get pthread support? What about the other errors? Has anybody had any luck building other C++ libraries or applications?

    --- Quote End ---

    He have successfully developed a large application which uses STL extensively, especially container templates.

    However, we weren't able to compile even the simplest application with C++ and pthreads combined.

    Cheers,

    Ricardo.