Search code examples
c++visual-c++scons

how to build c++ project with scons 2.3 visual express 2012?


I try:

env = Environment(ENV = {'PATH' : os.environ['PATH'], \
            'INCLUDE' : 'c:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\include\\', \
            'LIB' : 'c:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\lib\\'})

but it not working. error message: "cl" is not command ...

I found description in scons wiki(http://www.scons.org/wiki/PlatformSpecificNotes#Visual_C.2B-.2B-): If using Microsoft Visual C++, you need to set 'INCLUDE', 'LIB' and 'PATH' in your environment, then import them when you create your 'Environment' object. These will be used to locate the MSVC++ tools and set 'CPPFLAGS' etc.

What am I doing wrong?

complete sconstruct(it works on ubuntu, and on windows with mingw):

import os
import sys

if ARGUMENTS.get('ndk', 0):
    current_dir = os.getcwd()#os.path.dirname(os.path.abspath(__file__))
    os.environ["NDK_PROJECT_PATH"] = current_dir + '/android-project'
    os.system("ndk-build") # use V=1 if can't compile for android
    exit(0)

if ARGUMENTS.get('ant', 0):
    current_dir = os.getcwd()#os.path.dirname(os.path.abspath(__file__))
    android_prj_path = current_dir + '/android-project'
    os.chdir(android_prj_path)
    os.system("ant debug") # use V=1 if can't compile for android
    exit(0)

VariantDir('obj', 'src', duplicate = 0)

if sys.platform == 'win32':
    if ARGUMENTS.get('msvc', 0) == "1":
        env = Environment(ENV = {'PATH' : os.environ['PATH'], \
            'INCLUDE' : 'c:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\include\\', \
            'LIB' : 'c:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\lib\\'})
    else:
        env = Environment(tools = ['mingw'])
        env.Append(CCFLAGS = '-U__STRICT_ANSI__') # for boost::program_options on mingw 4.7
        env.Append(LINKFLAGS = '-mwindows')
        env.Append(LIBS = ['mingw32', 'SDL2', 'SDL2main', 'm', 'user32', 'gdi32', \
                    'winmm', 'imm32', 'ole32', 'oleaut32', 'version', \
                    'uuid', 'glew32', 'opengl32'])
else:
    env = Environment()
    env.Append(CCFLAGS = '-rdynamic')
    env.Append(LIBS = ['SDL2', 'pthread', 'm', 'dl', 'GL'])

env.Append(CCFLAGS = '-fno-strict-aliasing') # for angelscript compile see doc
cur_dir = os.getcwd()
env.Append(CCFLAGS = '-I ' + cur_dir) # for boost find in include path
env.Append(CCFLAGS = '-g -std=c++0x -Wall -Wfatal-errors') #-msse2 -pg
env.Append(LINKFLAGS=[]) # -pg

src = Glob('obj/*.cpp')
src += Glob('obj/scene2d/*.cpp')
src += Glob('obj/pugixml/*.cpp')
src += Glob('obj/debug_support/*.cpp')
src += Glob('obj/angelscript/*.cpp')
src += Glob('obj/scriptarray/*.cpp')
src += Glob('obj/scriptstdstring/*.cpp')
src += Glob('obj/scriptbuilder/*.cpp')
src += Glob('obj/boost_libs_src/program_options/src/*.cpp')
src += Glob('obj/boost_libs_src/smart_ptr/src/*.cpp')
src += Glob('obj/boost_libs_src/system/src/*.cpp')
src += Glob('obj/boost_libs_src/filesystem/src/*.cpp')
src += Glob('obj/libwebp/*/*.c')
src += Glob('obj/zlib/*.c')
src += Glob('obj/libpng/*.c')

env.Program(target = 'start', source = src)

Solution

  • Best way to use scons and MSVC is:

    env = Environment( MSVC_USE_SCRIPT = "c:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\bin\\vcvars32.bat")