Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does "-dndebug" (lower-case) do anything in g++?

Tags:

c++

makefile

g++

I'm working on minor changes to a multi-platform C++ project with a 400-line Linux makefile that someone else created years ago.

Two lines in the makefile use -dndebug (lower-case) as a command-line argument to g++.
I think the intention was to define the ndebug symbol, but does the argument even do anything when it's lower-case?

I have minimal knowledge of g++ and make but, going by the page linked below, I think the argument needs to be upper-case to work.
http://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html

like image 768
Scott Leis Avatar asked Jun 17 '14 06:06

Scott Leis


2 Answers

Yes, it should be upper case like this -DNDEBUG.

-D is the GCC option to define a macro. NDEBUG is the macro to be defined to turn off asserts as mandated by the C standard.

I have minimal knowledge of g++ and make but, going by the page linked below, I think the argument needs to be upper-case to work.

As for -dndebug, since macros are case-sensitive, I think it will not have any effect i.e. it should get ignored, unless there is some code you have that references it.

like image 95
legends2k Avatar answered Sep 21 '22 14:09

legends2k


It's fairly easy to test:

$ cat test.cpp
#include <iostream>

int main()
{
#ifdef TEST_DEFINE
    std::cout << "defined" << std::endl;
#endif
    return 0;
}

$ g++ -o 1 -DTEST_DEFINE test.cpp
$ ./1
defined
$ g++ -o 2 -dTEST_DEFINE test.cpp
cc1plus: warning: unrecognized gcc debugging option: T [enabled by default]
cc1plus: warning: unrecognized gcc debugging option: E [enabled by default]
cc1plus: warning: unrecognized gcc debugging option: S [enabled by default]
cc1plus: warning: unrecognized gcc debugging option: T [enabled by default]
cc1plus: warning: unrecognized gcc debugging option: _ [enabled by default]
cc1plus: warning: unrecognized gcc debugging option: E [enabled by default]
cc1plus: warning: unrecognized gcc debugging option: F [enabled by default]
cc1plus: warning: unrecognized gcc debugging option: E [enabled by default]
$ ./2
$

So as you can see the -d option actually causes compiler warnings so it looks like -D is what was intended.

like image 28
trojanfoe Avatar answered Sep 24 '22 14:09

trojanfoe