Skip to content

How to compile as static object file .o (not shared object)? #9637

@JavaCoder78

Description

@JavaCoder78

Describe the issue
I am trying to figure out how I can compile a static library (COFF file) when building with native-image. Is this possible? I have been trying to play around with --static and --shared but I am not allowed to use both. I also tried to use --native-compiler-options=-c. My ultimate goal is to generate a static library (.a) file from this.

Steps to reproduce the issue
Please include both build steps as well as run steps

  1. Compile this HelloWorld.java using: javac HelloWorld
class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
  1. run: native-image --native-compiler-options=-c HelloWorld
$ native-image --native-compiler-options=-c HelloWorld
========================================================================================================================
GraalVM Native Image: Generating 'helloworld' (executable)...
========================================================================================================================
[1/8] Initializing...
                                                                                    (0.0s @ 0.09GB)
------------------------------------------------------------------------------------------------------------------------
                        0.3s (9.2% of total time) in 11 GCs | Peak RSS: 0.45GB | CPU load: 4.06
------------------------------------------------------------------------------------------------------------------------
Produced artifacts:
 /home/user/Downloads/helloworld/svm_err_b_20240908T023752.138_pid990389.md (build_info)
========================================================================================================================
Failed generating 'helloworld' after 2.4s.

The build process encountered an unexpected error:

> com.oracle.svm.core.util.VMError$HostedError: Unable to run '/tmp/SVM-1725755871806/JNIHeaderDirectives' to compute offsets in C data structures. Is it possible that your antivirus software interferes and puts the resulting file into quarantine?

Please inspect the generated error report at:
/home/user/Downloads/helloworld/svm_err_b_20240908T023752.138_pid990389.md

If you are unable to resolve this problem, please file an issue with the error report at:
https://graalvm.org/support

Describe GraalVM and your environment:

  • Oracle GraalVM 17.0.12+8.1
  • JDK major version: Java version: 17.0.12+8-LTS
  • OS: Linux / Ubuntu
  • Architecture: AMD64

More details
N/A

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions