我在Linux平台上使用对象文件,并按照下面的代码链接它们到我的Delphi应用程序中,但是出现了以下错误:
"E2065 Unsatisfied forward or external declaration: 'add'"
Delphi:
program ITP_Test;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
{$LINK 'hello.o'}
function add(a ,b : Integer): Integer; cdecl; external;
begin
Writeln(add(2,7));
end.
hello.c
#include<stdio.h>
#ifdef __cplusplus
extern "C"
{
#endif
int add(int a, int b)
{
return a + b;
}
#ifdef __cplusplus
}
#endif
使用命令“gcc -c hello.c”编译hello.c文件。
gcc版本:7.5.0 Linux版本:Ubuntu 18.04
pascal
调用约定,而是应该使用cdecl
。在这里,基本的调试步骤是停止尝试编译最终产品,回到你可以尝试的最简单的东西。你能否创建一个程序,链接一个只包含以下函数的对象int add(int a, int b) { return a + b; }
? - undefined