1

I would like to compile my Qt program with a Qt 32 bits kit on a Windows 64 bits OS with QProcess.

I compile with a 64 bits kit using: C:/Qt/5.15.1/msvc2019_64/bin/qmake.exe then C:/Qt/Tools/QtCreator/bin/jom.exe and it works perfectly fine.

Things I tried to do to compile in 32 bits:

QProcess envBuilder;

envBuilder.start("\"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/vcvars32.bat\"", QStringList());
envBuilder.waitForFinished();
qDebug() << envBuilder.exitCode();
qDebug() << envBuilder.readAllStandardOutput();
qDebug() << envBuilder.readAllStandardError();

envBuilder.start("\"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/vcvarsall.bat\"", {"x86"});
envBuilder.waitForFinished();
qDebug() << envBuilder.exitCode();
qDebug() << envBuilder.readAllStandardOutput();
qDebug() << envBuilder.readAllStandardError();

envBuilder.start("C:/Qt/5.15.1/msvc2019/bin/qtenv2.bat", QStringList());
envBuilder.waitForFinished();
qDebug() << envBuilder.exitCode();
qDebug() << envBuilder.readAllStandardOutput();
qDebug() << envBuilder.readAllStandardError();

envBuilder.start("C:/Qt/5.15.1/msvc2019/bin/qmake.exe", {"MyProject.pro", "-o", "Makefile", "-spec", "win32-msvc", "\"CONFIG+=qtquickcompiler\""});
envBuilder.waitForFinished();
qDebug() << envBuilder.exitCode();
qDebug() << envBuilder.readAllStandardOutput();
qDebug() << envBuilder.readAllStandardError();

envBuilder.start("C:/Qt/Tools/QtCreator/bin/jom.exe", {"-f", "Makefile", "/D", "release"});
envBuilder.waitForFinished();
qDebug() << envBuilder.exitCode();
qDebug() << envBuilder.readAllStandardOutput();
qDebug() << envBuilder.readAllStandardError();

Compilation starts correctly but when linking it ouputs:

Qt5Charts.lib(Qt5Charts.dll) : fatal error LNK1112: module machine type 'x86' conflicts with target machine type 'x64'

What am I missing ?

xavi-b
  • 95
  • 1
  • 11
  • I copy/pasted your code and it compiles and executes. I do not have the problem. Do you have multiple `compilation kit`? – Pat. ANDRIA Oct 28 '20 at 13:26
  • 1
    Yes 5.15.1 64 bits, 5.15.1 32 bits and some others – xavi-b Oct 28 '20 at 13:48
  • Then you error is caused by the fact that you want to compile/link in 32 bits using a 64 bits lib or vice versa. I already had this error. Verify the different path you have in your compilation kits and it should go right. If it works and solves your problem then post your solution and I will give you an upvote :-) – Pat. ANDRIA Oct 28 '20 at 15:07
  • All of the `envBuilder.start()` are independent so calling the batch files is not helping initializing the environment variables for the execution below. – drescherjm Oct 28 '20 at 17:03
  • How can I make it so that the environment "generated" from the commands `vcvars32.bat` and `vcvarsall.bat x68` lasts to the commands `qmake.exe` and `jom.exe` ? – xavi-b Oct 28 '20 at 17:06
  • I think you want to call both in the same start() perhaps using something like `cmd /c batchfile.bat && executable.exe args for exe ...` – drescherjm Oct 28 '20 at 17:56

2 Answers2

0

Your error is caused by the fact that you compile a 32 bits target using 64 bits libraries (or vice versa).

On one hand, choose carefully which version of vcvarsXXXX.bat you use.

I talk about the line

C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/vcvars32.bat

You will find that there are many variants of this bat file for different targets.

On the other hand, you may also want to verify if the path in you compilation kits do not mix paths (e.g: use the 64bits path for the 32bits kits or vice versa)

You may want to check here also.

Pat. ANDRIA
  • 2,330
  • 1
  • 13
  • 27
  • PATH was indeed pointign to the 64bits kit, I edited the PATH of my QProcess and now I get: `LINK : fatal error LNK1181: cannot open input file 'User32.lib'` – xavi-b Oct 28 '20 at 15:43
  • A path is missing in your library path. I'm almost sure this comes from `Visual studio` initialisation script (the `vcvarsXXXX.bat` script). Could you check if you launch the one with the correct target? There are multiple files (`vcvarsall.bat`, `vcvars32.bat`, `vcvarsx86_amd64.bat`, `vcvars64.bat`...) . Check if you are using the correct one. Also check if in the `System environnement` of your kit, all your path to the system environment is not missing. – Pat. ANDRIA Oct 28 '20 at 15:55
  • As shown on my original post, I run `vcvars32.bat`and `vcvarsall.bat x86` but it doesn't change a thing. I did not understand your last sentence. – xavi-b Oct 28 '20 at 16:01
  • I do not understand. I am not compiling with QtCreator but with command lines inside a QProcess. I want my 64bits "builder" program to compile a 32bits Qt program inside his QProcess. – xavi-b Oct 28 '20 at 16:31
  • In your original post, you don't run only `vcvars32` but `vcvarsall`, which imho will be in 64 bits if uour machine is 64 bits. try to explicitly use `vcvars32`. Indeed, you run it twice (first 32 and then all), which will then override the first. Run only `vcvars32` to try – Pat. ANDRIA Oct 29 '20 at 06:09
0

Thanks to all the comments, what finally worked is :

QProcess envBuilder;

envBuilder.start("\"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/vcvars32.bat\" && C:/Qt/5.15.1/msvc2019/bin/qtenv2.bat && C:/Qt/5.15.1/msvc2019/bin/qmake.exe", {"MyProject.pro", "-o", "Makefile", "-spec", "win32-msvc", "\"CONFIG+=qtquickcompiler\""});
envBuilder.waitForFinished();
qDebug() << envBuilder.exitCode();
qDebug() << envBuilder.readAllStandardOutput();
qDebug() << envBuilder.readAllStandardError();

envBuilder.start("\"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/vcvars32.bat\" && C:/Qt/Tools/QtCreator/bin/jom.exe", {"-f", "Makefile", "/D", "release"});
envBuilder.waitForFinished();
qDebug() << envBuilder.exitCode();
qDebug() << envBuilder.readAllStandardOutput();
qDebug() << envBuilder.readAllStandardError();
xavi-b
  • 95
  • 1
  • 11