[ECOS] Re: Linking errors with arm-elf-g++

Peter Blair peterb@turnpikeglobal.com
Tue Aug 19 19:02:00 GMT 2003


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.

Yet, on the eCos website on how to compile C & C++ files, it explicitly
states the usage of the gcc & g++ programs respectively.

(
http://sources.redhat.com/ecos/docs-2.0/user-guide/compiler-and-linker-o
ptions.html#COMPILING-C-APP )
(
http://sources.redhat.com/ecos/docs-2.0/user-guide/compiling-cpp-app.htm
l )

I decided to take a look at four simple test cases, involving an ansi-C
function (void test(const char *str)) found in test.c and prototyped in
test.h, and two main functions, one written in ansi-c and the other in
c++ (main.c & main.cpp).  Below is the output of my development system
environment and the sources for all of my files including my Makefile as
well at the output of the applications and errors.

As you can see, the gcc application failed when attempting to link the
test.o and main.o(main.cpp) files ( Case 2 ), yet the g++ application
successfully compiles & links both .c & .cpp files.

PS: We (Turnpike Global) are currently working with Ravi & his company
with the porting of his company's eCos Bluetooth stack over to C++.

*** SYSTEM ENVIRONMENT & TEST FILES ***

peterb@turnpike1 ~/cpp_test
$ ls
Makefile  echo_files.sh  main.c  main.cpp  test.c  test.h

$ uname -a
CYGWIN_NT-5.0 turnpike1 1.3.22(0.78/3/2) 2003-03-18 09:20 i686 unknown
unknown Cygwin

$ gcc -v
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.2/specs
Configured with: /netrel/src/gcc-3.2-3/configure
--enable-languages=c,c++,f77,java --enable-libgcj --enable-threads=posix
--with-system-zlib --enable-nls --without-included-gettext
--enable-interpreter --disable-sjlj-exceptions
--disable-version-specific-runtime-libs --enable-shared
--build=i686-pc-linux --host=i686-pc-cygwin --target=i686-pc-cygwin
--enable-haifa --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc
--libdir=/usr/lib --includedir=/nonexistent/include
--libexecdir=/usr/sbin
Thread model: posix
gcc version 3.2 20020927 (prerelease)

$ ./echo_files.sh 'echo_files.sh Makefile test.h test.c main.c main.cpp'
> files.txt
$ cat files.txt
<-- echo_files.sh -->

#!/bin/sh

for file in $1
do
  echo "<-- $file -->"
  echo ""
  cat $file
done

<-- Makefile -->

test.o:
	gcc -ansi -c test.c

case1:	test.o
	gcc main.c test.o -o case1 2> case1.txt

case2:	test.o
	gcc main.cpp test.o -o case2 2> case2.txt

case3:	test.o
	g++ main.c test.o -o case3 2> case3.txt

case4:	test.o
	g++ main.cpp test.o -o case4 2> case4.txt

<-- test.h -->

#ifndef __TEST_H
#define __TEST_H
#include <stdio.h>

#if defined(__cplusplus)
extern "C" {
#endif
void test(const char * str);

#if defined(__cplusplus)
}
#endif
#endif

<-- test.c -->

#include "test.h"

void test(const char * str)
{
	printf(str);
}

<-- main.c -->

#include "test.h"

int main(void)
{
	test("main.c\n");
}
<-- main.cpp -->

#include "test.h"

int main()
{
	test("main.cpp\n");
}

*** 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
make: *** [case2] Error 1
g++ main.c test.c -o case3 2> case3.txt
g++ main.cpp test.c -o case4 2> case4.txt

$ ls *.exe
case1.exe  case3.exe  case4.exe

$ 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

$ ./case1
main.c

$ ./case3
main.c

$ ./case4
main.cpp


-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss



More information about the Ecos-discuss mailing list