MS VS 2010 C++ project - how to define DEBUG var?

longjumps
longjumps used Ask the Experts™
on
I have project and imported source regex.c

In this source I have
# ifdef DEBUG
.....


How to add this to project in order to get debugging information?

Where it prints?

Sources are attached.
regex.c
xregex.h
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
AndyAinscowFreelance programmer / Consultant

Commented:
When you select the DEBUG (as opposed to RELEASE) build then it is already defined for you.
AndyAinscowFreelance programmer / Consultant

Commented:
>>Where it prints?

If you use a TRACE command it prints to the output window (which is in visual studio)

Author

Commented:
How to use Trace command?
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

AndyAinscowFreelance programmer / Consultant

Commented:
eg.
      TRACE(_T("In put your function/class/whatever here"));

or
        TRACE(s);  //s is a string variable, eg with the value of some other variable in it

Author

Commented:
The question was related to
# ifdef DEBUG

and in the source I have already debugging printings like
DEBUG_PRINT1 ...

and others.

So the question is how should I compile and run this code in Visual Studio 2010 to see the existing printing and not adding new TRACEs?
AndyAinscowFreelance programmer / Consultant

Commented:
Build it as a debug build (see my original comment).Possibile build choices - Debug and ReleaseDEBUG is defined for you in a debug build

Author

Commented:
I don't see "Active Debug".

What should I do?

See attachment.
vs2010-no-active-debug.png
AndyAinscowFreelance programmer / Consultant

Commented:
In my snapshot there are only two project configurations defined.  Debug and Release.  That show the currently selected (=active) one is debug.

Author

Commented:
Dear, if I need something define or add, please advice how.

I simply wants that in the lib code I compile and run get debugging printing, using already existing in the code

# ifdef DEBUG
.....

DEBUG_PRINT1 ...

and others.

I attached lib code to the original question.

Please advice.
Freelance programmer / Consultant
Commented:
The following will define a symbol called DEBUG
#define DEBUG

(but for a debug build it is already defined so you do not need to do anything)


ps.  You can add that line of code to .h files or .cpp files anywhere you wish.  The symbol is only visible to the compiler AFTER it is defined.

Author

Commented:
But how to define DEBUG not from code, but compile variable?
AndyAinscowFreelance programmer / Consultant

Commented:
You can't.
It is a compiler directive to modify how code is compiled.

Author

Commented:
such precompiler directive should be pass from outside of code by compiler.
in Linux there is something -D<var>  can I do such thing in Win?
AndyAinscowFreelance programmer / Consultant

Commented:
You can define things in the command line to the compiler BUT it is not a variable.  They determine which blocks of code are compiled or not.  (See the project settings).

Author

Commented:
checking the solution

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial