打开并写入 FORTRAN DLL 中的文件

发布于 2024-09-07 03:35:25 字数 433 浏览 10 评论 0原文

我正在用 fortran 编写并使用 g95 编译器进行编译。

我需要将日志文件输出到我正在编写的 DLL,该 DLL 当前正在与主程序链接并运行,但会产生不正确的结果。我对 FORTRAN 不太了解,但我确实得到了以下代码来在我编译的 EXE 中生成输出:

  OPEN(UNIT=3, FILE='LOG.txt', STATUS='NEW')
  WRITE(3,*) "the gospel of PTP is bestowed upon the file."
  CLOSE(3)

这在独立的 EXE 中工作,当我运行它时,它会生成一个包含该字符串的文件。但是当我尝试将它包含在我正在处理的 DLL 中时,它会崩溃一切。当我将其注释掉时,一切都会再次运行并工作,但显然不会产生所需的输出。

有什么想法吗?有 FORTRAN 或 g95 人吗?

I am writing in fortran and compiling using the g95 compiler.

I need to have a log file output to a DLL i am writing, that is currently linking and running with the master program, but producing incorrect results. I don't know much about FORTRAN, but i did get the following code to produce output in an EXE i compiled:

  OPEN(UNIT=3, FILE='LOG.txt', STATUS='NEW')
  WRITE(3,*) "the gospel of PTP is bestowed upon the file."
  CLOSE(3)

this works in a stand alone EXE, when i run it, it produces a file with the string inside. But when i try to include it in the DLL i am working on, it crashes everything. when i comment it back out, everything runs and works again, but obviously doesn't produce the desired output.

Any ideas? Any FORTRAN or g95 people?

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

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

发布评论

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

评论(1

又爬满兰若 2024-09-14 03:35:25

猜测可能有帮助,也可能没有帮助,我很少使用 Fortran DLL 直接写入任何内容:

  • 您希望 DLL 将文件“LOG.txt”写入何处?它是否可能试图写入禁止写入的位置?我不太确定为什么这会让你的程序崩溃,但你需要检查一下。我希望您从您的用户目录之一运行代码的 EXE 版本。

并且,评论:

  • 在 Fortran 中通常避免使用单位数字。大多数操作系统将它们用于 stdout、stderr 等,虽然有常见的分配(例如,我认为 stdout 通常是 5,stderr 6),但这些在 Fortran 标准中没有定义,编译器编写者可以自由使用单元号他们认为合适的。

A guess which might help, or might not, I have rarely used Fortran DLLs to write anything directly:

  • To where do you expect the DLL to write the file 'LOG.txt' ? Is it perhaps trying to write into a location it is forbidden to write to ? Why that would crash your program I'm not very sure, but it's something for you to check. I expect that you ran the EXE version of your code from one of your user directories.

And, a comment:

  • In general avoid single-digit unit numbers in Fortran. Most o/s use them for stdout, stderr, etc, and while there are usual assignments (eg stdout is usually 5 I think, and stderr 6) these are not defined in the Fortran standard and compiler-writers are free to use unit numbers as they see fit.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文