相关文章推荐
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

In short, I want to change the type of application to win32 app , then, I've used the following commands in .pro file

CONFIG -=windows
QMAKE_LFLAGS += $$QMAKE_LFLAGS_WINDOWS

After use the previous commands the application works fine as I want.
But the problem is I don't know what the meaning of each command of these commands.

Can anybody explain each command of these commands?

The CONFIG variable specifies project configuration and compiler options. The values will be recognized internally by qmake and have special meaning. They are as follows.

[...]

The following options define the application/library type:

windows - The target is a Win32 window application (app only). The proper include paths, compiler flags and libraries will automatically be added to the project.

console - The target is a Win32 console application (app only). The proper include paths, compiler flags and libraries will automatically be added to the project.

Another excerpt from the manual: Operators

Operators

In many project files, the assignment (=) and append (+=) operators can be used to include all the information about a project. The typical pattern of use is to assign a list of values to a variable, and append more values depending on the result of various tests. Since qmake defines certain variables using default values, it is sometimes necessary to use the removal (-=) operator to filter out values that are not required.

The -= operator removes a value from the list of values in a variable:

DEFINES -= USE_MY_STUFF

The above line removes USE_MY_STUFF from the list of pre-processor defines to be put in the generated Makefile.

So with CONFIG -= windows you are removing the value windows from the list of values in variable CONFIG. Looks like windows is among the default values of CONFIG on your platform and you need to remove that value. The value windows defines that your target is a Win32 window application. By removing it you declare that you would not like to have a Win32 window app. If your target is a Win32 console application instead then it is recommended to declare it explicitly: CONFIG += console.

And now let's see QMAKE_LFLAGS += $$QMAKE_LFLAGS_WINDOWS.

Excerpt from the manual: QMAKE_LFLAGS

QMAKE_LFLAGS

This variable contains a general set of flags that are passed to the linker. If you need to change the flags used for a particular platform or type of project, use one of the specialized variables for that purpose instead of this variable.

[...]

QMAKE_LFLAGS_WINDOWS

This is used on Windows only.

This variable contains link flags when building Windows GUI projects (i.e. non-console applications). The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

This means that if you would like to change the flags then you should change either QMAKE_LFLAGS_CONSOLE or QMAKE_LFLAGS_WINDOWS. However you changed QMAKE_LFLAGS directly by adding the value of QMAKE_LFLAGS_WINDOWS which is strange because it contains link flags for building Win32 window apps and you declared with CONFIG -= windows that you would not like to have a Win32 window app.

Firstly, thanks for your explanation.then, this is excerpt from The most important point: However you changed "QMAKE_LFLAGS" directly by adding the value of "QMAKE_LFLAGS_WINDOWS" which is strange because it contains link flags for building Win32 window apps and you declared with "CONFIG -= windows" that you would not like to have a Win32 window app. the problem is in this point, why when remove either one from these commands the project doesn't work, must be both of which exists. – Lion King Sep 9, 2013 at 15:22 @LionKing I have too little information to answer your question. I do not know what you want to build. What you mentioned is win32 app, but which type, a window or a console win32 app? And I do not know which compiler you are using. I have a guess only: QMAKE_LFLAGS_CONSOLE and QMAKE_LFLAGS_WINDOWS may have a common part, that is, some values can be found in both variables. That's why adding the values of QMAKE_LFLAGS_WINDOWS to QMAKE_LFLAGS works for you. Please replace QMAKE_LFLAGS += $$QMAKE_LFLAGS_WINDOWS with QMAKE_LFLAGS += $$QMAKE_LFLAGS_CONSOLE and let's see if it works for you. – Bill Sep 9, 2013 at 17:01 I'm use Qt5.1.1 linked with MSVS2010 Compiler and the purpose of this, to use SDL game library. and the SDL application does not work unless I wrote those commands the above-mentioned in qmake file(.pro). – Lion King Sep 9, 2013 at 23:00 @LionKing Generate Makefile.Release and Makefile.Debug from your .pro file by running qmake, backup them, then remove the 2 lines in question from the .pro file and generate new Makefile.Release and Makefile.Debug files. Then you'll have two Makefile.Release and two Makefile.Debug files that you can compare and see the differences. – Bill Sep 10, 2013 at 6:32 Although I still did not understand, but you deserve to be the best answer, and the reason you are continuously in help me. Congratulations. – Lion King Sep 10, 2013 at 8:59

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

 
推荐文章