如何让 {$IFNDEF DEBUG} 在 lazarus/osx 项目中工作

发布于 2024-09-06 19:26:02 字数 174 浏览 2 评论 0原文

我需要在调试器下运行时禁用一些代码。

所以,我只是想象这样做:

{$IFNDEF DEBUG} 
  ...
{$ENDIF}

但是,ifndef 内的代码在调试器中执行,使其崩溃。

我有拉撒路 0.9.29 &软板2.4.0

I need to disable some code when run under the debugger.

So, I just imagine that doing:

{$IFNDEF DEBUG} 
  ...
{$ENDIF}

However, the code inside the ifndef is executed in the debugger, makin it crash.

I have lazarus 0.9.29 & FPC 2.4.0

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

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

发布评论

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

评论(2

风苍溪 2024-09-13 19:26:02

您提到的编译器指令实际上是:编译器指令,而不是调试指令。

它们与编译过程相关,与调试系统完全分开。

你要做的是:

  • 当你想要调试程序时,定义DEBUG符号。这不会编译测试中存在的块,也不会在调试会话中运行。
  • 当您确实想要发布该代码时,只需取消定义 DEBUG 即可,一切都准备就绪。

您混淆了编译和调试并将它们放在同一上下文中。
它们实际上位于完全独立的上下文中。
这可能是因为您在同一 GUI 系统下编译和调试,但如果您编译程序,调试器唯一查找的就是断点。

希望有帮助。

编辑:您可以通过程序/单元顶部某处的简单 {$DEFINE DEBUG} 来定义它,或者使用 Lazarus 选项窗格将其添加为命令行参数。

来完成我的回答。

The compiler directives that you mention are actually THAT: compiler directives, not debugging directives.

They relate to the compilation process, witch is completely separate from the debugging system.

What you have to do is:

  • When you want to debug the program, define the DEBUG symbol. This will NOT compile the blocks that exist inside the tests and will not run on the debugging session.
  • When you do want to release that code just un-define DEBUG and all is ready to ship.

You are confusing compilation and debugging and putting them in the same context.
They actually reside in complete separate contexts.
This could be due to the fact that you compile and debug under the same GUI system, but if you compile a program the only thing the debugger looks for is break points.

Hope it helps.

Edit: You can define it by a Simple {$DEFINE DEBUG} somewhere at the top of your Program/Unit or use the Lazarus Options pane to add it as a command line param.

To complete my answer.

老子叫无熙 2024-09-13 19:26:02
 {$IFOPT D-}
  //code
 {$ENDIF}

如果 $DEBUGINFO 已打开,则使用调试器运行!

 {$IFOPT D-}
  //code
 {$ENDIF}

if $DEBUGINFO is on that is run with debugger!

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