Mocing with Visual Studio command line, exit with code 1
-
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
-
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:
qmake <path_to_file.pro>\<file.pro>
Then run:
nmake
for debug build or
nmake release
for 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.Paul