dllexport - Qt and using an existing win32 dll -
i want development work using qt. have built several small apps , followed tutorials. all's fine , seems straight forward.
the development done involves using existing code contained in win32 dlls. want reuse code minimum fuss , link them qt app. have headers, libs , dlls i'll linking @ compile time not dynamically @ runtime.
i have tried qt complains complains link errors similar to: main.obj:-1: error: lnk2019: unresolved external symbol _imp_add referenced in function _main
no matter how tweak .pro file complains.
i've spent many hours googling , found snippets of info. not find 1 answer told whole story. i'm after set of steps, tutorial sequence needs followed. there may example in qt installation examples i've been unable find it.
here simple 'knock-up' i've been trying work in order move on main development. it's based on ms tutorial dll mathsfunc.
the win32 dll:
// visual studio 2005 //funcs.h #ifdef mathfuncs_exports #define mathfuncsdll_api __declspec(dllexport) #else #define mathfuncsdll_api __declspec(dllimport) #endif #ifdef __cplusplus extern "c" { /* assume c declarations c++ */ #endif // returns + b mathfuncsdll_api double add(double a, double b); #ifdef __cplusplus } /* assume c declarations c++ */ #endif //funcs.cpp #include "funcs.h" double add(double a, double b) { return + b; }
the qt app imports dll.
//main.cpp #include <qcoreapplication> #include "../../mathfuncs/funcs.h" int main(int argc, char *argv[]) { qcoreapplication a(argc, argv); double dresult = add(1.0,2.0); printf("1 + 2 = %f\n",dresult); return a.exec(); }
//the qt project file .por
#------------------------------------------------- # # project created qtcreator 2013-03-04t09:16:18 # #------------------------------------------------- qt += core qt -= gui target = useit config += console config -= app_bundle template = app sources += main.cpp includepath += c:/tmp/mathfuncs headers += c:/tmp/mathfuncs libs += c:/tmp/mathfuncs/mathfuncs.lib
thanks in advance input.
d.
Comments
Post a Comment