我有一个具有不同依赖关系的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。所以我会更新并测试。
答案 0 :(得分:0)
这个问题与以下内容有关:
Maven NAR plugin lots of errors in Windows.h when updating to 3.3.0
Maven NAR Plugin: Compiler errors in a simple program that uses Windows.h in version 3.3.0
所以解决方案也适用于此。简而言之:
的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>