Showing posts with label vs2010. Show all posts
Showing posts with label vs2010. Show all posts

Monday, April 6, 2015

Qt 4.7 and VS2010 Moc problem

When the projects grow bigger, the project settings might go out of control sometimes. Today I want to share a quick fix for one specific such case.

My case and fix happens under Qt version 4.7, Visual Studio 2010 and Qt Visual Studio add-on 1.1.7; however it might be applicable to other versions too.

When you have an error like "moc: Too many input files specified":
moc: Too many input files specified
1>  Usage: moc [options] <header-file>
1>    -o<file>           write output to file rather than stdout
1>    -I<dir>            add dir to the include path for header files
1>    -E                 preprocess only; do not generate meta object code
1>    -D<macro>[=<def>]  define macro, with optional definition
1>    -U<macro>          undefine macro
1>    -i                 do not generate an #include statement
1>    -p<path>           path prefix for included file
1>    -f[<file>]         force #include, optional file name
1>    -nn                do not display notes
1>    -nw                do not display warnings
1>    @<file>            read additional options from file
1>    -v                 display version of moc
One of the general cases I have encountered is the problem caused by the spaces in the project path. A quick solution might be getting rid of that ambiguity by changing the workspace and/or paths of environment variables.

However, in my case, I have multiple moc files and I get this error for only a few files. In that case, open the project settings file with a text editor (i.e. "vi <project_name>.vcxproj"), and look for "moc_". You will see that some moc files might be excluded from the build.

Normal:
<ClCompile Include="GeneratedFiles\Release\moc_normal_file.cpp" />
Excluded:
<ClCompile Include="GeneratedFiles\Release\moc_excluded_file.cpp" /> <ClComp      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>   <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>    </ClCompile>
Changing the excluded file to a normal form would make it be compiled and linked as the usual files:
<ClCompile Include="GeneratedFiles\Release\moc_excluded_file.cpp" />
If not, I would advise to look for more changed/corrupted settings in that file, especially with the filename associated with the error above.