简体   繁体   中英

C++ Static Library Linker Error

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.

问题似乎是两次链接checker.cpp-您可以添加您的makefile文件(还要确保在checker.cpp中没有两次定义check_spelling并尝试在构建之前清理中间文件)吗?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM