Mocing with Visual Studio command line, exit with code 1
Ver.X last edited by Ver.X
I am trying to use the visual studio command line to mocing files, but I get error below:
The command "<PATH_TO_QT>\qtbase\bin\moc.exe <PATH_TO_FILE>\file.h -nw -o .\GeneratedFiles\Release\moc_file.cpp -DUNICODE -DWIN32 -DWIN64 -DQT_DLL -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -I.\GeneratedFiles -I. -I<PATH_TO_QT>\qtbase\include -I.\GeneratedFiles. -I<PATH_TO_QT>\qtbase\include\QtCore -I<PATH_TO_QT>\qtbase\include\QtGui -I<PATH_TO_QT>\qtbase\include\QtWidgets" exited with code 1.
It seems that this error caused by my misuse the moc command. Is there any hint for me to figure out what should I fix?
My qt version is 5.4.1(static build). Also QT ADDIN works for me, I just want to figure out how to build it through the command line.
Thank you guys XDD
msue last edited by
You should use the devenv command to build a project or the complete solution. Then Visual Studio will do all the necessary steps including moc.
@msue Is there anyway avoid calling qmake?
Also I believe what qmake does is setting up the visual studio command line, then the visual studio will run the command line when it build the project. If I manually run the command line then does that means I do not need to call qmake?
It resolved. It turns out that I put a wrong output paht... stupid.
Thanks anyways XD
Paul H. last edited by
Are you just looking to be able to build a Qt project from a Visual Studio command line?
Or are you trying to duplicate everything Visual Studio does when it builds the project (target directories, etc.)?
For the first option, the first thing to do is make sure qmake is in your path. Then what I do is create a build directory, change to that directory, run:
nmakefor debug build or
nmake releasefor release build.
For the second option, change to the directory with the project file and run:
msbuild <MSVC_project_or solution_file>
You don't need the project file name if you only have one project (.vsxproj) in the folder. You can add options to the command line, such as:
msbuild <MSVC_project_file> /t:clean- clean the project.
msbuild <MSVC_project_file> /t:rebuild- rebuild the project.
msbuild <MSVC_project_file> /p:Configuration=Release- build release version.
You can also put the options together:
msbuild <MSVC_project_file> /t:rebuild /p:Configuration=Release- rebuild release version.
See this page for more information.