mirror of
https://gitlab.com/ita1024/waf.git
synced 2024-11-22 01:46:15 +01:00
Add a simple example for using Clang as a cross compiler for MSVC
This commit is contained in:
parent
6154a8de60
commit
1581e221b4
14
playground/clang_cross/msvc/ReadMe.txt
Normal file
14
playground/clang_cross/msvc/ReadMe.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
To cross compile for Windows in MSVC mode from Linux, you will require the following:
|
||||||
|
* A partition with Windows installed (NTFS).
|
||||||
|
* Visual Studio (Tested with 2017).
|
||||||
|
* The Windows SDK.
|
||||||
|
* lowntfs-3g file system driver.
|
||||||
|
|
||||||
|
Make sure the Windows partition is mounted with "-t lowntfs-3g -o defaults,ignore_case,windows_names".
|
||||||
|
This will allow Clang to find all headers and libraries referenced by scripts and headers, otherwise you will run into case sensitivity errors.
|
||||||
|
|
||||||
|
Clang uses the following environment variables to detect the Visual Studio install: VCINSTALLDIR, VCToolsInstallDir, INCLUDE, LIB, LIBPATH
|
||||||
|
I just copied these from the output of the "set" command in an MSVC command prompt on Windows and translated the paths to Linux paths.
|
||||||
|
Notice how the semicolon is still used as a path separator.
|
||||||
|
See "example_environment_linux.sh" for how my setup looks like.
|
||||||
|
It expects the Windows partition to be mounted on /mnt/windows, with VS2017 installed and Windows 10 SDK 10.0.17763.0.
|
5
playground/clang_cross/msvc/example_environment_linux.sh
Normal file
5
playground/clang_cross/msvc/example_environment_linux.sh
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export VCINSTALLDIR="/mnt/windows/program files (x86)/microsoft visual studio/2017/community/vc/"
|
||||||
|
export VCToolsInstallDir="/mnt/windows/program files (x86)/microsoft visual studio/2017/community/vc/tools/msvc/14.16.27023/"
|
||||||
|
export INCLUDE="/mnt/windows/program files (x86)/microsoft visual studio/2017/community/vc/tools/msvc/14.16.27023/atlmfc/include;/mnt/windows/program files (x86)/microsoft visual studio/2017/community/vc/tools/msvc/14.16.27023/include;/mnt/windows/program files (x86)/windows kits/10/include/10.0.17763.0/ucrt;/mnt/windows/program files (x86)/windows kits/10/include/10.0.17763.0/shared;/mnt/windows/program files (x86)/windows kits/10/include/10.0.17763.0/um;/mnt/windows/program files (x86)/windows kits/10/include/10.0.17763.0/winrt;/mnt/windows/program files (x86)/windows kits/10/include/10.0.17763.0/cppwinrt"
|
||||||
|
export LIB="/mnt/windows/program files (x86)/microsoft visual studio/2017/community/vc/tools/msvc/14.16.27023/atlmfc/lib/x64;/mnt/windows/program files (x86)/microsoft visual studio/2017/community/vc/tools/msvc/14.16.27023/lib/x64;/mnt/windows/program files (x86)/windows kits/10/lib/10.0.17763.0/ucrt/x64;/mnt/windows/program files (x86)/windows kits/10/lib/10.0.17763.0/um/x64"
|
||||||
|
export LIBPATH="/mnt/windows/program files (x86)/microsoft visual studio/2017/community/vc/tools/msvc/14.16.27023/atlmfc/lib/x64;/mnt/windows/program files (x86)/microsoft visual studio/2017/community/vc/tools/msvc/14.16.27023/lib/x64;/mnt/windows/program files (x86)/microsoft visual studio/2017/community/vc/tools/msvc/14.16.27023/lib/x86/store/references;/mnt/windows/program files (x86)/windows kits/10/unionmetadata/10.0.17763.0;/mnt/windows/program files (x86)/windows kits/10/references/10.0.17763.0"
|
11
playground/clang_cross/msvc/hello.c
Normal file
11
playground/clang_cross/msvc/hello.c
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
(void)argc;
|
||||||
|
(void)argv;
|
||||||
|
|
||||||
|
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), "Hello world!\n", 13, NULL, NULL);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
32
playground/clang_cross/msvc/wscript
Normal file
32
playground/clang_cross/msvc/wscript
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#! /usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
# DragoonX6 2019
|
||||||
|
|
||||||
|
# the following two variables are used by the target "waf dist"
|
||||||
|
VERSION='0.0.1'
|
||||||
|
APPNAME='hello_msvc'
|
||||||
|
|
||||||
|
top = '.'
|
||||||
|
|
||||||
|
from waflib.Configure import conf, ConfigurationContext
|
||||||
|
from waflib.Options import OptionsContext
|
||||||
|
|
||||||
|
def options(opt):
|
||||||
|
opt.load('clang_cross')
|
||||||
|
|
||||||
|
def configure(conf):
|
||||||
|
conf.load('clang_cross')
|
||||||
|
|
||||||
|
if not conf.env.implib_PATTERN == '%s.lib':
|
||||||
|
conf.fatal('''clang is not configured to compile in msvc mode.
|
||||||
|
Use flag '--clang-target-triple=x86_64-windows-msvc' to configure.
|
||||||
|
On Windows you're likely to require running from an MSVC command prompt.
|
||||||
|
On Linux you will need to have access to a Windows partition with VS installed, and the environment set up properly.
|
||||||
|
See the ReadMe for more information.''')
|
||||||
|
|
||||||
|
conf.env.append_value('CFLAGS', conf.env.CFLAGS_CRT_MULTITHREADED_DLL)
|
||||||
|
|
||||||
|
def build(bld):
|
||||||
|
bld.program(
|
||||||
|
source = 'hello.c',
|
||||||
|
target = 'hello_msvc')
|
Loading…
Reference in New Issue
Block a user