I’m creating a simple spell checker program with the use of static libraries, as I want other people to be able to use the spell checker functions. The two problem areas are in the library source code and the library header. When I compile the library, this is the error I get:
ar -cvq libspellcheck.a checker.o
a - checker.o
g++ -o spell-check main.o meta.o libspellcheck.a
libspellcheck.a(checker.o): In function `check_spelling(char*, char*)':
checker.cpp:(.text+0x0): multiple definition of `check_spelling(char*, char*)'
libspellcheck.a(checker.o):checker.cpp:(.text+0x0): first defined here
collect2: ld returned 1 exit status
make: *** [spellcheck] Error 1
The checker.cpp code is located here.
The header file (spellcheck.h) is located here.
What I would like to know is what is causing the errors above, as I can’t figure it out.
It looks as though you’ve added
checker.cppto the archive twice.Try using this command instead:
Using
rinstead ofqwill replace any existing file with the same name, rather than adding another copy of it.Alternatively, just ensure you delete the archive before you add any files to it, so it always starts empty.