2

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.

2 Answers 2

3

It looks as though you've added checker.cpp to the archive twice.

Try using this command instead:

ar -cvr libspellcheck.a checker.o 

Using r instead of q will 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.

Sign up to request clarification or add additional context in comments.

Comments

3

The problem seems to be linking checker.cpp twice - can you add your makefiles (also make sure check_spelling isn't defined twice in checker.cpp and try to clean the intermediary files before build)?

1 Comment

No, you can clearly see from the error both versions are inside the archive. Defining a function twice in one translation unit would be a compiler error.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.