cross compile with mingw

102 views
Skip to first unread message

Fabrice Bacchella

unread,
Aug 18, 2017, 10:24:31 AM8/18/17
to NAR Maven plugin

Still trying to compile my project, I tried to do a cross compilation using the mingw environment.


I first tested it with a make file, it worked, I got a dll.


It tried then to build using maven and nar, and got a strange result.


First, I prepared my environment with, after downloading a jdk for windows :

sudo yum install mingw64-gcc-c++ mingw64-headers

mkdir /tmp/wjdk /tmp/mingw

cd /tmp/wjdk

7z x jdk-8u144-windows-x64.exe

7z x ./.rsrc/1033/JAVA_CAB9/110

unzip tools.zip

ln -s /usr/bin/x86_64-w64-mingw32-g++ /tmp/mingw/g++


The configuration for nar was then:

                <configuration>

                    <aol>amd64-Windows-gpp</aol>

                    <os>Windows</os>

                    <libraries>

                        <library>

                            <type>jni</type>

                            <narSystemPackage>com.arkanosis.jpdh</narSystemPackage>

                        </library>

                    </libraries>

                    <linker>

                        <name>msvc</name>

                        <toolPath>/Volumes/c$/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/HostX86/x64</toolPath>

                    </linker>

                    <linker>

                        <name>g++</name>

                        <toolPath>/tmp/mingw</toolPath>

                    </linker>

                    <cpp>

                        <name>g++</name>

                        <toolPath>/tmp/mingw</toolPath>

                        <includePaths>

                            <includePath><path>/var/tmp/wjdk/include/win32</path></includePath>

                            <includePath><path>/var/tmp/wjdk/include</path></includePath>

                        </includePaths>

                    </cpp>

                </configuration>


And I also defined a property:

    <properties>

        ...

        <nar.os>Windows</nar.os>

    </properties>



And it almost works, but I'm getting a mix of linux and windows.


First it compile with fPIC. Indeed a quick look at GccCCompiler.java shows:

    this.isPICMeaningful = !System.getProperty("os.name").contains("Windows");

...

    if (this.isPICMeaningful && linkType.isSharedLibrary()) {

      args.addElement("-fPIC");

    }


The check property should be nar.os, to be consistent.

And there is a lot of usage os os.name:

grep -r 'os\.name' src | wc -l

      36


It should be using once I think, to set the default value of nar.os.


And also:


$ mvn clean nar:nar-compile

[DEBUG] Configuring mojo 'com.github.maven-nar:nar-maven-plugin:3.5.2:nar-compile' with basic configurator -->

[DEBUG]   (f) aol = amd64-Windows-gpp

...

[DEBUG]   (f) os = Windows

...

[DEBUG] getProperty(amd64-Windows-gpp, maxCores, 0) = 0


[INFO] Starting link {4.8.5 -shared -Bdynamic -lpdh -fexceptions -lstdc++}

[DEBUG] /usr/bin/x86_64-w64-mingw32-g++ -shared -o libJPDH-1.2-SNAPSHOT.so ...

[DEBUG] Execute:Java13CommandLauncher: Executing '/usr/bin/x86_64-w64-mingw32-g++' with arguments:

'-shared'

'-o'

'libJPDH-1.2-SNAPSHOT.so'

...


$ file ./target/nar/JPDH-1.2-SNAPSHOT-amd64-Windows-gpp-jni/lib/amd64-Windows-gpp/jni/libJPDH-1.2-SNAPSHOT.so

./target/nar/JPDH-1.2-SNAPSHOT-amd64-Windows-gpp-jni/lib/amd64-Windows-gpp/jni/libJPDH-1.2-SNAPSHOT.so: PE32+ executable (DLL) (console) x86-64, for MS Windows


I have been unable to identify how the generated file name is choosen, but it should be a .dll, not .so.


Reply all
Reply to author
Forward
0 new messages