Net beans optimized out

Jan 4, 2019 at 2:45pm
Hello every one!
I use Net Beans on Arch Linux. How I turn off optimization in g++, for view values of variables?
I'am trying:
1. "Project properties" > "C++ Compiler" > "Additional options" added -O0.
2. I use "volatile" before variable. For example volatile int length = strlen(str)

But it's, don't work ((
Jan 4, 2019 at 3:28pm
What exactly doesn't work? Can you describe how you're building and running it?
What is the full compiler command produced?

If you need to view values of variables, I assume that means you're debugging.
Are you turning on debugging symbols?
https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html
Try adding -g.

Also, does this article help?
https://netbeans.org/kb/docs/cnd/debugging.html
Last edited on Jan 4, 2019 at 3:31pm
Jan 5, 2019 at 10:06am
When I view variable value, I see "<optimized out>". I building and running as described https://netbeans.org/kb/docs/cnd/debugging.html. I click "Clean and building project" > "Debug project".
Screenshot https://ibb.co/mRCbxyB. I note, if place string int length = strlen(str); (as view the screenshot) in constructor, value of variable "<optimized out>", but place in main(), value viewed correct. I try adding -g, but not working.

Jan 5, 2019 at 4:41pm
Your screenshot has gone.
Jan 5, 2019 at 6:26pm
Hmmm... It's strange... May be you copy link with last dot? Alternative link https://pictr.com/image/0CHzSx
Last edited on Jan 5, 2019 at 6:32pm
Jan 5, 2019 at 7:01pm
It might be because you don't use length for anything.
Jan 5, 2019 at 7:15pm
Peter87, yes. You right, if I use variable below, then I see value. Can I view value without use variable?
Jan 5, 2019 at 11:51pm
I don't know. What's the point of the variable if you're not using it?
Jan 6, 2019 at 1:22pm
I heave read: "if I see "<optimized out>", and don't use variable, then will adding option -O0 into compilation string". It's don't working. Thank's every body!
Topic archived. No new replies allowed.