英文:
SCons uses Visual Studio flags with Clang
问题
我尝试在Windows上使用SCons和Clang。当我这样做时,SCons尝试使用Visual Studio标志与Clang。
运行scons -n
时,我得到:
我想要的是在Windows和Linux上运行的这些命令:
我的构建脚本:
英文:
I'm trying to use SCons with Clang on Windows. When I do SCons attempts to use Visual Studio flags with Clang.
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
clang++ /Fomain.obj /c main.cc -static /nologo /Iinclude
clang++: error: no such file or directory: '/Fomain.obj'
clang++: error: no such file or directory: '/c'
clang++: error: no such file or directory: '/nologo'
clang++: error: no such file or directory: '/Iinclude'
clang++: error: unable to make temporary file: no such file or directory
scons: *** [main.obj] Error 1
scons: building terminated because of errors.
Running scons -n
I get:
clang++ /Fomain.obj /c main.cc -static /nologo /Iinclude
link /OUT:test.exe /LIBPATH:lib main.obj
What I want are these commands which work on Windows and Linux:
clang++ -o main.o -c -static -Iinclude main.cc
clang++ -o test main.o -Llib
My build script:
import os
from os.path import join, dirname
import shutil
LIBS=[]
LIBPATH=['./lib']
CXXFLAGS='-static'
LINKFLAGS = ''
env = Environment(
CC='clang',
CXX='clang++',
CPPPATH=['./include'],
ENV = {'PATH' : os.environ['PATH']},
LIBS=LIBS,
LIBPATH=LIBPATH,
CXXFLAGS=CXXFLAGS,
LINKFLAGS=LINKFLAGS
)
source = ['main.cc']
env.Program('test', source)
答案1
得分: 2
Visual Studio 是 Windows 中首选的工具链。SCons 默认选择它,除非另有说明。
变量 CC
和 CXX
不能覆盖这一选择。它们只会改变在构建命令中调用的可执行文件。其他所有设置仍然配置为 Visual Studio。
你正在寻找的是 SCons 中的一个 "工具"。
它们是特定工具的完整配置,可以加载到 SCons 中。
如果你没有定义自己的工具列表,将加载默认列表,其中包括 SCons 选择的 C++ 编译器。
要更改此设置,而不是使用 CC
和 CXX
,请将一个名为 TOOLS
的变量传递给创建的环境,并列出使用 Clang 需要的所有工具(['clang', 'clang++', 'gnulink']
):
import os
from os.path import join, dirname
import shutil
LIBS=[]
LIBPATH=['./lib']
CXXFLAGS='-static'
LINKFLAGS = ''
env = Environment(
TOOLS=['clang', 'clang++', 'gnulink'],
CPPPATH=['./include'],
ENV = {'PATH' : os.environ['PATH']},
LIBS=LIBS,
LIBPATH=LIBPATH,
CXXFLAGS=CXXFLAGS,
LINKFLAGS=LINKFLAGS
)
source = ['main.cc']
env.Program('test', source)
这将设置不仅可执行文件名称,还包括选项的格式等其他所有内容。
请注意,在此更改之后,如果在计算机上找不到 Clang,构建脚本将失败。它不会默认使用 Visual Studio。
英文:
Visual Studio is the preferred toolchain in Windows. SCons chooses it by default unless told otherwise.
Variables CC
and CXX
do not override that. They only change the executables that will be called in the build commands. Every other setting is still configured for Visual Studio.
What you're looking for is called a "tool" in SCons.
They are complete configurations for specific tools that can be loaded into SCons.
If you not define your own list of tools, a default one is loaded, which includes the C++ compiler chosen by SCons.
To change this setting, istead of CC
and CXX
, pass a variable TOOLS
to the created environment, with the list of all tools required to use Clang (['clang', 'clang++', 'gnulink']
):
import os
from os.path import join, dirname
import shutil
LIBS=[]
LIBPATH=['./lib']
CXXFLAGS='-static'
LINKFLAGS = ''
env = Environment(
TOOLS=['clang', 'clang++', 'gnulink'],
CPPPATH=['./include'],
ENV = {'PATH' : os.environ['PATH']},
LIBS=LIBS,
LIBPATH=LIBPATH,
CXXFLAGS=CXXFLAGS,
LINKFLAGS=LINKFLAGS
)
source = ['main.cc']
env.Program('test', source)
This will set not only executable names but also everything else, like the format of options.
Be aware that after this change the build script will fail if there is no Clang found on the machine. It won't default to Visual Studio.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论