How to use an external static library in a Qt project in Qt Creator?

128 Views Asked by At

I am trying to import an external static library in my project. I have added .h files in my Qt Project and added the static library via the import external library option.

test.h:

#ifndef TEST_LIB_H 
#define TEST_LIB_H 

int Start_test(); 

#endif // TEST_LIB_H

test.c:

#include "../inc/test.h" 

int Start_test() 
{ 
    int a =4;
    int b =1;
    int somme =a+b;

    return somme; 
}

pro file:

CONFIG += c++11 

LIBS += -lws2_32 win32: 
LIBS += -L$$PWD/../testLib/lib/ -ltest 

INCLUDEPATH += $$PWD/../testLib 
DEPENDPATH += $$PWD/../testLib 

win32:!win32-g++: PRE_TARGETDEPS += $$PWD/../testLib/lib/test.lib 
else:win32-g++: PRE_TARGETDEPS += $$PWD/../testLib/lib/libtest.a

But I am getting this error message:

Undefined reference to 'Start_test'
collect2.exe: error: ld returned 1 exit status

Note: I am using MingW for compiling the library and the Qt project.

Tried to place it in the same folder as the Qt project, but same result.

0

There are 0 best solutions below