'ld' cannot link symbols, although they are in library

929 Views Asked by At

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?

1

There are 1 best solutions below

0
Kerrek SB On BEST ANSWER

List the libraries last:

gcc -Iinclude -Llib -DDMALLOC main.c -ldmalloc