0

I'm trying to create a static library that contains C and C++ functions and then use this library in a C environment. As per Using C++ library in C code, I wrap C functions around C++ functions.

The makefile for the library uses "ar -rvs libNAMEX.a $(OBJECTS)" where OBJECTS contains the object files compiled by gcc or g++ depending on type (GCC version 4.4.1).

I don't encounter any errors when building the library. But when I try to compile a C file (with a cross-compiled version of GCC 4.5.1) that used the library: "gcc -L[PATH TO libNAMEX.a] -lNAMEX ... c_source.c", it gives me errors related to C++ extensions (i.e., "undefined reference to operator new(unsigned long)", "undefined reference tostd::allocator::~allocator()'").

Are there any way around this problem?

Community
  • 1
  • 1
Jacob
  • 1
  • 3

1 Answers1

3

Use g++ as linker:

gcc my_c_file.c -c
g++ my_c_file.o -L blabla -lblabla
Andrea Bergia
  • 5,502
  • 1
  • 23
  • 38