Character compilation when compiling a DLL - MSVC

I have a shared library that uses CMake as a build system. It compiles fine on Linux machines with GCC. Now I am trying to compile windows. MSVC will not export characters until the specified. I know about __declspec(dllexport) . But the example provided on the CMake wiki is confusing. Please consider the following code.

 #if defined (_WIN32) #if defined(MyLibrary_EXPORTS) #define MYLIB_EXPORT __declspec(dllexport) #else #define MYLIB_EXPORT __declspec(dllimport) #endif /* MyLibrary_EXPORTS */ #else /* defined (_WIN32) */ #define MYLIB_EXPORT #endif 

I understand __declspec(dllexport) , but I wonder why __declspec(dllimport) ? Also how can I use this? MYLIB_EXPORT void function() this look like MYLIB_EXPORT void function() ?

I have a C function called foo() . This internally uses several static functions. When exporting, do I need to export static functions as well? Or is it enough to export only the input functions that are part of the API?

Any help would be greatly appreciated.

+4
source share
2 answers

It is enough to export only input functions that are part of the API. No need to export static functions.

In addition, there is no need to use __declspec (dllimport) for functions. This is only for data. Windows will automatically take care of importing features.

The links below are:

http://msdn.microsoft.com/en-us/library/ms235636(VS.80).aspx

http://msdn.microsoft.com/en-us/library/ms682589(VS.85).aspx

+5
source

This is usually used for the header file, which is used by both your compilation library and its clients; when you include a title in your library, you define MyLibrary_EXPORTS and it will export characters; when you include a title in a client application, it will import them instead.

No, you only need to export API entry points - you do not need to export static functions.

+1
source

All Articles