C++ 如何阻止GNU GCC损坏dll导入函数名
GNU GCC正在损坏我导入的函数名,即使我在声明中使用了extern“C” 我刚刚开始使用代码::Builder和GNU GCC,用于从Borland C++ Builder 6 Pro中迁移现有项目,并开发一些未来项目。从长远来看,我将1)制作我想交给使用各种平台的最终开发人员的.dll(即,.dll将不会严格留在内部),2)制作使用这些.dll的代码::块中的程序C++ 如何阻止GNU GCC损坏dll导入函数名,c++,gcc,codeblocks,C++,Gcc,Codeblocks,GNU GCC正在损坏我导入的函数名,即使我在声明中使用了extern“C” 我刚刚开始使用代码::Builder和GNU GCC,用于从Borland C++ Builder 6 Pro中迁移现有项目,并开发一些未来项目。从长远来看,我将1)制作我想交给使用各种平台的最终开发人员的.dll(即,.dll将不会严格留在内部),2)制作使用这些.dll的代码::块中的程序 当我尝试迁移第一个项目,它在Borland C++ +Builder下工作时,即使我把它们称为“Extn”C“./P>,它也会
当我尝试迁移第一个项目,它在Borland C++ +Builder下工作时,即使我把它们称为“Extn”C“./P>,它也会把导入的函数名损坏。” 例如,以下(减少的)代码在编译器开始链接后产生错误:
#include <windows.h>
#include <stdio.h>
#include <cstdlib>
#include "dsound.h"
//#include "CGG_Cpp_DInterface.h"
//The following are relevent items taken from CGG_Cpp_DInterface.h
struct CrimsonReply1{
unsigned int Echo;
unsigned int Result;
unsigned int ReplyType;
unsigned int Reserved1;
unsigned int Reserved2;
char* OutputString;
double Reply[32];
};
extern "C" __declspec(dllimport) int CrimsonCommandProc(/*I'm not going to list all the arguments here*/);
extern "C" __declspec(dllimport) int TranslateCrimsonReply1(int, CrimsonReply1*, int);
#define CGG_SETUP 0x20000001
#define CGG_SHUTDOWN 0x20000005
#define CGG_WINDOWED 0x0000002F
#define CGG_RECTANGLE 0x00000024
#define CGG_STRETCHTOCLIENT 0x00000028
#define CGG_DUMPALLREPLIES 0
//End of items taken from CGG_Cpp_DInterface.h
extern "C" LRESULT CALLBACK WndProc(HWND hWnd, UINT messg, WPARAM wParam, LPARAM lParam );
char szProgName[] = "Age Games: Animal Reader";
char message[] = "";
extern "C"{
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPreInst, LPSTR lpszCmdLine, int nCmdShow)
{ //Win32 entry-point routine
MSG WinEvent;//long pointer to an event message sent by Windows to the application
WNDCLASSEX WinClass;//A Windows Class Struct
RECT WindowRect;//A structure to describe the position and size of the window.
HWND WinHand;
/*Other Variables-------------------------------------------------------------*/
CrimsonReply1 CrimsonReply;
/*------------------------------------------------------------------------------
Set up a window, register it, and create it.
------------------------------------------------------------------------------*/
/*set up window class and register it*/
/*All the standard window initialization is in here. It's not relevent to the problem.*/
/*------------------------------------------------------------------------------
begin the message loop
------------------------------------------------------------------------------*/
LPDIRECTSOUND* DirectSoundObject;
HRESULT Result = DirectSoundCreate(NULL, DirectSoundObject, NULL);
if (Result == DS_OK && *DirectSoundObject) Result = (*DirectSoundObject)->SetCooperativeLevel(WinHand, DSSCL_NORMAL);
if (Result != DS_OK) return(0);
int ReplyPointer = CrimsonCommandProc(CGG_SETUP,NULL,(double)(int)WinHand,NULL,CGG_WINDOWED,NULL,
CGG_RECTANGLE,NULL,800,NULL,600,NULL,
CGG_STRETCHTOCLIENT);
if (ReplyPointer) ReplyPointer = TranslateCrimsonReply1(ReplyPointer, &CrimsonReply, CGG_DUMPALLREPLIES);
while(GetMessage(&WinEvent, NULL, 0, 0))
{
DispatchMessage(&WinEvent);
}
/*------------------------------------------------------------------------------
Shutdown.
------------------------------------------------------------------------------*/
ReplyPointer = CrimsonCommandProc(CGG_SHUTDOWN);
if (ReplyPointer) ReplyPointer = TranslateCrimsonReply1(ReplyPointer, &CrimsonReply, CGG_DUMPALLREPLIES);
return(WinEvent.wParam);
} //end of WinMain()
}
因此,它将DirectSoundCreate函数名与@12弄乱了,尽管我使用的是microsoft的dsound.h文件(它将它放在一个'extern“C”块中),并且它将CrimsonCommandProc与\u imp\uuu弄乱了,尽管我将所有内容都放在'extern“C”的范围内“如何让GNU GCC编译器停止损坏名称?”?(用于导入dll函数和最终创建dll时)
或者,我没有嫁给GNU GCC。如果有另一个编译器是A)免费的,B)跨平台的,C)使用DirectX.lib文件(最好是新版本发布时支持的),我可以使用它。DirectSoundCreate被声明为WINAPI,一个用于u stdcall的宏:
extern HRESULT WINAPI DirectSoundCreate(...);
这给了它@12的装饰。您可能收到链接器错误,因为您没有链接dsound.lib。或者,您拥有的任何版本都缺少导出,这在mingw版本的SDK文件中并不少见
因为您声明了函数uu declspec(dllimport),所以您得到了uu imp前缀。只需删除它。dsound.h将几乎所有文件都封装在#ifdef uucplusplus extern“C”{#endif//uucplusplus#ifdef uucplusplus}#endif/\uuu cplusplus同样,我将dsound.lib包含在项目中。我应该用它做些别的事吗?(这对BCB来说已经足够了,我对代码::blocks还不熟悉)我去构建选项…->链接器设置->添加->(浏览)并添加了dsound.lib和CGGWin.lib。现在我得到了“ld.exe | |找不到-ldsound.lib |”,CGGWin.Ah也是这样。在GNU GCC中使用uu stdcall时,即使指定了“extern”C,它也会添加@N。这在BCB中不会发生。此外,dsound.h文件用define WINAPI stdcall隐藏了u stdcall。现在我只需要弄清楚为什么Code::Blocks在浏览和添加library.lib时试图查找-llibrary.lib。@user1167758:您可能还需要配置链接器的搜索路径(或使用完整路径指定库)。另外,您可能需要将库名称配置为“:dsound.lib”和“:CGGWin.lib”,这样链接器就不会在名称中添加“lib”前缀。感谢Hans和Michael,现在我已经到了无法识别.lib文件格式的地步。但这是一个完全不同的问题。我不得不在通过浏览添加的内容中键入显式路径名,这让人难以置信。
extern HRESULT WINAPI DirectSoundCreate(...);