4

I have a problem while trying to compile and link my program with "dmalloc".

bin
+--dmalloc

include
+--dmalloc.h

lib
+--libdmalloc.a
+--libdmallocth.a

main.c

I have the following directory structure

Now I try to compile my program with the following command:

gcc -Iinclude -Llib -ldmalloc -DDMALLOC main.c
/tmp/ccSDFmWj.o: In function `main':
main.c:(.text+0x29): undefined reference to `dmalloc_malloc'
collect2: ld returned 1 exit status

Okay, I get that there's a problem with linking the symbols, ld simply cannot find reference to dmalloc_malloc. However...

nm lib/libdmalloc.a | grep dmalloc_malloc
0000000000001170 T dmalloc_malloc
0000000000000fe0 t dmalloc_malloc.part.6

I am puzzled... The symbol is there in that library. Why does 'ld' has problem with it?

Gray
  • 115,027
  • 24
  • 293
  • 354
Melon
  • 604
  • 1
  • 7
  • 30

1 Answers1

6

List the libraries last:

gcc -Iinclude -Llib -DDMALLOC main.c -ldmalloc
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084