How do you use jextract for two or more header files?
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Tue Aug 24 16:02:31 UTC 2021
Hi Carl,
note that jextract has an option to override the name of the generated
class: `--header-class-name`. This might alleviate the problem you are
referring to.
Maurizio
On 24/08/2021 15:17, Carl Dea wrote:
> Paul,
> Excellent!
> Yes others have mentioned this technique.
> Although it works rather well, the imports will have a header’s name:
> For example:
> foo.h
>
> After jextract it’s
>
> import org.unix.foo_h.*;
>
> Not a deal breaker, but just thought it might be noted in docs.
>
> Thank you,
> Carl
>
> Sent from my iPhone
>
>> On Aug 23, 2021, at 2:13 PM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
>>
>> Hi Carl,
>>
>> Generating separately will overwrite common generated artifacts (in this case the constants classes).
>>
>> Create your own header file with the following content:
>>
>> #include <stdio.h>
>> #include <time.h>
>>
>> Then run jextract using that header file as input.
>>
>> Paul.
>>
>>> On Aug 22, 2021, at 9:25 PM, carl dea <carl.dea at gmail.com> wrote:
>>>
>>> Panama Dev team,
>>>
>>> I'm trying to use jextract for stdio.h and time.h, but getting compile
>>> issues when the target (-t) name space is the same such as *-t org.unix*
>>> *jextract stdio.h*
>>>
>>> # jextract stdio.h
>>> jextract --source -d generated/src -t org.unix \
>>> -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
>>> \
>>> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdio.h
>>>
>>> *jextract time.h*
>>>
>>> # jextract time.h
>>> jextract --source -d generated/src -t org.unix \
>>> -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
>>> \
>>> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/time.h
>>>
>>> *Compile source*
>>>
>>> javac -d classes generated/src/org/unix/*.java
>>>
>>>
>>> *Compile Error*
>>> The following compile errors (87 errors)
>>> generated/src/org/unix/stdio_h.java:732: error: cannot find symbol
>>> return
>>> RuntimeHelper.requireNonNull(constants$0.renameat$MH,"renameat");
>>> ^
>>> symbol: variable renameat$MH
>>> location: class constants$0
>>> generated/src/org/unix/stdio_h.java:735: error: cannot find symbol
>>> ...
>>>
>>> *Workaround (change namespace)*
>>> My workaround is making time.h 's target namespace to *-t org.unix.time*.
>>> When I'm in the IDE and using Panama the source code looks like the
>>> following
>>>
>>> import static org.unix.stdio_h.*;
>>> import static org.unix.time.time_h.*;
>>>
>>> import org.unix.time.tm;
>>> ...
>>> // more code
>>> localtime_r(now2, pTmStruct);
>>>
>>> Is there a better way to perform a jextract on two more headers?
>>>
>>> This example uses both stdio.h and time.h
>>> https://github.com/carldea/panama4newbies/blob/main/part03/src/PanamaTime.java
>>>
>>>
>>> Thank you,
>>> Carl
>>>
>>> --
>>> *Carl Dea*
>>> Email: carldea at gmail.com
>>> Website: https://carlfx.wordpress.com
>>> Twitter: @carldea <https://twitter.com/carldea>
More information about the panama-dev
mailing list