This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Re: Linking errors with arm-elf-g++
- From: Andrew Lunn <andrew at lunn dot ch>
- To: Peter Blair <peterb at turnpikeglobal dot com>
- Cc: andrew dot lunn at ascom dot ch, ecos-discuss at sources dot redhat dot com
- Date: Wed, 20 Aug 2003 00:14:45 +0200
- Subject: Re: [ECOS] Re: Linking errors with arm-elf-g++
- References: <000001c36684$ba835030$2bc81aa7@home.turnpikeglobal.com>
On Tue, Aug 19, 2003 at 03:04:31PM -0400, Peter Blair wrote:
>
> Andrew,
>
> As per your previous post regarding linking error with gcc & CC/cpp/C
> files you stated that:
>
> "gcc is a front end to the C compiler, the C++ compiler .. If you pass
> it a c++ file it will call the c++ compiler .."
>
> So, one would assume that by your statement one would be able to compile
> the above listed language source-files (c, C, cpp, CC) with the gcc
> command and allow it to determine which back-end compiler to use.
Correct. info gcc: leaf: Invoking gcc:
For any given input file, the file name suffix determines what kind
of compilation is done:
`FILE.c'
C source code which must be preprocessed.
`FILE.i'
C source code which should not be preprocessed.
`FILE.ii'
C++ source code which should not be preprocessed.
`FILE.m'
Objective-C source code. Note that you must link with the library
`libobjc.a' to make an Objective-C program work.
`FILE.h'
C header file (not to be compiled or linked).
`FILE.cc'
`FILE.cxx'
`FILE.cpp'
`FILE.C'
C++ source code which must be preprocessed. Note that in `.cxx',
the last two letters must both be literally `x'. Likewise, `.C'
refers to a literal capital C.
[...]
> *** OUTPUT OF TEST CASES ***
>
> $ make case1; make case2; make case3; make case4
> gcc main.c test.c -o case1 2> case1.txt
> gcc main.cpp test.c -o case2 2> case2.txt
lunn@londo:~/Junk$ gcc -Wall -ansi -c test.c
lunn@londo:~/Junk$ gcc main.cpp test.o -o case2
lunn@londo:~/Junk$
This is gcc 2.95.4, where as you are using 3.2
> $ cat case2.txt
> /cygdrive/c/DOCUME~1/peterb/LOCALS~1/Temp/ccl6Cv67.o(.eh_frame+0x11):mai
> n.cpp: undefined reference to `___gxx_personality_v0'
> collect2: ld returned 1 exit status
This is actually a linker error, not a compiler error. When you are
linking c++ with gcc 3.x you need an extra library, libsupc++.a. If
you use g++ to do the link, it will automatically add this library. If
you use gcc you have to manually add the library. eCos linker scripts
always add this library.
lunn@londo:~/Junk$ arm-elf-gcc -v
Reading specs from /opt/ecos/gnutools/arm-elf/bin/../lib/gcc-lib/arm-elf/3.2.1/specs
Configured with: /home/demonweb/tools/ecos-gnutools-v1.4/r2/arm-elf/x86_linux_lsb1_3/tar_bz2/source/gcc-3.2.1/configure --target=arm-elf --prefix=/home/demonweb/tools/ecos-gnutools-v1.4/r2/arm-elf/x86_linux_lsb1_3/tar_bz2/opt/ecos/gnutools/arm-elf --enable-languages=c,c++ --with-gnu-as --with-gnu-ld --with-newlib --with-gxx-include-dir=/home/demonweb/tools/ecos-gnutools-v1.4/r2/arm-elf/x86_linux_lsb1_3/tar_bz2/opt/ecos/gnutools/arm-elf/arm-elf/include
Thread model: single
gcc version 3.2.1
lunn@londo:~/Junk$ arm-elf-gcc -Wall -ansi -c test.c
lunn@londo:~/Junk$ arm-elf-gcc -Wall main.cpp test.o -o case2 -L ~/eCos/work/install/lib -Ttarget.ld -nostdlib
lunn@londo:~/Junk$
Now, back to your original problem.
Your bluetooth stack is C code. So compile it with a C compiler by
making sure the endings are .c. Your application is cpp code, so make
sure it ends in .cpp or .cc so its compiled by the c++ compiler. You
have to make sure your c++ code knows its calling c code by ensuring
the header files declare the functions as extern "C" when compiling
c++ code. You have this correct in test.h.
Andrew
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss