Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
12748 Discussions

multiple definition of `_start'

Altera_Forum
Honored Contributor II
3,353 Views

Hello members of the forum... I am new working with Nios and programming applications C/C++ for that reason I please need the aid an expert who knows, wants and can help me to solve the errors of my small application of test, 

The application:# include <stdio.h> 

int main(void){ 

printf("\nThis is a test of the application CPP2...bye\n"); 

return 0; 

 

The error: 

make -k all  

no emulation specific options. 

nios2-elf-gcc -msys-crt0="c:/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.uClibc_1.4.0"/lib/crt0.o -r -d -L"c:/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.uClibc_1.4.0"/lib -o cpp2.bin cpp2.o /cygdrive/c/altera/kits/nios2/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/lib/libm.a /cygdrive/c/altera/kits/nios2/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/libgcc.a "c:/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.uClibc_1.4.0"/lib/libc.a 

cpp2.o(.text+0x0): in function `_start&#39;: 

: multiple definition of `_start&#39; 

c:/altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.uClibc_1.4.0/lib/crt0.o(.text+0x0): first defined here 

collect2: ld returned 1 exit status 

make: *** [cpp2.bin] Error 1 

make: Target `all&#39; not remade because of errors. 

 

I will thank for the aid of an expert who has knowledge about how to solve this problem.
0 Kudos
13 Replies
Altera_Forum
Honored Contributor II
1,455 Views

Hi carol, 

 

It is the startup crt0.o problem. 

 

It should be easier if you work on Linux and follow my buildroot guide, 

http://forum.niosforum.com/forum/index.php?showtopic=3174 (http://forum.niosforum.com/forum/index.php?showtopic=3174

 

The step8 in port#1 tells you how to compile and run a simple program on uClinux. 

 

About C++, you can not use nios2-elf&#39;s libstdc++, it is bond to newlib. 

On uClinux, you should need that which is bond to uClibc. 

The libstdc++ which we built with uClibc still have problems, it compiled and linked, but crashed when running on uClinux. I am not a C++ user, and I can&#39;t resolve the problems without help from C++ user.
0 Kudos
Altera_Forum
Honored Contributor II
1,455 Views

Hippo wrote.... 

 

--- Quote Start ---  

originally posted by hippo@Feb 24 2006, 11:55 AM 

the libstdc++ which we built with uclibc still have problems, it compiled and linked, but crashed when running on uclinux. 

--- Quote End ---  

 

 

Exactly, I&#39;m getting this when I try to compile and link C++ on uClinux 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

# Compile the helloWorld app 

nios2-linux-uclibc-g++ hello.cpp -o hello -elf2flt 

/home/hootsmon/buildroot/build_nios2/staging_dir/bin-ccache/../lib/gcc/nios2-linux-uclibc/3.4.5/../../../../nios2-linux-uclibc/bin/ld.real: section .gnu.linkonce.sb._ZGVNSt7collateIcE2idE [0002dc40 -> 0002dc47] overlaps section .text [00000000 -> 0004d45f] 

/home/hootsmon/buildroot/build_nios2/staging_dir/bin-ccache/../lib/gcc/nios2-linux-uclibc/3.4.5/../../../../nios2-linux-uclibc/bin/ld.real: section .gnu.linkonce.sb._ZGVNSt8messagesIcE2idE [0002dc48 -> 0002dc4f] overlaps section .text [00000000 -> 0004d45f] 

    etc....[/b] 

--- Quote End ---  

 

 

I spent some time digging into this problem, but I need some help please. 

 

Q) Can someone explain what W_RODATA and R_RODATA mean? 

I see these things get zapped by the Nios-specific linker script, but why? 

 

Grateful for any advice please.
0 Kudos
Altera_Forum
Honored Contributor II
1,455 Views

I posted this to buildroot bug report, but they didn&#39;t accept it yet. 

 

So download this and replace ~/buildroot/toolchain/elf2flt/elf2flt.nios2.conditional 

http://bugs.busybox.net/file_download.php?...id=601&type=bug (http://bugs.busybox.net/file_download.php?file_id=601&type=bug

 

And rebuild elf2flt 

cd ~/buildroot rm -rf toolchain_build_nios2/elf2flt make
0 Kudos
Altera_Forum
Honored Contributor II
1,455 Views

Hippo, I did try try your bugfix, but unfortunately the link error is still there. 

 

Here is my minimal C++ program... 

#include <iostream># include <stdio.h> using namespace std; int main() {  printf    ("Hello from STDIO\n");  // This works OK  cout    << "Hello from IOSTREAM" << endl;    // But this crashes linker!!!  return    0; } 

 

1) I have found that you can compile more-or-less any valid C code (with a CPP extension), so long as you don&#39;t link in any C++ specific stuff. 

 

2) I tried both C++ compilers. (ie. nios2-linux-uclibc-c++ and  

nios2-linux-uclibc-g++), however they appear to be identical. 

 

3) I&#39;m guessing there&#39;s a problem in buildroot&#39;s libstdc++, but that&#39;s where I&#39;m stumped. 

 

Can anyone explain how to run the DejaGnu testsuite, associated with libstdc++ ?
0 Kudos
Altera_Forum
Honored Contributor II
1,455 Views

hootsmon, 

 

1. what&#39;s the link error messages now with libstdc++? 

can you link to elf without -elf2flt flag? 

try nios2-linux-uclibc-nm hello | sort , here hello is the elf without -elf2flt flag. 

 

2. c++ and g++ are the same. 

 

3. I guess there is problem in the elf2flt.ld, which should be rebuild from regular link script. 

