- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi!
I have started working with C++ in my project. Creating classes and using own objects is no problem, Now I want to use objects of the standard library, e.g. class "string", but I get lots of linker errors. My linker flags are: ECOS_GLOBAL_LDFLAGS = -g -nostdlib -Wl,--gc-sections -Wl,-static -mno-hw-mul -mno-hw-div Example of my source code: # include <string> using namespace std; .... void ThrdMain(cyg_addrword_t data) { ... string s1 = "Hello"; string s2 = " "; s2 = s1; ... } This causes many unresolved methods of the class "string": background.o(.text.ThrdBackground+0x3c):/cygdrive/f/alt_projects/R106/application/src/background.cpp:104: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)' background.o(.text.ThrdBackground+0x44):/cygdrive/f/alt_projects/R106/application/src/background.cpp:104: undefined reference to `std::allocator<char>::~allocator()' background.o(.text.ThrdBackground+0x4c):/cygdrive/f/alt_projects/R106/application/src/background.cpp:42: undefined reference to `std::allocator<char>::allocator()' ... and many more Can anyone help me? Thanks!Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
eCos doesn't include out-of-the-box STL support. Some people seem to use STLPort (http://www.stlport.com/). Discussion about that can be found on the eCos mailinglist, eg. here: http://sourceware.org/ml/ecos-discuss/2005-05/msg00269.html (http://sourceware.org/ml/ecos-discuss/2005-05/msg00269.html) Regards, Andreas.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually, eCos supports STL just fine; this is a function of GCC and not eCos. It's just that the "-nostdlib" flag makes it not link the standard C++ library by default.
You need to add the "-lstdc++" flag to your link command, and it needs to be after all your .o files and any other libraries that use the STL.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- originally posted by mike desimone@Oct 5 2005, 12:22 PM actually, ecos supports stl just fine; this is a function of gcc and not ecos. it's just that the "-nostdlib" flag makes it not link the standard c++ library by default.
you need to add the "-lstdc++" flag to your link command, and it needs to be after all your .o files and any other libraries that use the stl.
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=10180)
--- quote end ---
--- Quote End --- I have the same problem, and the -lstdc++ makes no difference. See below: make INSTALL_DIR=c:/Development/DefectAnalyzer/eCos/DspFull_Install all nios2-elf-gcc -nostartfiles -Lc:/Development/DefectAnalyzer/eCos/DspFull_Install/lib -Ttarget.ld -g -lstdc++ -Wl,--gc-sections -Wl,-static -mhw-mul -mhw-mulx -mno-hw-div -o hello hello.o hello.o(.gnu.linkonce.t._ZN9ExceptionD1Ev+0x68): In function `main': /cygdrive/c/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../../include/c++/3.4.1/bits/basic_string.h:178: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_S_empty_rep_storage' hello.o(.gnu.linkonce.t._ZN9ExceptionD1Ev+0x6c): In function `main': /cygdrive/c/Development/DefectAnalyzer/eCosProjects/examples/hello.cpp:30: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_S_empty_rep_storage' [etc.] Any ideas about what to try next?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- originally posted by klocken+oct 17 2006, 08:24 pm--><div class='quotetop'>quote (klocken @ oct 17 2006, 08:24 pm)</div>
--- quote start ---
<!--quotebegin-mike desimone@Oct 5 2005, 12:22 PM actually, ecos supports stl just fine; this is a function of gcc and not ecos. it's just that the "-nostdlib" flag makes it not link the standard c++ library by default.
you need to add the "-lstdc++" flag to your link command, and it needs to be after all your .o files and any other libraries that use the stl.
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=10180)
--- quote end ---
--- Quote End --- I have the same problem, and the -lstdc++ makes no difference. See below: make INSTALL_DIR=c:/Development/DefectAnalyzer/eCos/DspFull_Install all nios2-elf-gcc -nostartfiles -Lc:/Development/DefectAnalyzer/eCos/DspFull_Install/lib -Ttarget.ld -g -lstdc++ -Wl,--gc-sections -Wl,-static -mhw-mul -mhw-mulx -mno-hw-div -o hello hello.o hello.o(.gnu.linkonce.t._ZN9ExceptionD1Ev+0x68): In function `main': /cygdrive/c/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../../include/c++/3.4.1/bits/basic_string.h:178: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_S_empty_rep_storage' hello.o(.gnu.linkonce.t._ZN9ExceptionD1Ev+0x6c): In function `main': /cygdrive/c/Development/DefectAnalyzer/eCosProjects/examples/hello.cpp:30: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_S_empty_rep_storage' [etc.] Any ideas about what to try next? <div align='right'><{post_snapback}> (index.php?act=findpost&pid=18759)</div> [/b] --- Quote End --- It looks like you didn't put the -lstdc++ after all the .o files that use the std C++ library. It needs to be the last thing on the line. So, for example, you might see something like this in your makefile: @$(XLD) $(LDFLAGS) $(ECOS_GLOBAL_LDFLAGS) -o $@ $(OBJS) -lstdc++
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page