Difference between revisions of "Zh/Documentation/DevGuide/WritingUNO/C++/Building and Testing C++ Components"

From Apache OpenOffice Wiki
Jump to: navigation, search
(New page: {{Documentation/DevGuide/WritingUNOTOC/Zh |WritingUNO2d=block |ShowPrevNext=block |PrevPage=Zh/Documentation/DevGuide/WritingUNO/C++/Multiple Components in One Dynamic Link Library |NextPa...)
 
Line 25: Line 25:
 
</ol>
 
</ol>
  
{{Documentation/Caution|通常,共享库组件应限制其导出,仅导出上面提到的函数(前缀为 <tt>component_</tt>),以避免 Unix 上的符号冲突。此外,对于 GUN gcc3 C++ 编译程序,还要导出异常的 RTTI 符号。}}
+
{{Warn|通常,共享库组件应限制其导出,仅导出上面提到的函数(前缀为 <tt>component_</tt>),以避免 Unix 上的符号冲突。此外,对于 GUN gcc3 C++ 编译程序,还要导出异常的 RTTI 符号。}}
  
 
<ol start=7>
 
<ol start=7>

Revision as of 19:49, 13 July 2018


编译过程

如果需要更多有关编译组件代码的信息,请参阅 GUN makefile 文件。它使用了许多 SDK 中的平台相关的变量,这些变量包括在 <SDK>/settings/settings.mk 中。为简单起见,此处省略具体内容,只概要介绍建立过程的八个步骤:

  1. UNOIDL 编译程序将 .idl 文件 some.idl 编译到 urd 文件中。
  2. 生成的二进制 .urd 文件合并到新的 simple_component.rdb
  3. 工具 xml2cmp 解析 XML 组件说明 simple_component.xml,以了解编译所需的类型。此文件介绍了用于部署的服务实现,例如实现的目的和使用的类型。如果需要有关这些 XML 文件的语法的更多信息,请访问 http://udk.openoffice.org/common/man/module_description.html
  4. 步骤 3 中解析的类型将传送到 cppumaker,它将使用 simple_component.rdb 和存储在您的 OpenOffice.org 的程序目录中的 OpenOffice.org 类型库 types.rdb 在包括目录的输出中生成相应的标头对。

Template:Documentation/Tip

  1. 编译源文件 service1_impl.cxxservice2_impl.cxx
  2. 共享库被链接出对象文件,而是动态连接到 UNO 基本库 sal、cppu 和 cppuhelper。共享库的名称在 Unix 上是 libsimple_component.so,在 Windows 上是 simple_component.dll
Documentation caution.png 通常,共享库组件应限制其导出,仅导出上面提到的函数(前缀为 component_),以避免 Unix 上的符号冲突。此外,对于 GUN gcc3 C++ 编译程序,还要导出异常的 RTTI 符号。
  1. 共享库组件注册到 simple_component.rdb 中。此操作也可以通过手动运行以下命令来完成。
 $ regcomp -register -r simple_component.rdb -c simple_component.dll


测试注册并使用

组件的注册表 simple_component.rdb 拥有已注册的服务实现的条目。如果已成功注册库,请运行:

 $ regview simple_component.rdb


其结果应类似如下所示:

 /
   / UCR
     / my_module
       / XSomething
 
         ... interface information ...
 
   / IMPLEMENTATIONS
     / my_module.my_sc_impl.MyService2
       / UNO
         / ACTIVATOR
           Value: Type = RG_VALUETYPE_STRING
                  Size = 34
                  Data = "com.sun.star.loader.SharedLibrary"
 
         / SERVICES
           / my_module.MyService2
         / LOCATION
           Value: Type = RG_VALUETYPE_STRING
                  Size = 21
                  Data = "simple_component.dll"
 
     / my_module.my_sc_impl.MyService1
       / UNO
         / ACTIVATOR
           Value: Type = RG_VALUETYPE_STRING
                  Size = 34
                  Data = "com.sun.star.loader.SharedLibrary"
 
         / SERVICES
           / my_module.MyService1
         / LOCATION
           Value: Type = RG_VALUETYPE_STRING
                  Size = 21
                  Data = "simple_component.dll"
 
   / SERVICES
     / my_module.MyService1
       Value: Type = RG_VALUETYPE_STRINGLIST
              Size = 40
              Len = 1
              Data = 0 = "my_module.my_sc_impl.MyService1"
 
     / my_module.MyService2
       Value: Type = RG_VALUETYPE_STRINGLIST
              Size = 40
              Len = 1
              Data = 0 = "my_module.my_sc_impl.MyService2"


OpenOffice.org 可以识别插入 OpenOffice.org 的程序目录的 unorc 文件(在 Unix 上;在 Windows 上是 uno.ini)中的注册表文件。通过 simple_component.rdb 扩展该文件中的类型和服务。给定文件必须是绝对文件 URL,但是如果 rdb 被复制到 OpenOffice.org 程序目录,则可以使用 $ORIGIN 宏,如以下 unorc 文件所示:

 [Bootstrap]
 UNO_TYPES=$ORIGIN/types.rdb $ORIGIN/simple_component.rdb
 UNO_SERVICES=$ORIGIN/services.rdb $ORIGIN/simple_component.rdb


第二,运行 OpenOffice.org 时,请扩展 PATH (Windows) 或 LD_LIBRARY_PATH (Unix),包括建立的输出路径,以便加载程序可以找到组件。如果共享库被复制到程序目录或程序目录内创建的链接(仅适用于 Unix),则不要扩展路径。


启动 OpenOffice.org Basic 脚本中的测试组件的操作很简单,如以下代码所示:

 Sub Main
 
     REM calling service1 impl
     mgr = getProcessServiceManager()
     o = mgr.createInstance("my_module.MyService1")
     MsgBox o.methodOne("foo")
     MsgBox o.dbg_supportedInterfaces
 
     REM calling service2 impl
     dim args( 0 )
     args( 0 ) = "foo"
     o = mgr.createInstanceWithArguments("my_module.MyService2", args())
     MsgBox o.methodOne("bar")
     MsgBox o.dbg_supportedInterfaces
 
 End Sub


此程序可以实例化服务实现,并执行对其接口的调用。methodOne() 调用返回的值将在消息框中显示。Basic 对象属性 dbg_supportedInterfaces 将通过对象的 com.sun.star.lang.XTypeProvider 接口检索信息。


Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages