在maven nar插件的测试阶段,C ++未解析的外部符号

时间:2016-03-09 17:46:36

标签: c++ maven maven-plugin

我有一个具有不同依赖关系的C ++ Maven NAR项目,我的pom.xml看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>my.image</groupId>
    <artifactId>image</artifactId>
    <packaging>nar</packaging>
    <version>1.0</version>

    <name>Maven NAR Executable Project</name>

    <dependencies>

        <dependency>
            <groupId>org.opencv</groupId>
            <artifactId>opencv-core</artifactId>
            <version>2.4.10</version>
            <type>nar</type>
        </dependency>

        <dependency>
            <groupId>org.opencv</groupId>
            <artifactId>opencv-highgui</artifactId>
            <version>2.4.10</version>
            <type>nar</type>
        </dependency>

        <dependency>
            <groupId>my.commons</groupId>
            <artifactId>commons</artifactId>
            <version>1.0</version>
            <type>nar</type>
        </dependency>

    </dependencies>

    <build>
        <defaultGoal>integration-test</defaultGoal>
        <plugins>
            <plugin>
                <groupId>com.github.maven-nar</groupId>
                <artifactId>nar-maven-plugin</artifactId>
                <version>3.2.3</version>
                <extensions>true</extensions>
                <configuration>
                    <libraries>
                        <library>
                            <type>static</type>
                        </library>
                    </libraries>
                    <tests>
                        <test>
                            <name>NativeLibTest</name>
                            <link>static</link>
                        </test>
                    </tests>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

当我运行mvn compile时,项目成功编译。

当我使用mvn test -X时出现问题:

[INFO] --- nar-maven-plugin:3.2.3:nar-testCompile (default-nar-testCompile) @ image ---
...
[DEBUG] Examining artifact for NarInfo: org.opencv:opencv-core:nar:2.4.10:compile
[DEBUG]     - added as NarDependency
[DEBUG] Examining artifact for NarInfo: org.opencv:opencv-highgui:nar:2.4.10:compile
[DEBUG]     - added as NarDependency
[DEBUG] Examining artifact for NarInfo: my.commons:commons:nar:1.0:compile
[DEBUG]     - added as NarDependency
...
[DEBUG] Execute:Java13CommandLauncher: Executing 'link' with arguments:
'/MANIFEST'
'/NOLOGO'
'/SUBSYSTEM:CONSOLE'
'/INCREMENTAL:NO'
'/OUT:NativeLibTest.exe'
'E:\PROY\image-lib\dev\1.0\image\target\nar\image-1.0-x86-Windows-msvc-static\lib\x86-Windows-msvc\static\image-1.0.lib'
'E:\PROY\image-lib\dev\1.0\image\target\test-nar\opencv-core-2.4.10-x86-Windows-msvc-shared\lib\x86-Windows-msvc\shared\opencv-core-2.4.10.lib'
'E:\PROY\image-lib\dev\1.0\image\target\test-nar\opencv-highgui-2.4.10-x86-Windows-msvc-shared\lib\x86-Windows-msvc\shared\opencv-highgui-2.4.10.lib'
'E:\PROY\image-lib\dev\1.0\image\target\test-nar\obj\x86-Windows-msvc\image-test.obj'

从消息看来Maven NAR插件忽略了一些库my.commons),这很奇怪,因为my.commons被添加为NarDependency(你可以请参阅第一行),即使target\test-nar\commons-1.0-x86-Windows-msvc-static\lib\x86-Windows-msvc\static被复制也有commons-1.0.lib。最后,库不会传递给link,从而导致许多未解析的外部符号。

TLDR:Maven NAR在使用mvn compile时成功编译,但在使用mvn test时失败。

更新

我认为我的其他依赖项正在被注入,因为它们是“库目录”。库目录是一个项目,它包含目录树src\nar\resources\aol\x86-Windows-msvc\lib中的库(在我的示例中为.lib)及其src\nar\resources\noarch中的相应标头。术语“库目录”可以在插件的代码中找到(参见NarTestCompileMoo.java:284)。关于为什么库必须在测试阶段链接,有一些评论:

  **NarTestCompileMoo.java:273**
  // Static libraries should be linked. Even though the libraries
  // themselves will have been tested already, the test code could
  // use methods or classes defined in them.

那么,为什么我的静态库没有被识别?

更新

当我知道版本3.3.0 http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.maven-nar%22%20AND%20a%3A%22nar-maven-plugin%22时,我正在使用版本3.2.3。所以我会更新并测试。

1 个答案:

答案 0 :(得分:0)

这个问题与以下内容有关:

所以解决方案也适用于此。简而言之:

  1. 您需要使用最新版本的Maven NAR插件。
  2. 正如GregDomjan在github上所述,你需要相应地配置你的工具,在我的情况下(msvc11.0 / winsdk8.0):
  3. 的pom.xml

    <build>
        <plugins>
            <plugin>
                <groupId>com.github.maven-nar</groupId>
                <artifactId>nar-maven-plugin</artifactId>
                <version>3.3.0</version>
                <extensions>true</extensions>
                <configuration>
                    <libraries>
                        <library>
                            <type>executable</type>
                            <run>true</run>
                        </library>
                    </libraries>
                    <msvc>
                        <version>11.0</version>
                        <windowsSdkVersion>8.0</windowsSdkVersion>
                    </msvc>
                </configuration>
            </plugin>
        </plugins>
    </build>