Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt program terminates upon link to a static library.

Qt program terminates upon link to a static library.

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • musimbateM Offline
    musimbateM Offline
    musimbate
    wrote on last edited by
    #1

    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.

    Why join the navy if you can be a pirate?-Steve Jobs

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      can you post come slice of code?

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DerManu
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • musimbateM Offline
          musimbateM Offline
          musimbate
          wrote on last edited by
          #4

          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.

          Why join the navy if you can be a pirate?-Steve Jobs

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DerManu
            wrote on last edited by
            #5

            [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.

            1 Reply Last reply
            0
            • musimbateM Offline
              musimbateM Offline
              musimbate
              wrote on last edited by
              #6

              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.

              Why join the navy if you can be a pirate?-Steve Jobs

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved