A
A
alexey7342014-05-27 15:04:49
C++ / C#
alexey734, 2014-05-27 15:04:49

How to fix libbson library linking error in Qt?

There is a need to use the libbson library https://github.com/mongodb/libbson written in C in a Qt project.
The library was built according to the instructions for Windows https://github.com/mongodb/libbson/blob/master/REA... using one of the proposed cmake generator "Visual Studio 11" (for Visual Studio 2012), msbuild.exe ALL_BUILD.vcxprojand
msbuild.exe INSTALL.vcxprojwere successful.
The library was installed in C:\install\path\.
In the .pro file of the Qt project, I connected the headers of the library

HEADERS += \
    C:/install/path/include/libbson-1.0/bcon.h \
    C:/install/path/include/libbson-1.0/bson.h \
    C:/install/path/include/libbson-1.0/bson-atomic.h \
    C:/install/path/include/libbson-1.0/bson-clock.h \
    C:/install/path/include/libbson-1.0/bson-compat.h \
    C:/install/path/include/libbson-1.0/bson-config.h \
    C:/install/path/include/libbson-1.0/bson-context.h \
    C:/install/path/include/libbson-1.0/bson-endian.h \
    C:/install/path/include/libbson-1.0/bson-error.h \
    C:/install/path/include/libbson-1.0/bson-iter.h \
    C:/install/path/include/libbson-1.0/bson-json.h \
    C:/install/path/include/libbson-1.0/bson-keys.h \
    C:/install/path/include/libbson-1.0/bson-macros.h \
    C:/install/path/include/libbson-1.0/bson-md5.h \
    C:/install/path/include/libbson-1.0/bson-memory.h \
    C:/install/path/include/libbson-1.0/bson-oid.h \
    C:/install/path/include/libbson-1.0/bson-reader.h \
    C:/install/path/include/libbson-1.0/bson-stdint.h \
    C:/install/path/include/libbson-1.0/bson-stdint-win32.h \
    C:/install/path/include/libbson-1.0/bson-string.h \
    C:/install/path/include/libbson-1.0/bson-types.h \
    C:/install/path/include/libbson-1.0/bson-utf8.h \
    C:/install/path/include/libbson-1.0/bson-value.h \
    C:/install/path/include/libbson-1.0/bson-version.h \
    C:/install/path/include/libbson-1.0/bson-writer.h

and indicated where to look for lib
LIBS += "C:\install\path\lib\bson-1.0.lib"
In the cpp file, I include the library header:
extern "C" {
#include "C:/install/path/include/libbson-1.0/bson.h"
}

And I try to use the libbson functions:
bson_t *bsonobj = bson_new();
I make a Clean project, Run qmake.
I build the project using the MSVC2012 64bit profile, the build fails with the following error:
moc_TestApp.obj:-1: ошибка: LNK2019: ссылка на неразрешенный внешний символ bson_new в функции "protected: void __cdecl TestApp::usageBson(class QTextStream &)" ([email protected]@[email protected]@@Z)

lib is visible because if I deliberately specify the wrong path in LIBS, then I get the error LNK1181
What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
drozdVadym, 2014-05-27
@alexey734

If it's not important to use this particular lib, you can try QJson
habrahabr.ru/post/147952
And in Qt 5.0 there is doc-snapshot.qt-project.org/5.0/qjsondocument.html
Why do you include all libbson headers in the project?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question