Visual C++ - Linking plugin DLL against EXE?

后端 未结 4 1265
甜味超标
甜味超标 2021-02-04 13:34

I\'m in the process of porting a large C++ application from Linux (gcc) to Windows (Visual C++ 2008) and am having linker issues with plugins. On Linux this wasn\'t an issue, as

相关标签:
4条回答
  • 2021-02-04 13:43

    You can't, easily. The windows loader isn't designed to export symbols out of an EXE and bind them to symbols in a DLL.

    One pattern that I have seen is the DLL export a certain function that the EXE calls. It takes as a parameter a structure which contains addresses of functions in the EXE for the DLL to call.

    0 讨论(0)
  • 2021-02-04 13:50

    What do you mean by "runtime symbol lookup"? Do you mean dynamically loading libraries using dlopen and dlsym and so on? The equivalents in Windows are called LoadLibrary and GetProcAddress.

    In windows, you don't export symbols from a executable. You should only export them from a dll. The right way to solve your problem is to rearchitect so that the exported symbols are in a dll that the executable and other plugin dlls can link against.

    0 讨论(0)
  • 2021-02-04 13:55

    As 1800 INFORMATION says, don't do it like that. Move Object out of the executable and into a "third" DLL. Link the plugins and the executable against that.

    0 讨论(0)
  • 2021-02-04 14:07

    I have been implementing the same, constructing a plugin library to build under both Linux and Windows.

    The solution under Linux is to use the -rdynamic option in the gcc command line. This exports all of the symbols in the main executable, so that a plugin can find them on loading.

    Under Windows, the solution is to add __declspec(dllexport) in front of the definition of those functions in the exe that you want the dlls to use. Compilation will create a .lib file for the dlls to link to. Certainly works under Visual studio 2008. Related post: https://stackoverflow.com/a/3756083/1486836

    0 讨论(0)
提交回复
热议问题