Melon
Melon

Reputation: 614

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

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?

Upvotes: 4

Views: 951

Answers (1)

Kerrek SB
Kerrek SB

Reputation: 477580

List the libraries last:

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

Upvotes: 7

Related Questions