使用 JNA 构建 C 项目时遇到问题

发布于 2024-11-04 03:31:14 字数 713 浏览 1 评论 0原文

尝试创建一个小型 JNA 程序。

生成头文件后,我现在尝试构建并创建 dll 文件。但是这个问题出现了......

我使用 Netbeans IDE 和 Cygwin,其他 C/C++ 项目可以工作。

gcc:-mno-cygwin 标志已 删除;使用 mingw 为目标 交叉编译器。

make[2]:离开 目录 `/cygdrive/c/Users/User/Documents/NetBeansProjects/HelloWorldNative'

make[1]:离开目录 `/cygdrive/c/Users/User/Documents/NetBeansProjects/HelloWorldNative'

make[2]:* [构建/调试/Cygwin-Windows/_ext/1653581963/HelloWorldNative.o] 错误1

make[1]:* [.build-conf] 错误2

make:* [.build-impl] 错误 2

构建失败(退出值2,总时间:1s)

我真的很想让 Netbeans 在这里工作,因为我是 JNA 的新手,并且希望能够快速进行更改和实验。因此,必须从控制台每 5 秒构建它并不可取:S

Trying to create a small JNA program.

After generating the header file im now trying to build and create the dll file. But this problem arises...

Im using the Netbeans IDE with Cygwin, other C/C++ projects work.

gcc: The -mno-cygwin flag has been
removed; use a mingw-targeted
cross-compiler.

make[2]: Leaving
directory
`/cygdrive/c/Users/User/Documents/NetBeansProjects/HelloWorldNative'

make[1]: Leaving directory
`/cygdrive/c/Users/User/Documents/NetBeansProjects/HelloWorldNative'

make[2]: *
[build/Debug/Cygwin-Windows/_ext/1653581963/HelloWorldNative.o]
Error 1

make[1]: * [.build-conf]
Error 2

make: * [.build-impl] Error
2

BUILD FAILED (exit value 2, total time: 1s)

I would really like to get Netbeans to work here as I'm new to JNA and want to be able to quickly make changes and experiment. So having to build it from console evry 5 secs is not preferable:S

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

过去几天我一直致力于实现 Java + JNA + Cygwin 解决方案。经过多次尝试和死胡同,我终于想出了一个好的解决方案。我的 JNA 调用是 getpwnam、chown 和 perror,所有三个调用都实现到 Cygwin1.dll 中。您可以在 http://vouters 中查看适用于我的上下文的完整解决方案.dyndns.org/tima/Linux-OpenVMS-Java-Implementing_chown_in_Java.html

我只是希望我的编码和文档风格对您来说足够清晰。

I have been working those past days onto implementing a Java + JNA + Cygwin solution. After many attempts and dead ends, I finally come up with a sound solution. My JNA calls are getpwnam, chown and perror, all three implemented into Cygwin1.dll. You may view my full solution which applies to my context at http://vouters.dyndns.org/tima/Linux-OpenVMS-Java-Implementing_chown_in_Java.html

I just hope my coding and documentation style is clear enough for you.

傲鸠 2024-11-11 03:31:14

我想我有点失落了。 JNA 的全部意义在于它使您不必编写或编译本机代码。您需要提供有关本机代码正在执行的操作的更多详细信息。您是否正在尝试编译自己的 dll,然后计划使用 JNA 访问该 dll?如果是这样,您可能没有正确设置 Netbeans 来构建 dll。我猜它正在尝试构建一个可执行文件,但找不到“主要”方法。

I guess I'm a bit lost. The whole point of JNA is that it frees you from having to write or compile native code. You need to provide more details as to what your native code is doing. Are you trying to compile your own dll, which you then plan to access using JNA? If so, you probably don't have Netbeans set up properly to build a dll. I'm guessing it's trying to build an executible, but can't find a 'main' method.

想念有你 2024-11-11 03:31:14

在我提供的 Java/JNA chown 代码中,我调用的 DLL 是 Cygwin1.dll,这是 Cygwin 附带的 dll,其中包含我之后的三个调用(getpwnam、chown 和 perror)。

为什么我需要 Cygwin1.dll ?因为这是 Windows 上唯一包含这些 Unix 入口点的 DLL。我的目标仍然是尽可能多地编写可移植的代码。 MinGW 不提供这些电话,我不得不放弃。

微软肯定会提出一些与这些 Unix 调用类似的东西。然而,这肯定会导致我编写 Windows 特定的代码。我确实不关心这个。

希望这能澄清

In the Java/JNA chown code I provide, the DLL I call is Cygwin1.dll, a Cygwin's shipped dll, which contains the three calls I am after (getpwnam, chown and perror).

Why do I need Cygwin1.dll ? Because this is the only DLL on Windows containing these Unix entry points. My purpose still remains to write as much as portable code as I can. MinGW not offering these calls, I had to give up with it.

Microsoft may surely propose something analogue to these Unix calls. However this would have surely caused me to assemble a Windows specific code. I am indeed not looking after this.

In the hope this clarifies

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文