0

This is some code to get an environment variable from inside Qt, however, it seems Qt's QProcessEnvironment::systemEnvironment() only reflect a new environment variable change after reboot. So I am thinking about using getenv. However I got "error C2220: warning treated as error - no 'object' file generated" from this :

QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
const QString ENGINE_ROOT = env.value("ENGINE_ROOT", "") != "" ? 
env.value("ENGINE_ROOT","") : QString(getenv("ENGINE_ROOT"));

Don't tell me something like disable /WX or lower W4 to W3, I don't want to hear this, I want to know exactly what cause

no 'object' file generated

.

4
  • 2
    What was the warning you actually got, that triggered the C2220 error? Your compiler is set to treat warnings as errors, and errors cause the compiler to not generate an output object file. In order to avoid that error, you need to fix the warning. Commented Jan 17, 2014 at 3:19
  • Also, your original problem of "only reflect a new environment variable change after reboot" would probably be solved by simply reopening your command prompt window (or opening a new one). The environment variables inherited by a command prompt window are those in effect at the time it is opened. (Or, the environment variables inherited by any process, including your IDE for example.) Commented Jan 17, 2014 at 3:22
  • I am not talking about doing it inside cmd.exe, if you reopen another cmd.exe then of course you'll see it reflects the new environment variables. I am talking about retrieve environment varialbes inside Qt, where it seems not able to relect new changes on the fly. Commented Jan 17, 2014 at 3:30
  • 2
    The OP has fallen into the trap of thinking "no 'object' file generated" is the warning causing the error. The error is ambiguously worded imo and invites this confusion.
    – chrisvarnz
    Commented Oct 30, 2014 at 16:42

4 Answers 4

10

"error C2220: warning treated as error - no 'object' file generated"

The error already answers your question:

  1. A warning was generated.
  2. Because you have told the compiler to treat warnings as errors, an error occurred.
  3. Because an error occurred, the compiler did not generate an object file.

If you want to know what the original warning means, then you need to ask us about that warning.

4

I just had this problem. The real source of the confusion is that Microsoft Visual Studio lists the
error C2220: warning treated as error - no 'object' file generated
line separately from the warnings--sometimes even before the warnings--so it is not immediately apparent that the error is related to the listed warnings.

Fix all warnings listed to fix this problem.

2
  • 1
    It's especially confusing that the warning appears to be "no 'object' file generated", which seems to be the trap the OP fell into.
    – chrisvarnz
    Commented Oct 30, 2014 at 16:16
  • In my case i have a bunch of other warnings, and when i added /wd for those warnings this warning went away. And as a sidenote, i don't think C2220 can be ignored using /wd2220. The compiler (VS2010) produces a warning citing it as a improper value in command line" Commented Oct 31, 2014 at 11:19
3

I'll address the underlying question instead of the compilation problem.

Environment variables for any process are copied from those of its parent process when your new process is started. From that point, the only thing that can modify them is your process yourself.

In practical terms, this means that going to the Windows dialog box to change environment variables does not change those values for any existing processes. Those changes are applied to the explorer.exe process, and then any new processes launched from Explorer.

There is a possible way for a Windows application to get notified of changes made to environment variables made by Explorer. See How to modify the PATH variable definitely through the command line in Windows for details.

0

in my case, eliminating all useless 'object' will deal this erro

1
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented May 27, 2022 at 3:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.