Add a static library for the link phase of a Maven NAR project

I've packaged an already compiled version of OpenCV to a NAR Maven project. I've followed https://github.com/CERN/narlibs-log4cplus to achieve this (a project that only contains .lib, .dll and .h files). This is my final directory structure (the lib directory contains the .lib and .dll files and the directory include contains the .h files):

The pom.xml file:

...
<groupId>org.opencv</groupId>
<artifactId>opencv-nar</artifactId>
<packaging>nar</packaging>
<version>2.4.10</version>
<build>
    <plugins>
        <plugin>
            <groupId>com.github.maven-nar</groupId>
            <artifactId>nar-maven-plugin</artifactId>
            <version>3.0.0</version>
            <extensions>true</extensions>
            <configuration>
                <libraries>
                    <library>
                        <type>static</type>
                    </library>
                    <library>
                        <type>shared</type>
                    </library>
                </libraries>
            </configuration>
        </plugin>
    </plugins>
</build>

I am using this dependency on a simple project:

#include "opencv2/highgui/highgui.hpp"
int main(int argc, char *argv[]) {
    cv::waitKey(0);
    return 0;
}

The problem is happening in the link phase (after executing mvn compile -X).

...
[DEBUG] FileSet: Setup scanner in dir E:\PROY\image-lib\dev\1.0\image\target\nar\opencv-nar-2.4.10-x86-Windows-msvc-shared\lib\x86-Windows-msvc\shared with patternSet{ includes: [opencv-nar-2.4.10.lib] excludes: [] }
...
[DEBUG] Execute:Java13CommandLauncher: Executing 'link' with arguments:
'/MANIFEST'
'/NOLOGO'
'/SUBSYSTEM:CONSOLE'
'/INCREMENTAL:NO'
'/OUT:image.exe'
'C:\image\target\nar\obj\x86-Windows-msvc\image-test.obj'
[INFO] image-test.obj : error LNK2019: unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey@cv@@YAHH@Z) referenced in function _main
[ERROR] image-test.obj : error LNK2019: unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey@cv@@YAHH@Z) referenced in function _main
[INFO] image.exe : fatal error LNK1120: 1 unresolved externals
[ERROR] image.exe : fatal error LNK1120: 1 unresolved externals
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

For what I see the problem is because none of the static libs from OpenCv are passed to the 'link' arguments. So, How do I add a static library (or better, a directory) to the link arguments?

opencv_core2410.lib
opencv_imgproc2410.lib
opencv_highgui2410.lib

Answers


This is not an aswer, but more of a way around. I believe that by te way MAVEN NAR is designed (even MAVEN itself) every library has to be on its own project.

So, with this in mind you need to generate a project based on these 2 projects:

So, for my OpenCV project, this is the parent pom.xml, which is based on parent pom.xml from Boost C++ libraries in maven form, for a list of compiler names for the NAR plugin see in aol.properties:

<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>org.opencv</groupId>
    <artifactId>parent</artifactId>
    <version>2.4.10</version>
    <packaging>pom</packaging>

    <name>OpenCV :: Parent</name>
    <description>OpenCV</description>

    <properties>
        <nar-plugin.version>3.2.3</nar-plugin.version>
        <compiler-name>msvc</compiler-name>
        <linker-name>msvc</linker-name>
    </properties>

    <modules>
        <module>core</module>
        <module>highgui</module>
        <module>imgproc</module>
    </modules>

    <build>
        <plugins>
            <plugin>
                <groupId>com.github.maven-nar</groupId>
                <artifactId>nar-maven-plugin</artifactId>
                <version>${nar-plugin.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <cpp>
                        <name>${compiler-name}</name>
                        <includes>
                            <include>**/*.hpp</include>
                            <include>**/*.h</include>
                            <include>**/*.cpp</include>
                            <include>**/*.c</include>
                        </includes>
                    </cpp>
                    <linker>
                        <name>${linker-name}</name>
                    </linker>
                    <libraries>
                        <library>
                            <type>static</type>
                        </library>
                        <library>
                            <type>shared</type>
                        </library>
                    </libraries>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

And each module has a pom.xml file that more or less resembled this:

<?xml version = '1.0'?>
<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 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.opencv</groupId>
        <artifactId>parent</artifactId>
        <version>2.4.10</version>
    </parent>

    <artifactId>opencv-core</artifactId>
    <packaging>nar</packaging>
    <name>OpenCV :: Core</name>
    <description>OpenCV</description>

    <build>
        <plugins>
            <plugin>
                <groupId>com.github.maven-nar</groupId>
                <artifactId>nar-maven-plugin</artifactId>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>
</project>

Now, you will have to add the respective dependencies in your project pom.xml:

<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>org.opencv</groupId>
        <artifactId>opencv-imgproc</artifactId>
        <version>2.4.10</version>
        <type>nar</type>
    </dependency>
</dependencies>

And there you have:

> mvn compile
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...

Need Your Help

Meteor - Facebook Graph Api

javascript jquery facebook facebook-graph-api meteor

I am creating a meteor app. I successfully implemented the facebook login but now the last feature I should implement is to create a chat (involving facebook messenger) between the page(admin) and ...

Example of a very insecure ASP.NET application

asp.net sql-server security

I am looking for a very insecure ASP.NET application. Ideally i'm looking for an application that was written by a noob who has made a lot of security mistakes. If the app has a MS-SQL back-end ...