Question

Consider the program:

#include <gc/gc.h>
int main() {
  void* p = GC_MALLOC(15);
}

Under Ubuntu 10.04 LTS this compiles (gcc -lgc test.c). Under 12.04 LTS:

/tmp/cc7GcTfU.o: In function `main':
main.c:(.text+0xe): undefined reference to `GC_malloc'
collect2: ld returned 1 exit status

It looks like between 10.04 and 12.04 they've changed the library not to compile in malloc replacements. Or that's what I think this description of the libgc1c2 package says:

[...] However, it does not work as a drop-in malloc(3) replacement.

Is there a simple way to get around this? (Say, something simpler than recompiling libgc manually...)

Was it helpful?

Solution

To answer my own question: actually, the Boehm GC library still works the same way as it used to in 12.04. The problem is that GCC doesn't! GCC has started to default to --as-needed, and it drops -lgc completely if it is at the beginning of the line. This is a very major change!!

Solution is to move -lgc to the end:

gcc test.c -lgc

Or add:

gcc -Wl,--as-needed -lgc test.c
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top