c - gcc static linking undefined references -


i made static library using ar make simple word counter, when reach linking stage in makefile, following error:

g++ -o wordcount obj/word.o obj/main.o   -wall -l lib  -llinkedlist obj/word.o: in function `cleanup(linkedlist*)': word.c:(.text+0x83): undefined reference `ll_clear(linkedlist*)' obj/word.o: in function `initialize(linkedlist*)': word.c:(.text+0xa7): undefined reference `ll_init(linkedlist*)' obj/word.o: in function `gettotalwordcount(linkedlist*)': word.c:(.text+0xbd): undefined reference `ll_getiterator(linkedlist*)' word.c:(.text+0xd7): undefined reference `ll_next(linkedlistiterator*)' word.c:(.text+0xea): undefined reference `ll_hasnext(linkedlistiterator*)' obj/word.o: in function `getword(linkedlist*, unsigned int)': word.c:(.text+0x118): undefined reference `ll_get(linkedlist*, unsigned int)' obj/word.o: in function `findword(linkedlist*, char*)': word.c:(.text+0x12e): undefined reference `ll_getiterator(linkedlist*)' word.c:(.text+0x148): undefined reference `ll_next(linkedlistiterator*)' word.c:(.text+0x178): undefined reference `ll_hasnext(linkedlistiterator*)' obj/word.o: in function `combinecounts(linkedlist*, worddata*)': word.c:(.text+0x26e): undefined reference `ll_add(linkedlist*, void const*, unsigned int)' obj/main.o: in function `main': main.c:(.text+0x1df): undefined reference `ll_getiterator(linkedlist*)' main.c:(.text+0x1f2): undefined reference `ll_next(linkedlistiterator*)' main.c:(.text+0x25c): undefined reference `ll_hasnext(linkedlistiterator*)' collect2: error: ld returned 1 exit status makefile:38: recipe target 'wordcount' failed make: *** [wordcount] error 1 

however, using nm @ symbol table library produces these results (truncated readability):

linkedlist.o: 00000028 t ll_add 00000124 t ll_addindex 000003b7 t ll_clear 00000363 t ll_get 00000438 t ll_getiterator 00000477 t ll_hasnext 00000000 t ll_init 00000493 t ll_next 00000285 t ll_remove 00000420 t ll_size 

all answers i've found similar questions mention order in specify libraries matters, adding library after other object files. have ideas might going wrong?

the issue library compiled c compiler, had compiled new sources reference library c++ compiler. object file output different between these 2 methods. take following code example:

// main.c #include <stdio.h>  void foo(int x) {   printf("%d\n"); }  int main(int argc, char** argv) {   foo(argc);   return 0; } 

compiling file object file c program produce different symbols compiling c++ program. example:

# compile c program $ gcc -c main.c; nm main.o 00000000 t foo 00000018 t main          u printf  # compile c++ program $ g++ -c main.c; nm main.o 00000018 t main          u printf 00000000 t _z3fooi 

as can see foo function compiled 2 different symbols. since new source files compiled c++, linker expected c++ style symbols while library contained c style symbols. linker couldn't match symbols , therefore throws error since c++ symbols undefined.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -