vc写的dll被mingw的g++编译引用

dll.cpp,用vc2017编译

#include <iostream>
#include <windows.h>

extern "C" __declspec(dllexport) void Go() {
  std::cout << "go" << std::endl;
}

BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

main.cpp 用mingw64的g++编译

#include <iostream>

extern "C" __declspec(dllimport) void Go();
int main (int argc, char **argv)
{ 

  Go();
  return 0;
}

将dll.lib dll.dll dll.exp dll.pdb复制到main.cpp当前目录,编译:

g++ main.cpp -ldll -L.

扫描二维码关注公众号,回复: 1069154 查看本文章

猜你喜欢

转载自www.cnblogs.com/yuanxiaoping_21cn_com/p/9101306.html