[英]Is there a difference in source code for release and debug compiled program? [C/C++]
[英]How to obtain debug/release conditional compiling in C++ program
在一個大型的C ++ / Qt / QMake / qtcreator項目中,我想執行一些測試,但只有在我使用debug標志進行編譯時。
有沒有辦法告訴g ++代碼的一些小部分只能在調試模式下編譯?
執行此操作的標准方法是依賴於宏NDEBUG
,它由<cassert>
定義的宏assert()
使用:
#ifdef NDEBUG
// release mode code
#else
// debug mode code
#endif
#ifdef
的反面是#ifndef
,當然#else
分支是可選的。
如果這個宏不起作用(無論出於何種原因),你
可以嘗試宏QT_NO_DEBUG
,Qt用於與Q_ASSERT()
類似的目的; 和
應該修復它以便正確定義(未) NDEBUG
; <cassert>
需要正常工作,您使用的代碼可能依賴於它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.