I am using SWIG (https://www.swig.org/) to convert C++ to Java code and have it as a shared library for use from within Java with System.loadLibrary("foo.so").
SWIG call goes ok
swig -DSWIGWORDSIZE64 -c++ -java -I<location of c++ STL> -I<location of headers I'm converting> -package <java package i want i.e. blah.bar.foo> -outdir <path to said java package i.e. src/blah/bar/foo> <SWIG interface file I wrote, i.e. src/blah/bar/foo/foo.i>
This generates foo_wrap.h, foo_wrap.cxx, and a bunch of Java files implementing objects I specified for conversion in the .i file. So far so good. The JNI in the .cxx looks reasonable to my non-JNI-trained eye.
Compile call goes ok
g++ -c -std=c++17 <path to the wrap files, i.e. src/blah/bar/foo/foo_wrap.*> -I<location of JDK17 include folder> -I<location of JDK17 Linux include folder> -I<location of c++ STL> -I<location of headers I'm converting> -fPIC -o <path to the .o file, i.e. src/blah/bar/foo/foo_wrap.o>
This generates foo_wrap.o.
Calling file src/blah/bar/foo/foo_wrap.o says GCC precompiled header (version 014) for C++.
Something goes wrong with the next step.
g++ -shared <the .o file, i.e. src/blah/bar/foo/foo_wrap.o> -o <the shared library I want, i.e. src/blah/bar/foo/libfoo.so>
The error message is file not recognized: File format not recognized
I did not have this issue doing it with the simple example provided on SWIG page, but the simple example wasn't dealing with existing built libraries. I can think of two possibilities that may be causing it to be wrong, but I'm not sure
- I need to provide the existing .so file that has the built source for the rest of the C++ code I am trying to convert. I'm not sure where I would provide that, I tried it with -I on the last step and it did not make a difference.
- I did something silly in the format or order of my last g++ step.