首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FPC编译为静态库

FPC编译为静态库
EN

Stack Overflow用户
提问于 2016-07-11 04:33:31
回答 1查看 1K关注 0票数 1

我有以下Pascal代码:

代码语言:javascript
复制
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。但是,我需要一个静态库。

编辑:也在生成这个批处理文件:

代码语言:javascript
复制
@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文件。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-11 11:32:18

我玩了一会儿,令人震惊的是,您需要声明它为导出或us 公众姓名 (或者公共别名,如果您想要的都是损坏的和非损坏的符号)

代码语言:javascript
复制
unit xx;
interface

uses
  ctypes;

procedure Dummy; cdecl;export;

implementation
procedure Dummy; cdecl; 

begin
end;


begin
end.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38299221

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档