mojohaus / maven-native

https://www.mojohaus.org/maven-native/
MIT License
18 stars 12 forks source link

Linker uses wrong files with multiple executions #26

Closed pschichtel closed 5 years ago

pschichtel commented 6 years ago

I'm currently trying to cross-compile a library to all required target platforms (currently testing with x86_64 and aarch64, but I'm having trouble linking the binary on the second execution (aarch64) because the aarch64 gcc linker tries to link x86_64 objects.

Plugin conf:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>native-maven-plugin</artifactId>
    <version>1.0-alpha-9</version>
    <extensions>true</extensions>
    <configuration>
        <compilerProvider>generic-classic</compilerProvider>
        <sources>
            <source>
                <directory>${basedir}/src/main/c</directory>
                <fileNames>
                    <fileName>javacan_socketcan.c</fileName>
                </fileNames>
            </source>
            <source>
                <directory>${headers.target}</directory>
            </source>
        </sources>
        <javahOS>linux</javahOS>
        <jdkIncludePath>${java.home}/include</jdkIncludePath>
        <compilerEndOptions>
            <compilerEndOption>-fPIC</compilerEndOption>
            <compilerEndOption>-std=c99</compilerEndOption>
        </compilerEndOptions>
        <linkerStartOptions>
            <linkerStartOption>-I ${libdir}</linkerStartOption>
        </linkerStartOptions>
        <linkerEndOptions>
            <linkerEndOption>-shared</linkerEndOption>
            <linkerEndOption>-fPIC</linkerEndOption>
        </linkerEndOptions>
        <linkerOutputDirectory>${project.build.directory}</linkerOutputDirectory>
        <linkerFinalName>libSocketCAN</linkerFinalName>
        <linkerFinalNameExt>so</linkerFinalNameExt>
    </configuration>
    <executions>
        <execution>
            <id>compile-native-x86_64</id>
            <phase>compile</phase>
            <goals>
                <goal>compile</goal>
                <goal>link</goal>
            </goals>
            <configuration>
                <compilerExecutable>x86_64-pc-linux-gnu-gcc</compilerExecutable>
                <compilerOutputDirectory>${project.build.directory}/objs-x86_64</compilerOutputDirectory>
                <linkerExecutable>ld</linkerExecutable>
                <linkerFinalName>${libname}-x86_64</linkerFinalName>
            </configuration>
        </execution>
        <execution>
            <id>compile-native-aarch64</id>
            <phase>process-classes</phase>
            <goals>
                <goal>compile</goal>
                <goal>link</goal>
            </goals>
            <configuration>
                <compilerExecutable>aarch64-linux-gnu-gcc</compilerExecutable>
                <compilerOutputDirectory>${project.build.directory}/objs-aarch64</compilerOutputDirectory>
                <linkerExecutable>aarch64-linux-gnu-ld</linkerExecutable>
                <linkerFinalName>${libname}-aarch64</linkerFinalName>
            </configuration>
        </execution>
    </executions>
</plugin>

Maven output:

[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ JavaCAN ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to /home/phillip/Code/JavaCAN/target/classes
[INFO] 
[INFO] --- native-maven-plugin:1.0-alpha-9:compile (compile-native-x86_64) @ JavaCAN ---
[INFO] /bin/sh -c cd '/home/phillip/Code/JavaCAN' && 'x86_64-pc-linux-gnu-gcc' '-I/home/phillip/Code/JavaCAN/src/main/c' '-I/home/phillip/Code/JavaCAN/target/jni' '-I/home/phillip/Code/JavaCAN/target/generated-sources/annotations' '-I/usr/lib/jvm/java-10-openjdk/include' '-I/usr/lib/jvm/java-10-openjdk/include/linux' '-o/home/phillip/Code/JavaCAN/target/objs-x86_64/javacan_socketcan.o' '-c' '/home/phillip/Code/JavaCAN/src/main/c/javacan_socketcan.c' '-fPIC' '-std=c99'
[INFO] 
[INFO] --- native-maven-plugin:1.0-alpha-9:link (compile-native-x86_64) @ JavaCAN ---
[INFO] /bin/sh -c cd '/home/phillip/Code/JavaCAN' && 'ld' '-I' '/usr/lib/jvm/java-10-openjdk/lib' '-o/home/phillip/Code/JavaCAN/target/libSocketCAN-x86_64.so' 'target/objs-x86_64/javacan_socketcan.o' '-shared' '-fPIC'
[INFO] 
[INFO] --- native-maven-plugin:1.0-alpha-9:compile (compile-native-aarch64) @ JavaCAN ---
[INFO] /bin/sh -c cd '/home/phillip/Code/JavaCAN' && 'aarch64-linux-gnu-gcc' '-I/home/phillip/Code/JavaCAN/src/main/c' '-I/home/phillip/Code/JavaCAN/target/jni' '-I/home/phillip/Code/JavaCAN/target/generated-sources/annotations' '-I/usr/lib/jvm/java-10-openjdk/include' '-I/usr/lib/jvm/java-10-openjdk/include/linux' '-o/home/phillip/Code/JavaCAN/target/objs-aarch64/javacan_socketcan.o' '-c' '/home/phillip/Code/JavaCAN/src/main/c/javacan_socketcan.c' '-fPIC' '-std=c99'
[INFO] 
[INFO] --- native-maven-plugin:1.0-alpha-9:link (compile-native-aarch64) @ JavaCAN ---
[INFO] /bin/sh -c cd '/home/phillip/Code/JavaCAN' && 'aarch64-linux-gnu-ld' '-I' '/usr/lib/jvm/java-10-openjdk/lib' '-o/home/phillip/Code/JavaCAN/target/libSocketCAN-aarch64.so' 'target/objs-x86_64/javacan_socketcan.o' 'target/objs-aarch64/javacan_socketcan.o' '-shared' '-fPIC'
aarch64-linux-gnu-ld: target/objs-x86_64/javacan_socketcan.o: Relocations in generic ELF (EM: 62)
aarch64-linux-gnu-ld: target/objs-x86_64/javacan_socketcan.o: Relocations in generic ELF (EM: 62)
aarch64-linux-gnu-ld: target/objs-x86_64/javacan_socketcan.o: error adding symbols: file in wrong format
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.931 s
[INFO] Finished at: 2018-08-11T18:26:04+02:00
[INFO] Final Memory: 17M/64M
[INFO] ------------------------------------------------------------------------