I am trying to compile a simple program using scons + MSVC compiler under Windows. Program source is just simple "Hello world".
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!\n";
return 0;
}
SConstruct is utterly simple:
Program("hw.cc")
When I run scons
in the source directory, I get
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
cl /Fohw.obj /c hw.cc /TP /nologo
scons: *** [hw.obj] Error 123
scons: building terminated because of errors.
in the console and pop-up message with 0xc000007b error.
Aslo results of where
command:
where cl
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\bin\Hostx86\x86\cl.exe
where scons
C:\Python35-32\Scripts\scons.bat
I don't have any clue what's wrong.
UPD 2
After some experiments with cl
and scons
I have finally figured out what was wrong and how to fix it.
First of all, cl
should be available from the command line. If after entering command cl
in the console you get errors like command not found
, you should add path to cl.exe
to the PATH
system variable. In my case
PATH=<rubbish>;C:\Microsoft\VC\Tools\MSVC\14.14.26428\bin\Hostx86\x86;
After this you should set up variables INCLUDE
and LIB
to tell compiler and linker where to find include files and libs. And this part is a little bit tricky, because, to my surprise, cl
does not compiling anything without Windows Kits 10 (whatever it is). Thus, you should specify its includes and libs accordingly. In my case
INCLUDE=C:\Microsoft\VC\Tools\MSVC\14.14.26428\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\ucrt
LIB=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17134.0\ucrt\x86;C:\Microsoft\VC\Tools\MSVC\14.14.26428\lib\x86;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17134.0\um\x86
When these variables are set up correctly, hw.cc
should compile fine.
And, probably, this should do the trick for scons
too, but to make one hundred percent sure it works correctly, SConstruct
should be modified to something like this
import os
env = Environment(ENV = os.environ)
flags = ["/EHsc"] # Flags are completely optional
env.Program("hw.cc", CXXFLAGS=flags)
With all these steps, everything should compile fine.
User contributions licensed under CC BY-SA 3.0