0

I need help with compiling a c++ code using maven-nar plugin.I tried reading through the documentation but could not get the code working. Any help is greatly appreciated

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.github.maven-nar</groupId>
<artifactId>maven-nar-poc</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>nar</packaging>
<dependencies>

</dependencies>
<build>
    <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>jni</type>
                        <narSystemPackage>com.github.maven-nar</narSystemPackage>
                    </library>
                </libraries>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.10</version>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${project.build.directory}/nar/nar-generated/</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

<profiles>
    <profile>
        <id>mac</id>
        <activation>
            <os>
                <family>mac</family>
            </os>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.github.maven-nar</groupId>
                    <artifactId>nar-maven-plugin</artifactId>
                    <extensions>true</extensions>
                    <configuration>
                        <skip>false</skip>
                        <cpp>
                            <debug>true</debug>
                            <includePaths>
                                <includePath>${project.basedir}/src/main/cpp</includePath>
                            </includePaths>
                            <options>
                                <option>-DMAC -DMAC_OSX -DMAC_CARBON -D__CF_USE_FRAMEWORK_INCLUDES__ -DLARGE64_FILES
                                </option>
                            </options>
                        </cpp>
                        <libraries>
                            <library>
                                <type>executable</type>
                                <!-- <run>true</run> -->
                                <subSystem>gui</subSystem>
                            </library>
                        </libraries>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>windows</id>
        <activation>
            <os>
                <family>windows</family>
            </os>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.github.maven-nar</groupId>
                    <artifactId>nar-maven-plugin</artifactId>
                    <extensions>true</extensions>
                    <configuration>
                        <skip>false</skip>
                        <cpp>
                            <debug>true</debug>
                            <includePaths>
                                <includePath>${project.basedir}/src/main/cpp</includePath>
                            </includePaths>
                            <options>
                                <option>-DWINDOWS -D__CF_USE_FRAMEWORK_INCLUDES__ -DLARGE64_FILES
                                </option>
                            </options>
                        </cpp>
                        <libraries>
                            <library>
                                <type>executable</type>
                                <!-- <run>true</run> -->
                                <subSystem>gui</subSystem>
                            </library>
                        </libraries>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

The above pom.xml does not throw any issue but it is not creating any binaries for windows and also i am unable to understand what options i could use for WINDOWS.

wandermonk
  • 6,856
  • 6
  • 43
  • 93
  • Maven log output might be helpful to assist – Greg Domjan Dec 03 '19 at 09:33
  • The build helper seems to point to the JNI generated folder, may also be unnecessary if not building JNI – Greg Domjan Dec 03 '19 at 09:35
  • A suspicious detail is that they repeatedly refer ImageJ as big open source project using NAR ([1](https://github.com/maven-nar/nar-maven-plugin/wiki/Compiling-for-multiple-platforms), [2](https://github.com/maven-nar/nar-maven-plugin/wiki/Working-examples)), but the referred ImageJ component (https://github.com/imagej/imagej-launcher) has actually replaced NAR with CMake a year ago, for some reason. – tevemadar Dec 03 '19 at 10:19

1 Answers1

0

Not familiar with the issues around mac executables

These 2 configurations will be joined together, you probably don't need the jni library section if you are aiming for an executable.

        <libraries>
            <library>
                <type>jni</type>
                <narSystemPackage>com.github.maven-nar</narSystemPackage>
            </library>
        </libraries>

        <libraries>
            <library>
                <type>executable</type>
                <!-- <run>true</run> -->
                <subSystem>gui</subSystem>
            </library>
        </libraries>

This section might work

  • having multiple options in 1 could be an issue - spaces are quoted to make this one arg instead of 3...
  • newline in options might be an issue...

        <options>
            <option>-DWINDOWS -D__CF_USE_FRAMEWORK_INCLUDES__ -DLARGE64_FILES
            </option>
        </options>
    
        <options>
            <option>-DWINDOWS</option>
            <option>-D__CF_USE_FRAMEWORK_INCLUDES__</option>
            <option>-DLARGE64_FILES</option>
        </options>
    

But generally would do it as

        <defines>
            <define>WINDOWS</define>
            <define>__CF_USE_FRAMEWORK_INCLUDES__</define>
            <define>LARGE64_FILES</define>
        </defines>
Greg Domjan
  • 13,943
  • 6
  • 43
  • 59