Forcing symbol export with MSVC

后端 未结 5 532
我寻月下人不归
我寻月下人不归 2020-12-25 08:38

I have a application and several plugins in DLL files. The plugins use symbols from the application via a export library. The application links in several static libraries a

5条回答
  •  春和景丽
    2020-12-25 09:17

    The "Use Library Dependency Inputs" option does the trick in VS2005!

    This option can be found under Configuration Properties -> Linker -> General -> Use Library Dependency Inputs. Set to "true" to force linking in ALL symbols & code declared in every LIB specified as input to the project.

    You can do the following to get the symbol to export from the DLL: define LIB_EXPORTS in the library project and nothing in either the DLL project or the DLL client project.

    #ifdef LIB_EXPORTS
    #define DLLAPI __declspec(dllexport)
    #else
    #define DLLAPI __declspec(dllimport)
    #endif
    

    Turns out there is no need #include any headers from the LIB project when compiling the DLL project; just specify the LIB as a linker input. However, if you need to make use of the LIB code from within the DLL, you will need to #define DLLAPI as an empty macro; setting the symbol(s) to either dllexport or dllimport will generate an error or a warning, respectively.

提交回复
热议问题