FPC 编译为静态库
FPC Compile as Static Library
我有以下 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
。但是,如果我 link 使用 GCC 访问文件(link 使用我的 C++ 程序),Dummy
找不到符号。
FPC 说它 link 与 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
文件。
我玩了一点,显然你需要声明它 export or us public name(或者 public 别名,如果你想要错位和非错位符号)
unit xx;
interface
uses
ctypes;
procedure Dummy; cdecl;export;
implementation
procedure Dummy; cdecl;
begin
end;
begin
end.
我有以下 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
。但是,如果我 link 使用 GCC 访问文件(link 使用我的 C++ 程序),Dummy
找不到符号。
FPC 说它 link 与 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
文件。
我玩了一点,显然你需要声明它 export or us public name(或者 public 别名,如果你想要错位和非错位符号)
unit xx;
interface
uses
ctypes;
procedure Dummy; cdecl;export;
implementation
procedure Dummy; cdecl;
begin
end;
begin
end.