c++ - 警告 : resolving Func by linking to Func@##

标签 c++

我正在构建一个包含以下内容的 DLL:

extern "C" __declspec(dllexport) void __stdcall DrawMouse(int X, int Y, int R, int G, int B)
{
    Buffer.SetMouse(X, Y, R, G, B);
}

然后在 .def 文件中我添加了:

LIBRARY Test
;DESCRIPTION "Test Definition File"
EXPORTS

DrawMouse;

然后当我编译时,我添加链接器选项:

-static
-static-libstdc++
-static-libgcc
-Wl,--kill-at -d --input-def src\Test.def
-m32

输出是:

Warning: Resolving _DrawMouse by linking to _DrawMouse@24

为什么?为什么它警告我要解决,我怎样才能摆脱它?对于大量导出,我收到大量警告..

小例子:

主要.cpp:

#include <windows.h>

class Input
{
    public:
        void SetMouse(int X, int Y, int R, int G, int B)
        {
            /**Dummy Example**/
        }
};



Input Buffer;
extern "C" void __stdcall SetMouse2(int X, int Y, int R, int G, int B)
{
    /**Dummy Non-Class Example**/
}

extern "C" __declspec(dllexport) void __stdcall DrawMouse(int X, int Y, int R, int G, int B)
{
    Buffer.SetMouse(X, Y, R, G, B);
}

extern "C" __declspec(dllexport) void __stdcall DrawMouse2(int X, int Y, int R, int G, int B)
{
    SetMouse2(X, Y, R, G, B);
}

extern "C" __declspec(dllexport) bool __stdcall DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            DrawMouse(100, 100, 1, 1, 1);
            DrawMouse2(100, 100, 1, 1, 1);
            break;

        case DLL_PROCESS_DETACH:
            break;
    }
    return true;
}

测试.def:

LIBRARY Test
;DESCRIPTION "Test Definition File"
EXPORTS

DrawMouse;
DrawMouse2;

编译器日志:

-------------- Clean: Release in Test (compiler: GNU GCC Compiler)---------------

Cleaned "Test - Release"

-------------- Build: Release in Test (compiler: GNU GCC Compiler)---------------

x86_64-w64-mingw32-g++.exe  -O2  -Wall -m32 -DBUILD_DLL  -std=c++11    -c C:\Users\Brandon\Desktop\Test\main.cpp -o obj\Release\main.o

x86_64-w64-mingw32-g++.exe -shared -Wl,--output-def=bin\Release\libTest.def -Wl,--out-implib=bin\Release\libTest.a -Wl,--dll  obj\Release\main.o   -o bin\Release\Test.dll -s -static -static-libstdc++ -static-libgcc -Wl,--kill-at -d --input-def Test.def -m32  -luser32 

Warning: resolving _DrawMouse by linking to _DrawMouse@20
Warning: resolving _DrawMouse2 by linking to _DrawMouse2@20
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups

Output size is 32.50 KB
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 2 warnings (0 minutes, 0 seconds)

注意:--disable-stdcall-fixup 不起作用。这就是为什么我要问如何解决这个问题并消除这些警告以及导致它们的原因。

编辑:

按要求修复的命令行:

x86_64-w64-mingw32-g++.exe  -O2  -Wall -m32 -DBUILD_DLL  -std=c++11    -c C:\Users\Brandon\Desktop\Test\main.cpp -o obj\Release\main.o

x86_64-w64-mingw32-g++.exe -shared -Wl,--output-def=bin\Release\libTest.def -Wl,--out-implib=bin\Release\libTest.a -Wl,--dll  obj\Release\main.o   -o bin\Release\Test.dll -s -static -static-libstdc++ -static-libgcc -Wl,--kill-at -d --input-def Test.def -m32 --disable-stdcall-fixup  -luser32 

还试过:

x86_64-w64-mingw32-g++.exe  -O2  -Wall -m32 -DBUILD_DLL  -std=c++11    -c C:\Users\Brandon\Desktop\Test\main.cpp -o obj\Release\main.o

x86_64-w64-mingw32-g++.exe -shared -Wl,--output-def=bin\Release\libTest.def -Wl,--out-implib=bin\Release\libTest.a -Wl,--dll  obj\Release\main.o   -o bin\Release\Test.dll -s -static -static-libstdc++ -static-libgcc -Wl,--kill-at -d --input-def Test.def -m32 --enable-stdcall-fixup  -luser32 

都不行。

最佳答案

您需要向链接器提供 --enable-stdcall-fixup(它会自动修复问题)。当与 gccg++ 一起使用时,这意味着 -Wl,--enable-stdcall-fixup

有关这些选项的详细信息,请查看 Gnu Linker options 的第 2.1.1 节.

关于c++ - 警告 : resolving Func by linking to Func@##,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16911866/

相关文章:

c++ - 如何正确升级您的 OpenMP 版本?

c++ - boost:如何监视互斥体的状态并在死锁时强制释放

c# - 控制台应用程序的返回码

c++ - 使用 C++14 lambda 测量任意函数的执行时间

c++ - Intel one-api 编译器在编译 GDAL cpp 文件时出错

c++ - QT构建QWidget、QObject错误

c++ - 管道优化,这样做有什么意义吗?

c++ - 如何用R读取msg文件

c++ - GLES 程序资源索引/位置与统一索引/位置

java - 使用 SWIG 返回一个 java 对象数组