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

.

Maxim Makhun
  • 2,197
  • 1
  • 22
  • 26
Quaid Tseng
  • 41
  • 1
  • 1
  • 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. – Greg Hewgill Jan 17 '14 at 03: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.) – Greg Hewgill Jan 17 '14 at 03: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. – Quaid Tseng Jan 17 '14 at 03: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 Oct 30 '14 at 16:42

4 Answers4

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.

jalf
  • 243,077
  • 51
  • 345
  • 550
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.

aampere
  • 270
  • 3
  • 10
  • 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 Oct 30 '14 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" – Soundararajan Oct 31 '14 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.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
0

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

  • 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](/help/how-to-answer). – Community May 27 '22 at 03:13