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. Problem with linking library

Problem with linking library

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 685 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.
  • K Offline
    K Offline
    kokodyn
    wrote on last edited by kokodyn
    #1

    Hi,
    I use Qt_5_9_4_MSVC2015_64bit. I try to write unit test for my classes.
    :-1: error: LNK1104: cannot open file 'myapp.lib'
    Can you help me to solve it, please?
    Is my structure o project is, ok?
    Structure of my project look like here:
    Game:
    |game.pro
    |test
    |@test.pro
    |@main.cpp
    |src
    |@src.pro
    |@source.h
    |@source.cpp
    |app
    |@app.pro
    |@main.cpp

    Files looks:
    game.pro:
    TEMPLATE = subdirs
    CONFIG += ordered

    SUBDIRS +=
    src
    tests
    app

    app.depends = src
    tests.depends = src
    ......................................................
    app.pro
    include(../defaults.pri)

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

    SOURCES += main.cpp

    LIBS += -L../src -lmyapp
    ......................................................
    main.cpp
    #include <iostream>
    int main(int argc, char *argv[])
    {
    std::cout << "main in app";
    return 0;
    }
    ......................................................

    src.pro
    include(../defaults.pri)
    CONFIG -= qt

    TARGET = myapp
    TEMPLATE = lib

    SOURCES +=
    source.cpp
    HEADERS +=
    source.h
    ......................................................
    source.h
    #ifndef SOURCE_H
    #define SOURCE_H

    class Source
    {
    public:
    Source();
    };

    #endif // SOURCE_H

    source.cpp
    #include "source.h"

    Source::Source()
    {

    }
    ......................................................
    tests.pro
    include(../defaults.pri)
    TEMPLATE = app

    CONFIG += console
    CONFIG -= app_bundle
    CONFIG += qt qwidgets
    QT += testlib

    HEADERS += cardsbuildertest.h
    SOURCES +=
    cardsbuildertest.cpp
    main.cpp
    LIBS += -L../src -lmyapp
    ......................................................
    main.cpp
    #include "cardsbuildertest.h"
    #include <source.h>
    int main(int argc, char *argv[])
    {

    Source source = Source();
    return 0;
    }

    aha_1980A 1 Reply Last reply
    0
    • K kokodyn

      Hi,
      I use Qt_5_9_4_MSVC2015_64bit. I try to write unit test for my classes.
      :-1: error: LNK1104: cannot open file 'myapp.lib'
      Can you help me to solve it, please?
      Is my structure o project is, ok?
      Structure of my project look like here:
      Game:
      |game.pro
      |test
      |@test.pro
      |@main.cpp
      |src
      |@src.pro
      |@source.h
      |@source.cpp
      |app
      |@app.pro
      |@main.cpp

      Files looks:
      game.pro:
      TEMPLATE = subdirs
      CONFIG += ordered

      SUBDIRS +=
      src
      tests
      app

      app.depends = src
      tests.depends = src
      ......................................................
      app.pro
      include(../defaults.pri)

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

      SOURCES += main.cpp

      LIBS += -L../src -lmyapp
      ......................................................
      main.cpp
      #include <iostream>
      int main(int argc, char *argv[])
      {
      std::cout << "main in app";
      return 0;
      }
      ......................................................

      src.pro
      include(../defaults.pri)
      CONFIG -= qt

      TARGET = myapp
      TEMPLATE = lib

      SOURCES +=
      source.cpp
      HEADERS +=
      source.h
      ......................................................
      source.h
      #ifndef SOURCE_H
      #define SOURCE_H

      class Source
      {
      public:
      Source();
      };

      #endif // SOURCE_H

      source.cpp
      #include "source.h"

      Source::Source()
      {

      }
      ......................................................
      tests.pro
      include(../defaults.pri)
      TEMPLATE = app

      CONFIG += console
      CONFIG -= app_bundle
      CONFIG += qt qwidgets
      QT += testlib

      HEADERS += cardsbuildertest.h
      SOURCES +=
      cardsbuildertest.cpp
      main.cpp
      LIBS += -L../src -lmyapp
      ......................................................
      main.cpp
      #include "cardsbuildertest.h"
      #include <source.h>
      int main(int argc, char *argv[])
      {

      Source source = Source();
      return 0;
      }

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi @kokodyn, welcome.

      What is the problem you encounter?

      Qt has to stay free or it will die.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kokodyn
        wrote on last edited by kokodyn
        #3

        I forgot to add a problem code, this is:
        :-1: error: LNK1104: cannot open file 'myapp.lib'
        Can you help me to solve it, please?
        Is my project structure is ok?
        After dividing tests and source code, I had a problem to include headers from source code to use it in test.

        aha_1980A 1 Reply Last reply
        0
        • K kokodyn

          I forgot to add a problem code, this is:
          :-1: error: LNK1104: cannot open file 'myapp.lib'
          Can you help me to solve it, please?
          Is my project structure is ok?
          After dividing tests and source code, I had a problem to include headers from source code to use it in test.

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @kokodyn without having a deeper look, you need to asure two things:

          1. make sure the lib is built before anything else
          2. give the linker the (relative) path to your lib

          I only have the phone now, so no deeper analysys possible from my side...

          Qt has to stay free or it will die.

          1 Reply Last reply
          2
          • K Offline
            K Offline
            kokodyn
            wrote on last edited by
            #5

            @aha_1980 thanks for answer!
            The problem was because myapp.lib was never created.
            It was caused by lack of:
            __declspec(dllexport)
            In class source.h
            Without this only myapp.dll file was created.
            Is my project structure is ok? Spliting to directories and static linking tests and source code is the way how it is should be done?

            aha_1980A 1 Reply Last reply
            0
            • K kokodyn

              @aha_1980 thanks for answer!
              The problem was because myapp.lib was never created.
              It was caused by lack of:
              __declspec(dllexport)
              In class source.h
              Without this only myapp.dll file was created.
              Is my project structure is ok? Spliting to directories and static linking tests and source code is the way how it is should be done?

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @kokodyn from a short glance, the structure is good.

              If you prefer static or dynamic linking is a matter of taste, just mind the license you are using and if it allows static linking.

              Qt has to stay free or it will die.

              1 Reply Last reply
              2

              • Login

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