> For the complete documentation index, see [llms.txt](https://docs.proudnet.com/proudnet.cn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.proudnet.com/proudnet.cn/proudnet/2.setting/yun-xing-pidl-bian-yi-qi.md).

# 運行 PIDL 編譯器

## 1. Windows

您可以使用 [**PIDL附加元件**](/proudnet.cn/proudnet/pn_utility.md#pidl)方便地建立和編譯 PIDL 文件，但如果您無法使用它，請使用下列方法設定 <mark style="color:orange;">PIDL Custom Build</mark>。

#### 1-1. 在 Visual Studio 專案中設定 <mark style="color:orange;">PIDL Custom Build</mark>

<figure><img src="/files/c6ffkwkMMP52xC13COfm" alt=""><figcaption></figcaption></figure>

每個建置設定的詳細資訊如下。

> **命令列**: <mark style="color:orange;">\<PIDL.exe所在路徑>\PIDL.exe "%(FullPath)" -outdir .</mark>&#x20;
>
> **註釋**: Compiling %(Filename).pidl ...&#x20;
>
> **輸出**: %(RootDir)%(Directory)%(Filename)\_common.cpp;%(RootDir)%(Directory)%(Filename)\_common.h;%(RootDir)%(Directory)%(Filename)\_proxy.cpp;%(RootDir)%(Directory)%(Filename)\_proxy.h;%(RootDir)%(Directory)%(Filename)\_stub.cpp;%(RootDir)%(Directory)%(Filename)\_stub.h;%(Outputs)&#x20;
>
> **附加從屬性**: <mark style="color:orange;">\<PIDL.exe所在路徑>\PIDL.exe</mark>

{% hint style="warning" %}

* <mark style="color:orange;">PIDL.exe</mark>位於ProudNet安裝路徑的<mark style="color:orange;">util</mark>資料夾中。
* Debug和Release必須設定相同。
  {% endhint %}

所有設定完成後，您可以編譯 PIDL 檔案並查看如下所示的輸出。

```
1>---— 開始建構: 專案: ..., 構成: Release Win32 ---—
1>Compiling TestC2C.pidl ...
1>建置日誌保存到“...”。
1>ProudNetTest_2005 - 錯誤：0，警告：0
========== 建置：1 成功，0 失敗，0 最新，0 跳過 ==========
```

Visual Studio 2005 和 2008 版本支援[**Custom Build Rules**](/proudnet.cn/proudnet/using_pn/pidl/using_pidl.md#custom-build-rules)，因此它們會自動設置，而無需在每次新增 PIDL 檔案時設定自訂生成。 Visaul Studio 2010 及更高版本可使用<mark style="color:orange;">Build customizations</mark>。

<figure><img src="/files/Bfm8Gmis2PPIafNyX8kZ" alt=""><figcaption></figcaption></figure>

***

## 2. Linux

{% tabs %}
{% tab title="Ubuntu" %}
在Ubuntu上安裝開源Mono庫的範例\
※ 開源 Mono 專案支援 Linux、Windows 和 Mac OS。

```
$sudo apt-get install mono-gmcs
$sudo apt-get install mono-runtime
```

{% endtab %}

{% tab title="CentOS" %}
在CentOS上安裝開源Mono庫的範例\
※ 開源 Mono 專案支援 Linux、Windows 和 Mac OS。

```
$sudo yum install mono-devel
$sudo yum install mono-complete
```

{% endtab %}

{% tab title="Mono 平台" %}
在Mono平台上運行PIDL編譯器的範例

```
$pwd
/home/ProudNet/util
$mono PIDL.exe ../Sample/Simple/Common/*.pidl -outdir ./
```

{% endtab %}
{% endtabs %}

***

## 3. C\#

RMI 也可以在 C# 語言中使用，為此，PIDL 編譯器也為 C# 語言產生代理程式和存根程式碼。

\
執行以下命令將產生 C# 語言的代理程式和存根程式碼。 （現有的 -clr 與 -cs 相同。）

```csharp
PIDL.exe -cs <input-file-name>
```

常用模組推薦使用C#語言建立的proxy和stub。 與 PIDL 一樣，此模組需要從 C# 專案和自訂建置輸入 PIDL 檔案。

<figure><img src="/files/HaGuSESVBL6tYIK4SZmQ" alt=""><figcaption><p>在 C# 專案中為 PIDL 檔案設定自訂構建</p></figcaption></figure>

建構<mark style="color:orange;">C2S.pidl</mark>後所建立的代理和存根如下。

* C2S\_common.cs
* C2S\_proxy.cs
* C2S\_stub.cs

將這些檔案包含在您的 C# 專案 (<mark style="color:orange;">.csproj</mark>) 中。 但是，這些檔案是建置結果，不應放置在原始程式碼管理（例如 SVN 等）中，因為唯讀檔案中可能會出現寫入錯誤。

我們建議使用編輯器開啟 <mark style="color:orange;">.csproj</mark> 檔案並進行以下修改：

```csharp
<Target Name="BeforeBuild">
<ItemGroup>
<Compile Include="C2S_common.cs" />
<Compile Include="C2S_proxy.cs" />
<Compile Include="C2S_stub.cs" />
</ItemGroup>
 
</Target>
<Target Name="AfterBuild">
</Target>
```

{% hint style="info" %}
C#語言中建立的Proxy和Stub是C++中的同名類，它們的用法也是一樣的。
{% endhint %}

### - RMI proxy, stub類別public, internal, private設定

PIDL編譯器產生的代理類別、存根類別和公用類別的存取修飾符預設為internal。 這些類別可以從同一模組（或組件）內的不同來源使用，但不能從其他模組使用。

但是，當您建立一個單獨的模組來收集這些類別並希望在其他模組中使用此模組中的類別時，您可能需要將存取修飾符變更為 public。

\
在這種情況下，設定 PIDL 編譯器產生的類別的存取修飾符屬性，如下所示。

```csharp
// This will let proxy, stub and common classes to have access modifier 'public'.
[marshaler(clr)=MyMarshaler, access=public]
global MyC2S 3000
{
    Foo(...);
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.proudnet.com/proudnet.cn/proudnet/2.setting/yun-xing-pidl-bian-yi-qi.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
