Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
delphi(XE7)和mingw-gcc兼容性(switch语句具有5种或更多情况)_Delphi_Gcc_Dll - Fatal编程技术网

delphi(XE7)和mingw-gcc兼容性(switch语句具有5种或更多情况)

delphi(XE7)和mingw-gcc兼容性(switch语句具有5种或更多情况),delphi,gcc,dll,Delphi,Gcc,Dll,我试图在Delphi中使用C代码。我在编译和包含由gcc构建的*.o文件时面临这个问题。具体例子: C源文件“simple.C”代码: 通过以下命令编译: gcc -fno-leading-underscore -c simple.c 这将生成simple.o文件,该文件将用于以下delphi项目: program Project2; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; {$L simple.o} procedu

我试图在Delphi中使用C代码。我在编译和包含由gcc构建的*.o文件时面临这个问题。具体例子: C源文件“simple.C”代码:

通过以下命令编译:

gcc  -fno-leading-underscore  -c simple.c
这将生成simple.o文件,该文件将用于以下delphi项目:

program Project2;

{$APPTYPE CONSOLE}

{$R *.res}
uses
  System.SysUtils;

{$L simple.o}
procedure foo5 (); cdecl; external ;

begin

  try
    foo5;   {<-- here the exception will occur)
    Writeln('hello world~~~!!!');
    readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);

  end;
    readln;
end.
稍微更改delphi代码:

program Project2;

{$APPTYPE CONSOLE}

{$R *.res}
uses
  System.SysUtils;

//{$L simple.o}
procedure foo5 (); cdecl; external 'simple.dll' ;

begin

  try
    foo5;    {this time no fail}
    Writeln('hello world~~~!!!');
    readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);

  end;
    readln;
end.
说明中有带“o”的故障

70A81593 8B00             mov eax,[eax]
70A8158E 056440A870       add eax,$70a84064
其中eax conatins的值为10,因此实际上无法读取地址为10的内存。 我发现了区别。当我用objdump-S反编译“o”文件和“dll”时,我发现dll有before mov指令

70A81593 8B00             mov eax,[eax]
70A8158E 056440A870       add eax,$70a84064
而“o”有

这种差异导致eax在使用dll时包含合理的值,而eax在使用“o”时包含错误的值


在我的项目中,我希望使用o文件而不是dll。你知道为什么gcc对o和dll执行不同的编译指令吗?我想知道有没有办法强迫gcc对o文件执行相同的指令?

我从来没有对mingw编译的静态链接对象有过太多的运气。我将bcc32用于32位构建,将cl用于64位构建。感谢您的提示bcc32适用于所有情况。我的意图是在我们的项目中开始使用gcc。我觉得gcc有最优化的性能代码,这就是我想尝试gcc.BTW的原因,如果有人想尝试上面的代码,请不要跳过simple.c文件中的foo343。由于uknown的原因,delphi不接受地址为0000000的“o”文件中的函数。所以我把空函数放在C文件中,将函数foo5移到更高的地址。正如我所说,mingw从未为我带来成功。如果您想要比bcc32更高效的代码,请尝试cl。嗨,大卫,谢谢您的提示。我也成功地使用了gcc,switch语句的问题通过-O2 switch解决了。我现在不知道怎么解释,可能以后再调查。。我对“cl”编译器感兴趣。我想将其用作带有“无前导下划线”开关的gcc,但似乎没有类似的东西。你有什么经验?马丁
00419ECE 0500000000       add eax,$00000000