Unsolved Problem with linking library
-
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.cppFiles looks:
game.pro:
TEMPLATE = subdirs
CONFIG += orderedSUBDIRS +=
src
tests
appapp.depends = src
tests.depends = src
......................................................
app.pro
include(../defaults.pri)TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qtSOURCES += 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 -= qtTARGET = myapp
TEMPLATE = libSOURCES +=
source.cpp
HEADERS +=
source.h
......................................................
source.h
#ifndef SOURCE_H
#define SOURCE_Hclass Source
{
public:
Source();
};#endif // SOURCE_H
source.cpp
#include "source.h"Source::Source()
{}
......................................................
tests.pro
include(../defaults.pri)
TEMPLATE = appCONFIG += console
CONFIG -= app_bundle
CONFIG += qt qwidgets
QT += testlibHEADERS += 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;
} -
Hi @kokodyn, welcome.
What is the problem you encounter?
-
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. -
@kokodyn without having a deeper look, you need to asure two things:
- make sure the lib is built before anything else
- give the linker the (relative) path to your lib
I only have the phone now, so no deeper analysys possible from my side...
-
@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? -
@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.