简体   繁体   中英

Error when statically-linking to libzbar.a: undefined reference to `_imp__GetACP@0'

I link to zbar from my program. I've built zbar using mingw/msys. My application is built using Qt Creator.

When I link dynamically to zbar using libzbar.dll.a , it compiles and runs fine. When I link to libzbar.a , building my application fails with a linker error:

C:/Qt/Tools/mingw491_32/bin/../lib/gcc/i686-w64-mingw32/4.9.1/../../../../i686-w64-mingw32/lib/../lib/libiconv.a(localcharset.o):localcharset.c:(.text+0x7): undefined reference to `_imp__GetACP@0'
collect2.exe: error: ld returned 1 exit status

This convoluted path - C:/Qt/Tools/mingw491_32/bin/../lib/gcc/i686-w64-mingw32/4.9.1/../../../../i686-w64-mingw32/lib/../lib/libiconv.a - resolves to C:\\Qt\\Tools\\mingw491_32\\i686-w64-mingw32\\lib\\libiconv.a . So it seems that Qt Creator is trying to link against its own libiconv.a , which is missing some functions that libzbar.a needs to use.

I'm not sure how to make Qt Creator use the msys libiconv.a , I tried this:

LIBS += c:/mingw/lib/libiconv.a
LIBS += $$PWD/zbar/lib/libzbar.a

But it had no effect, I'm getting the same error. How do I convince Qt Creator to use c:/mingw/lib/libiconv.a instead of its own version?

Edit: Here is the smallest code that reproduces the error:

#define NULL 0
#include <zbar.h>
int main()
{
    zbar::ImageScanner scanner;
    return 0;
}

And in the .pro file I have:

INCLUDEPATH += c:/MinGW/msys/1.0/local/include
LIBS += -Lc:/MinGW/msys/1.0/local/lib -lzbar

Many thanks to @skypjack, his solution works. I'll only add some things I found out by testing it:

PRE_TARGETDEPS was not really necessary, those 3 lines are sufficient to make the project compile:

INCLUDEPATH += c:/MinGW/msys/1.0/local/include
LIBS += c:/MinGW/msys/1.0/local/lib/libzbar.a
LIBS += c:/MinGW/lib/libiconv.a

Which was strange because I distinctly remember trying this even before posting my question on SO. But after swapping the last 2 lines :

INCLUDEPATH += c:/MinGW/msys/1.0/local/include
LIBS += c:/MinGW/lib/libiconv.a
LIBS += c:/MinGW/msys/1.0/local/lib/libzbar.a

the error returned. I had indeed put libiconv.a before libzbar.a , so the error really was because of link-order.

Edit: In the end, it worked even with Qt Creator's own libiconv, it was just that I needed to add it after zbar:

LIBS += -Lc:/MinGW/msys/1.0/local/lib -lzbar -liconv

Try with a .pro file like the following one:

TEMPLATE=app
TARGET=appname
SOURCES=main.cpp
PRE_TARGETDEPS += c:/MinGW/msys/1.0/local/lib/libzbar.a
PRE_TARGETDEPS += c:/MinGW/msys/1.0/local/lib/libiconv.a
INCLUDEPATH += c:/MinGW/msys/1.0/local/include
win32:LIBS += c:/MinGW/msys/1.0/local/lib/libzbar.a
win32:LIBS += c:/MinGW/msys/1.0/local/lib/libiconv.a
// ... continue

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