problem producing library with C interface using gcc 3.2

Polevoy, IgorX
Sun Dec 22 08:04:00 GMT 2002

 I'm compiling library that should give a C interface to the outside word,
but has C++ code inside. 
The end is that library will be able to link with C programs, as well as
with C++ programs. 
While it worked with previous version of gcc it has problem with gcc 3.2.

the following example explains the problem:

**************  file foo.h ************
#ifndef _FOO_H
#define _FOO_H

#ifdef __cplusplus
extern "C" {

  int fooFunc();

#ifdef __cplusplus


**************  file foo.c ************
#include "foo.h"

class Foo{
  int getFoo(){ return i; }
private :
  int i;

extern "C" int fooFunc()

  Foo f;
  return 1;

**************  file foom.c ************
#include "foo.h"
#include <stdio.h>

int main()
  return fooFunc();


**************  makefile  ************

all: lib prog

lib: foo.cpp
	g++ -c -o foo.o foo.cpp
	ar rcv libfoo.a foo.o
	ranlib libfoo.a

prog: foom.c
	gcc foom.c libfoo.a
**************    ************


gcc foom.c libfoo.a
libfoo.a(foo.o)(.eh_frame+0x11): undefined reference to
collect2: ld returned 1 exit status
make: *** [prog] Error 1

QUESTION is how I could force the definition of  __gxx_personality_v0 for
library, without explicit linking with libstdc++ ? I know that if I build
shared library, like this

 g++  -shared -Wl,-h -o foo.o
it will work OK...


More information about the Gcc-help mailing list