【问题标题】:Maven NAR plugin: wrong linked library nameMaven NAR 插件:错误的链接库名称
【发布时间】:2016-03-28 19:58:01
【问题描述】:

我第一次使用 maven nar 插件在 C++ 中编译一系列 corba IDL 文件。我已经通过使用 exec 插件和omniidl 成功生成了存根和骨架,现在我在 src/ 下拥有所有 *.C 和 *.H 文件。

我们正在使用内部 Nexus 存储库来检索 NAR 依赖项,到目前为止,我设法编译了所有 *.o 文件。但是,链接器失败并显示以下消息:

[INFO] 21 files were compiled.
[INFO] 21 files were compiled.
[INFO] Linking...
[INFO] Linking...
[INFO] Starting link {4.8 -shared -L/home/dev/repos/idl/cpp-idl/bin/nar/omniORB4-4.2.0-R1-amd64-Linux-gpp-shared/lib/amd64-Linux-gpp/shared -lomniORB4-4.2.0-R1 -L/home/dev/repos/idl/cpp-idl/bin/nar/omnithread-4.2.0-R1-amd64-Linux-gpp-shared/lib/amd64-Linux-gpp/shared -lomnithread-4.2.0-R1 -L/home/dev/repos/idl/cpp-idl/bin/nar/c-2.19-R1-amd64-Linux-gpp-shared/lib/amd64-Linux-gpp/shared -lc-2.19-R1 -L/home/dev/repos/idl/cpp-idl/bin/nar/m-2.19-R1-amd64-Linux-gpp-shared/lib/amd64-Linux-gpp/shared -lm-2.19-R1 -L/home/dev/repos/idl/cpp-idl/bin/nar/stdc__plus__plus-4.8.3+r212056-R1-amd64-Linux-gpp-shared/lib/amd64-Linux-gpp/shared -lstdc__plus__plus-4.8.3+r212056-R1 -fexceptions -lstdc++}
[INFO] Starting link {4.8 -shared -L/home/dev/repos/idl/cpp-idl/bin/nar/omniORB4-4.2.0-R1-amd64-Linux-gpp-shared/lib/amd64-Linux-gpp/shared -lomniORB4-4.2.0-R1 -L/home/dev/repos/idl/cpp-idl/bin/nar/omnithread-4.2.0-R1-amd64-Linux-gpp-shared/lib/amd64-Linux-gpp/shared -lomnithread-4.2.0-R1 -L/home/dev/repos/idl/cpp-idl/bin/nar/c-2.19-R1-amd64-Linux-gpp-shared/lib/amd64-Linux-gpp/shared -lc-2.19-R1 -L/home/dev/repos/idl/cpp-idl/bin/nar/m-2.19-R1-amd64-Linux-gpp-shared/lib/amd64-Linux-gpp/shared -lm-2.19-R1 -L/home/dev/repos/idl/cpp-idl/bin/nar/stdc__plus__plus-4.8.3+r212056-R1-amd64-Linux-gpp-shared/lib/amd64-Linux-gpp/shared -lstdc__plus__plus-4.8.3+r212056-R1 -fexceptions -lstdc++}
[ERROR] /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lomniORB4-4.2.0-R1
[ERROR] /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lomnithread-4.2.0-R1
[ERROR] /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lc-2.19-R1
[ERROR] /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lm-2.19-R1
[ERROR] /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lstdc__plus__plus-4.8.3+r212056-R1
[ERROR] collect2: error: ld returned 1 exit status

事情是,例如文件夹

/home/dev/repos/idl/cpp-idl/bin/nar/omniORB4-4.2.0-R1-amd64-Linux-gpp-shared/lib/amd64-Linux-gpp/shared

包含以下共享对象:

libomniORB4.so  libomniORB4.so.2  libomniORB4.so.2.0

并且链接器尝试链接包含完整版本(依赖版本)的库名称

-lomniORB4-4.2.0-R1

我的问题如下:

  1. 我可以假设包含共享对象的 Nexus 存储库中提供的 omniORB4 NAR 依赖项包含错误的 .so 名称吗?
  2. 有没有办法通过在链接器部分告诉 NAR 插件使用不同的库名称进行链接来解决此问题?

这里是配置 NAR 插件的 pom 部分:

 <build>
   <defaultGoal>install</defaultGoal>
   <plugins>
     <plugin>
       <groupId>com.github.maven-nar</groupId>
       <artifactId>nar-maven-plugin</artifactId>
       <configuration>
         <libraries>
           <library>
             <type>shared</type>
           </library>
         </libraries>
         <cpp>
           <name>g++</name>     
             <sourceDirectory>${project.basedir}/src</sourceDirectory>
             <options>
               <option>-g</option>
             </options>
           <includes>
             <include>**/*.C</include>
           </includes>
         <includePaths>
           <includePath>${project.basedir}/src</includePath>
         </includePaths>
       </cpp>
     </configuration>
   </plugin>
   ....

谢谢。

【问题讨论】:

  • 这实际上是自定义 NAR 依赖中的错误
  • 如果对其他人有帮助,请关闭问题或回答。

标签: c++ maven linker-errors omniorb maven-nar-plugin


【解决方案1】:

有两种方法可以将第三方库打包为 NAR。

重命名库以匹配 NAR 约定

首先是重命名库以匹配插件的约定。如果要使用插件构建库,这些约定与使用的命名相匹配。此打包的示例作为 github 项目中的集成测试之一提供。见:Integration-test it0020

提供自定义nar.properties

在构建 NAR 时,插件通常会生成一个 nar.properties 文件,其中包含一些目前不完整的文档 NAR Dependencies。发布第三方 NAR 时,可以提供一个自定义属性文件,该文件覆盖特定 AOL 的库名称。属性是:

<aol>.output=<space separated list of library names>

例如:

amd-Linux-gpp.output=fooapi foobasic

会导致此架构的 linux 链接行包含 -lfooapi-lfoobasic

应复制生成的构建中的其他属性,例如库绑定的类型以及 nar 的链接方式。

一些文档说无法覆盖此文件,但遵循正常的 maven 资源约定允许替换它。在项目中将nar.properties 文件放在src/main/resources/META-INF/nar/&lt;groupId&gt;/&lt;artifact-name&gt; 中会在库nar 中构建一个自定义属性文件。

【讨论】:

    【解决方案2】:

    在依赖项的 pom.xml 中使用 libsName 配置选项:

    <configuration>
        <libsName>omniORB4</libsName>
        ...
    </configuration>
    

    libsName

    此标签用于列出要包含在链接器中的多个库。 这在打包 3rd 方库时非常有用。

    使用 CSV 表示法:lib1,lib2

    【讨论】:

      【解决方案3】:

      错误出现在格式错误的依赖 NAR 内容中。

      【讨论】:

      • 多么详细的答案,准确地解释了问题所在以及您如何解决它。如果您根本不会提供有关问题如何解决的任何细节,请不要将您自己的“答案”标记为已接受的答案。这是垃圾。
      猜你喜欢
      • 1970-01-01
      • 2019-04-09
      • 2020-01-27
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多