maven nar 插件测试阶段的 C++ 未解析的外部符号
C++ unresolved external symbol in test phase of maven nar 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.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.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.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.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
时失败。
更新
我认为我的其他依赖项正在被注入,因为它们是 "Library Directories"。库目录是一个项目,它在目录树 src\nar\resources\aol\x86-Windows-msvc\lib
中包含一个库(在我的例子中是 .lib),在 src\nar\resources\noarch
中包含相应的 headers。术语 "library directory" 可以在插件的代码中找到(参见 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 版本时,我才意识到我使用的是 3.2.3 版本 http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.maven-nar%22%20AND%20a%3A%22nar-maven-plugin%22。所以我会更新和测试。
此问题与以下内容有些相关:
所以解决方案也适用于此。简而言之:
- 您需要使用最新版本的 Maven NAR 插件。
- 正如 GregDomjan 在 github 上所述,您需要相应地配置您的工具,在我的例子中 (msvc11.0/winsdk8.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>
我有一个具有不同依赖项的 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.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.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.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.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
时失败。
更新
我认为我的其他依赖项正在被注入,因为它们是 "Library Directories"。库目录是一个项目,它在目录树 src\nar\resources\aol\x86-Windows-msvc\lib
中包含一个库(在我的例子中是 .lib),在 src\nar\resources\noarch
中包含相应的 headers。术语 "library directory" 可以在插件的代码中找到(参见 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 版本时,我才意识到我使用的是 3.2.3 版本 http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.maven-nar%22%20AND%20a%3A%22nar-maven-plugin%22。所以我会更新和测试。
此问题与以下内容有些相关:
所以解决方案也适用于此。简而言之:
- 您需要使用最新版本的 Maven NAR 插件。
- 正如 GregDomjan 在 github 上所述,您需要相应地配置您的工具,在我的例子中 (msvc11.0/winsdk8.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>