Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JavaCoder78 opened this issue Sep 8, 2024 · 2 comments
Closed

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

JavaCoder78 opened this issue Sep 8, 2024 · 2 comments
Assignees

Comments

@JavaCoder78
Copy link

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

@selhagani
Copy link
Member

Hi @JavaCoder78,

Thank you for reaching out to us! Unfortunately, native-image does not support generating static libraries like that. The native-image tool is designed primarily for producing native executables, and while it can generate shared libraries using the --shared option, it does not support generating static libraries since --static is meant for producing static executables, not libraries. Also The --static and --shared options cannot be used together.

@JavaCoder78
Copy link
Author

Turns out all the files I needed were located in the graalvm /lib directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants