c - 使用 MSVC 从命令行构建 DLL(无入口点)

标签 c visual-studio dll visual-c++

我想使用 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

  1. the initialization function must be named DllMain() and the entry point must be specified with the linker option -entry:_DllMainCRTStartup@12 - or -

  2. 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/

相关文章:

c - 解析 IP header 时出错

visual-studio - 内部 NuGet 服务器无法访问

c - 当 GDB 崩溃/出现段错误时如何编辑正在运行的程序

c - C 中的 Winsock 文件传输

android - 您如何启动 VS Android 模拟器图像?

c++ - 配置 Visual Studio 以创建 32 位和 64 位配置

c# - 委托(delegate)从引用的 C++ DLL 触发 C# 函数

c++ - collect2.exe : error: ld returned 5 exit status

c++ - 从 C++ 中静态对象的 C'tor 抛出/捕获异常

c - 有没有办法让 dirent 的 ent->d_name 作为 w_char * ?