I did bot run the test suits. If the hello can not run, it won&#39;t run the test suits either. 

The c++ is very different from c in class functions. I didn&#39;t have time to trace inside.
0 Kudos
Altera_Forum
Honored Contributor II
1,455 Views

 

--- Quote Start ---  

originally posted by hippo@Mar 7 2006, 05:06 PM 

1. what&#39;s the link error messages now with libstdc++? 

--- Quote End ---  

 

The error messages say: "overlaps section...." 

nios2-linux-uclibc-g++ hello.cpp -o hello -elf2flt /home/hootsmon/buildroot/build_nios2/staging_dir/bin-ccache/../lib/gcc/nios2-linux-uclibc/3.4.5/../../../../nios2-linux-uclibc/bin/ld.real: section .gnu.linkonce.sb._ZGVNSt7collateIcE2idE overlaps section .text /home/hootsmon/buildroot/build_nios2/staging_dir/bin-ccache/../lib/gcc/nios2-linux-uclibc/3.4.5/../../../../nios2-linux-uclibc/bin/ld.real: section .gnu.linkonce.sb._ZGVNSt8messagesIcE2idE overlaps section .text  

 

 

--- Quote Start ---  

originally posted by hippo+mar 7 2006, 05:06 pm--><div class='quotetop'>quote (hippo @ mar 7 2006, 05:06 pm)</div> 

--- quote start ---  

  can you link to elf without -elf2flt flag?[/b] 

--- quote end ---  

 

yes, compiling --> elf works fine 

 

<!--quotebegin-hippo@Mar 7 2006, 05:06 PM 

  try nios2-linux-uclibc-nm hello | sort 

--- Quote End ---  

 

 

OK, I did this. Here are the symbols (compiled without -elf2flt).... 

http://users.bigpond.net.au/hootsmon/temp/sysmbols.txt (http://users.bigpond.net.au/hootsmon/temp/sysmbols.txt)
0 Kudos
Altera_Forum
Honored Contributor II
1,455 Views

The result of elf seems OK. 

There is onething I forgot to tell you. 

Please download some later snapshot of uClibc, after 20060208. eg, 20060214 or 20060215. 

and rebuild buildroot. 

 

cd ~/buildroot 

rm -rf build_nios2 toolchain_build_nios2 

make
0 Kudos
Altera_Forum
Honored Contributor II
1,455 Views

For build0207, add a line at 117 of build_nios2/staging_dir/lib/elf2flt.ld , 

There is no need to rebuild buildroot. 

 

--- build_nios2/staging_dir/lib/elf2flt.ld    2006/03/08 02:10:19    1.1 +++ build_nios2/staging_dir/lib/elf2flt.ld    2006/03/08 02:21:44 @@ -114,6 +114,7 @@      *(.dynsbss)      *(.sbss)      *(.sbss.*) +  *(.gnu.linkonce.sb*)      *(.scommon)      *(.dynbss)      *(.bss) 

 

helloworld.cxx 

#include <iostream> int main(int argc, char *argv) {     std::cout << "Hello, world\n";     return 0; } 

 

nios2-linux-uclibc-c++ helloworld.cxx -o helloworld -elf2flt="-s 64000" 

compiled and linked, but reboot when running on nios2 uclinux. 

 

Maybe I add the tag to the wrong place?
0 Kudos
Altera_Forum
Honored Contributor II
1,455 Views

Hippo, I took your advice and grabbed a uClibc snapshot from 20060214. 

This is much better. Now my C++ program compiles and links cleanly. 

But when I execute, no output appears, and it just hangs (until I hit CTRL-C). 

So this is a hopeful sign. 

 

 

--- Quote Start ---  

originally posted by hippo@Mar 8 2006, 12:44 PM 

for build0207, add a line at 117 of build_nios2/staging_dir/lib/elf2flt.ld , 

--- Quote End ---  

 

 

I tried, but was unable to apply your patch. It seems my elf2flt.ld does not to match what was expected in the patch. Could could perhaps send me the whole elf2flt.ld script pls?
0 Kudos
Altera_Forum
Honored Contributor II
1,455 Views

hootsmon, 

find it in post#1 of the buildroot guide, elf2flt_ld.zip
0 Kudos
Altera_Forum
Honored Contributor II
1,455 Views

Thanks, I tried out your elf2flt_ld script. I didn&#39;t patch it. Now the linker is getting some undefined references....  

nios2-linux-uclibc-g++ hello.cpp -o hello -elf2flt="-s 64000" hello.elf2flt(.text+0xc964): In function `__uClibc_fini&#39;: : undefined reference to `__fini_array_start&#39; hello.elf2flt(.text+0xc968): In function `__uClibc_fini&#39;: : undefined reference to `__fini_array_start&#39; hello.elf2flt(.text+0xc96c): In function `__uClibc_fini&#39;: : undefined reference to `__fini_array_end&#39; 

 

I didn&#39;t try to execute it, &#39;cos it would probably crash anyway. 

 

Any thoughts?
0 Kudos
Altera_Forum
Honored Contributor II
1,455 Views

There are two versions of uClibc that we are talking about. 

20060207 or 20060208, the older one, use the elf2flt.ld from elf2flt_ld.zip. 

20060214 or later, the newer one with fini_array, use the patches which I post to busybox. 

 

But both will crash on libstdc++. I made the patches from normal elf ldscript. Maybe you can try to trace it out.
0 Kudos
Altera_Forum
Honored Contributor II
1,455 Views

OK, I got confused by this. I will try to trace it.

0 Kudos
Reply