M
M
Mars362020-12-15 20:10:31
Qt
Mars36, 2020-12-15 20:10:31

How to connect a static library to a project in QT Creator under windows?

I'm trying to connect the P7 static logger library to my application. I built the logger using cmake according to the instructions in the documentation, i.e.


cd *p7_folder_path*
mkdir *_build_*
cd *_build_*
cmake ..

after assembly, I received several projects for MCVS, built a lib with it, got p7.lib at the output, connected it to my project through the creator's manager, chose an external one, indicated the path to the lib, left the checkboxes only for Windows. In the pro file, added the path to the headers. As a result, the pro file looks like this:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../logger/_build_/Sources/release/ -lp7
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../logger/_build_/Sources/debug/ -lp7

INCLUDEPATH += $$PWD/../../logger/_build_/Sources/Debug
DEPENDPATH += $$PWD/../../logger/_build_/Sources/Debug

win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../logger/_build_/Sources/release/libp7.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../logger/_build_/Sources/debug/libp7.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../logger/_build_/Sources/release/p7.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../logger/_build_/Sources/debug/p7.lib

SOURCES += \
        main.cpp

INCLUDEPATH += D:/Example/logger/Headers

This is what main.cpp looks like
#include <iostream>
#include "GTypes.h"
#include "P7_Client.h"
#include "P7_Trace.h"

using namespace std;

int main()
{
    IP7_Client* l_pClient = P7_Create_Client( TM( "/P7.Sink=FileTxt" ) );

    if ( l_pClient == NULL ) {
        cout << "Error IP7_Client" << endl;
    }

    IP7_Trace* l_pTrace = P7_Create_Trace( l_pClient, TM( "Test" ) );
    l_pTrace->P7_WARNING( 0, TM( "Test" ) );
    l_pClient->Release();
    return 0;
}

The IDE, in theory, sees everything and does not swear at anything.
But during assembly, a couple of dozen errors like:
p7.lib(ClBaical.obj):-1: ошибка: LNK2019: ссылка на неразрешенный внешний символ __WSAFDIsSet в функции "public: enum eSocket_Status __cdecl CUDP_Socket::Is_Ready(enum eFD_Type,unsigned int)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]).
p7.lib(ClText.obj):-1: ошибка: LNK2001: неразрешенный внешний символ __imp_bind.

All errors refer to linking, i.e. either LNK2001 or LNK2019.
I'm compiling lib for the first time and maybe I'm missing something obvious, which is not indicated in the documentation, because. the author considers it obvious.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ighor July, 2020-12-15
@Mars36

In addition to linking a lib, you also need to link its dependencies.
__WSAFDIsSet for example here https://docs.microsoft.com/en-us/windows/win32/api...
LIBS += -lWs2_32

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question