我想使用 MSVC 编译器来构建一个 DLL 文件。
问题是 DLL 没有主入口点。它应该是一个共享 DLL,用作应用程序的插件。我可以这样使用 GCC 编译它:
gcc -c plugin.c
gcc -shared -o plugin.dll plugin.o interface.def
DEF 文件是为了避免插件函数导出中的名称修改(这是应用程序使用插件的方式,通过该函数)。
如果我尝试使用 MSVC 编译它,链接器会提示必须定义入口点。
我想问另一个问题,MS Visual Studio 套件中有没有像 GCC“strip”这样的工具来减少 EXE 的文件大小?
最佳答案
虽然 DLL 不需要入口点,但 Microsoft C 运行时需要一个入口点来初始化自身。有没有理由没有空的 DllMain?
When building a DLL which uses any of the C Run-time libraries, in order to ensure that the CRT is properly initialized, either
the initialization function must be named DllMain() and the entry point must be specified with the linker option -entry:_DllMainCRTStartup@12 - or -
the DLL's entry point must explicitly call CRT_INIT() on process attach and process detach
KB94248
关于c - 使用 MSVC 从命令行构建 DLL(无入口点),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1373783/