Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt program terminates upon link to a static library.



  • Hello ,
    I am trying to link against a static library to run an examples and make sure it works before I invest more into it .It compiles without problem but when run the program terminates with a console message " Press <RETURN > to close this window" .

    My minimal .pro file looks like this
    @

    LIBS += -L$$PWD/libraries/lib/ -llibzinnia
    INCLUDEPATH += $$PWD/libraries/include
    DEPENDPATH += $$PWD/libraries/include

    @

    and my main function like this
    @

    #include <iostream>
    #include "zinnia.h"

    int main()

    {

    zinnia::Recognizer *recognizer = zinnia::Recognizer::create();
    std::cout<<"TEST IF THE PROGRAM GETS HERE"<<std::endl;
    .............

    return 0;
    }

    @

    The program exists as soon as I call something from the library.(even the test line is not printed out).The same thing happened to me a few days ago with another library so I think I am doing something wrong linking against libraries here.Or might this have something to do with the system that compiled the libraries?

    I am working on windows7 Qt 4.8.1 Creator 2.7.1 and msvc2010.I tried on my other setup with msvc2008 and hit the same issue.

    Any help would be appreciated.Thanks.



  • Hi,

    can you post come slice of code?



  • Did you compile the static library with different flags or even a different compiler?
    Your application and the static library must be binary compatible.



  • Thanks guys for the answers,

    here is the complete .pro file

    @

    TEMPLATE = app
    CONFIG += console
    CONFIG -= app_bundle
    CONFIG -= qt

    LIBS +=-L$$PWD/libraries/lib/ -llibzinnia
    INCLUDEPATH += $$PWD/libraries/include
    DEPENDPATH += $$PWD/libraries/include

    SOURCES += main.cpp

    HEADERS +=
    libraries/include/zinnia.h

    @

    and here is my main.cpp file

    @

    #include <iostream>
    #include "zinnia.h"

    int main(int argc, char **argv) {
    zinnia::Recognizer *recognizer = zinnia::Recognizer::create();
    if (!recognizer->open("/usr/local/lib/zinnia/model/tomoe/handwriting-ja.model")) {
    std::cerr << recognizer->what() << std::endl;
    return -1;
    }

    zinnia::Character *character = zinnia::Character::create();
    character->clear();
    character->set_width(300);
    character->set_height(300);
    character->add(0, 51, 29);
    character->add(0, 117, 41);
    character->add(1, 99, 65);
    character->add(1, 219, 77);
    character->add(2, 27, 131);
    character->add(2, 261, 131);
    character->add(3, 129, 17);
    character->add(3, 57, 203);
    character->add(4, 111, 71);
    character->add(4, 219, 173);
    character->add(5, 81, 161);
    character->add(5, 93, 281);
    character->add(6, 99, 167);
    character->add(6, 207, 167);
    character->add(6, 189, 245);
    character->add(7, 99, 227);
    character->add(7, 189, 227);
    character->add(8, 111, 257);
    character->add(8, 189, 245);

    zinnia::Result *result = recognizer->classify(*character, 10);
    if (!result) {
    std::cerr << recognizer->what() << std::endl;
    return -1;
    }
    for (size_t i = 0; i < result->size(); ++i) {
    std::cout << result->value(i) << "\t" << result->score(i) << std::endl;
    }
    delete result;

    delete character;
    delete recognizer;

    return 0;
    }

    @

    I did not build the static lib myself,I got it from this "engine":http://zinnia.sourceforge.net/ that I am trying to use into my application.
    [quote author="DerManu" date="1372752311"]Did you compile the static library with different flags or even a different compiler?
    Your application and the static library must be binary compatible.[/quote]
    Unfortunately I can't know yet which compiling env was used to build the lib.Does this mean it can only be used with the same environment it was built with?
    Thanks.



  • [quote author="musimbate" date="1372753233"]Unfortunately I can't know yet which compiling env was used to build the lib.Does this mean it can only be used with the same environment it was built with?[/quote]

    Yes, the restriction of binary compatibility can easily be broken, e.g. by "using a different compiler or even compiler version":http://www.mingw.org/wiki/Interoperability_of_Libraries_Created_by_Different_Compiler_Brands.

    Shared libraries are a bit less restrictive in that respect.



  • Thanks again DerManu for the input.
    I know it was built with msvc because it has a .lib extension.I thought you meant which version of msvc(my bad).
    But it should work across all msvc compilers right?I mean I have been compiling applications that used static libs and so far they have worked on 2008 and 2010.

    Edit: after reading your doc thoroughly,I know that even different versions can cause problems.I look into this.


Log in to reply