Building dllimport / dllexport and static libraries in Visual C ++

I desperately need your help.

Im trying to copy the poppler static library (specifically for qt4) on Windows using the Visual C ++ 2008 compiler. To achieve this, I needed to compile many other libraries as dependencies for poppler statically. When I finally create a static version of poppler, I got a binding error while creating my application:

error LNK2019: unresolved external symbol "__declspec(dllimport)...

I already added a new include path and linked poppler-qt4.lib, but I still get the error. Finding a solution I found this discussion here on stackoverflow

How to link a static library in Visual C ++ 2008?

whit this information I looked at the included library files (poppler dependencies such as zlib, libpng, cairo, ...), and I found, on different occasions, that they did not have a preprocessor directive to determine the static version of lib. Example static directive (openjpeg.h):

#if defined(OPJ_STATIC) || !(defined(_WIN32) || defined(WIN32) || defined(__WIN32__))
# define OPJ_API
# define OPJ_CALLCONV
#else
# define OPJ_CALLCONV __stdcall
# ifdef OPJ_EXPORTS
#  define OPJ_API __declspec(dllexport)
# else
#  define OPJ_API __declspec(dllimport)
# endif /* OPJ_EXPORTS */
#endif /* !OPJ_STATIC || !WIN32 */

Example without a static directive (jconfig.h from jpeg lib):

#if defined(_WIN32)
    #if defined(libjpeg_EXPORTS)
        #define JPEG_EXPORT __declspec(dllexport)
    #else
        #define JPEG_EXPORT __declspec(dllimport)
    #endif
#else
    #define JPEG_EXPORT 
#endif

My question is: is it not enough to change the project properties from dynamic to static, so do I also need to change these headers ?, and if this is true, where can I define these new directives in order to make the difference between static or dynamic compilation?

Thanks in advance.

+3
source share
2 answers

, openjpeg.h, , . , , OPJ_STATIC...

:

#if defined(_WIN32)
    #if defined(OPJ_STATIC)
         # define OPJ_CALLCONV __stdcall
    #el if defined(libjpeg_EXPORTS)
        #define JPEG_EXPORT __declspec(dllexport)
    #else
        #define JPEG_EXPORT __declspec(dllimport)
    #endif
#else
    #define JPEG_EXPORT 
#endif
+2

, , Windows . ! thunks. , : dllexport, , , dllexport. .

, dllimport, , , C __imp_ , ++.

, DLL, DLL (), LIB. . , . , DLL, LIB dllimport, __imp_ ++.

, DLL, DLL, LIB. LIB - thunks, DLL.

, LIB, LIB.EXE, OBJ , dllexport, , dllimport. __imp_function(), ().

, dllimport. AFAIK dllexport . , , .

? , , , . Windows C runtime OS DLL. , : , . , ! ( LINK, DLL, fred.LIB, LIB fred.LIB)

0

Source: https://habr.com/ru/post/1788771/


All Articles