我有以下Pascal代码:
Library foo;
uses
ctypes;
procedure Dummy; cdecl;
begin
end;
exports
Dummy;
begin
end.要将其编译为.o文件,我需要:
ppcrossx64.exe -Cn -CcCDECL -O2 -Xs -XS -Xt foo.pas。
它创建一个foo.o和一个link.res文件。
然后我做ar -q foo.a foo.o link.res来创建foo.a。但是,如果我用GCC链接到文件(链接到我的C++程序),Dummy符号就找不到了。
FPC表示,它与gcc的链接兼容。为什么我找不到符号?我做错了什么?如果我不指定-Cn,它会将其编译成一个工作的.dll。但是,我需要一个静态库。
编辑:也在生成这个批处理文件:
@echo off
SET THEFILE=C:\Users\Brandon\Desktop\foo.dll
echo Linking %THEFILE%
ld.exe -b pei-x86-64 --gc-sections -s --dll --entry _DLLMainCRTStartup --base-file base.$$$ -o C:\Users\Brandon\Desktop\foo.dll link.res
if errorlevel 1 goto linkend
dlltool.exe -S as.exe -D C:\Users\Brandon\Desktop\foo.dll -e exp.$$$ --base-file base.$$$
if errorlevel 1 goto linkend
ld.exe -b pei-x86-64 -s --dll --entry _DLLMainCRTStartup -o C:\Users\Brandon\Desktop\foo.dll link.res exp.$$$
if errorlevel 1 goto linkend
goto end
:asmend
echo An error occured while assembling %THEFILE%
goto end
:linkend
echo An error occured while linking %THEFILE%
:end双击它将创建一个工作的.dll文件。
发布于 2016-07-11 11:32:18
我玩了一会儿,令人震惊的是,您需要声明它为导出或us 公众姓名 (或者公共别名,如果您想要的都是损坏的和非损坏的符号)
unit xx;
interface
uses
ctypes;
procedure Dummy; cdecl;export;
implementation
procedure Dummy; cdecl;
begin
end;
begin
end.https://stackoverflow.com/questions/38299221
复制相似问题