我正在编写一个PowerShell脚本,该脚本应该使用CMake为Fortran项目创建Ninja Build:
Set-PSDebug -Trace 1
#MOVE TO load_modules
$env:CC="C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2018.1.156/windows/bin/intel64/icl.exe"
$env:CXX="C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2018.1.156/windows/bin/intel64/icl.exe"
#$env:FC="C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2018.1.156/windows/bin/intel64/ifort.exe"
$env:Path+=";C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.11.25503\bin\Hostx86\x86\"
$env:Path+=";C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.11.25503\bin\Hostx64\x64\"
$env:Path+=";C:\Program Files (x86)\Windows Kits\10\bin\10.0.16299.0\x86\"
$env:Path+=";C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.1.156\windows\bin\intel64\"
#$env:Path+=";C:\Windows\System32\kernel32.dll"
& 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\vsdevcmd'
$env:Path+=";C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\SDK\ScopeCppSDK\SDK\lib\kernel32.Lib"
echo $env:Path
# Install
mkdir build
mkdir install
pushd build
Start-Process $env:CMAKE -ArgumentList "-G ""Ninja""
-DCMAKE_Fortran_COMPILER=""C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2018.1.156/windows/bin/intel64/ifort.exe""
-DCMAKE_INSTALL_PREFIX=../install ../src" -NoNewWindow
然而,CMake无法成功编译C测试程序,因为找不到'kernel32.lib':
...
PS C:\Users\fnick\modflow> -- The C compiler identification is Intel
18.0.1.20171018
-- The CXX compiler identification is Intel 18.0.1.20171018
-- The Fortran compiler identification is unknown
-- Check for working C compiler: C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2018.1.156/windows/bin/inte l64/icl.exe
-- Check for working C compiler: C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2018.1.156/windows/bin/inte l64/icl.exe -- broken CMake Error at C:/Program Files/CMake/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message): The C compiler
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2018.1.156/windows/bin/intel64/icl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/fnick/modflow/build/CMakeFiles/CMakeTmp
Run Build Command:"C:/Users/fnick/ninja.exe" "cmTC_27e84"
[1/2] Building C object CMakeFiles\cmTC_27e84.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTC_27e84.exe
FAILED: cmTC_27e84.exe
cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_27e84.dir --manif ests -- xilink /nologo CMakeFiles\cmTC_27e84.dir\testCCompiler.c.obj /out:cmTC_27e84.exe /implib:cmTC_27e84.lib /pdb:c mTC_27e84.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib wins pool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK Pass 1: command "xilink /nologo CMakeFiles\cmTC_27e84.dir\testCCompiler.c.obj /out:cmTC_27e84.exe /implib:cmTC_ 27e84.lib /pdb:cmTC_27e84.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib g di32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMak eFiles\cmTC_27e84.dir/intermediate.manifest CMakeFiles\cmTC_27e84.dir/manifest.res" failed (exit code 1104) with the fol lowing output:
LINK : fatal error LNK1104: Datei "kernel32.lib" kann nicht ge├Àffnet werden.
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:34 (project)
...
Datei“kernel32.lib”kannnichtge├Àffnetwerden。
表示“文件”kernel32.lib“无法打开”。我假设这意味着无法找到它。
我没有得到多件事:我想到了
&安培; 'C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Professional \ Common7 \ Tools \ vsdevcmd'
基本上会为我设置环境?! 而且,我将PATH直接指向了必要的库:
$ env:Path + =“; C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Professional \ SDK \ ScopeCppSDK \ SDK \ lib \ kernel32.Lib”
但这没有帮助(我尝试没有明确的kernel32.Lib - 没有帮助;为什么有资本'L'?!)
从我看来,看起来Linux环境变量PATH和LD_LIBRARY_PATH都对应于Windows上的PATH?!
我在这里缺少什么?在PowerShell中设置工作构建环境的最佳方法是什么?
修改: 致电
&安培; 'C:\ Program Files(x86)\ IntelSWTools \ compilers_and_libraries_2018 \ windows \ bin \ compilervars.bat'intel64
也没有帮助。
EDIT2 :
Windows版本是“Windows Server 2012 R2 Standard”64位
编译器:英特尔编译器2018 Update 1
CMake版本3.10-rc3
更新: 一位同事给了我以下脚本:
function StartVSNativeCommandPromt($VSVersion, $VSName, $ArchName, $VSKind, $Options)
{
if(($VSVersion -Eq "12.0") -Or ($VSVersion -Eq "14.0"))
{
$dir = "c:\Program Files (x86)\Microsoft Visual Studio $VSVersion\VC"
}
else
{
$dir = "C:\Program Files (x86)\Microsoft Visual Studio\$VSName\$VSKind\VC\Auxiliary\Build"
}
pushd $dir
cmd.exe /c "vcvarsall.bat $Options $ArchName&set" |
foreach {
if ($_ -match "=") {
$v = $_.split("="); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])"
}
}
popd
write-host "`nVisual Studio $VSName Command Prompt variables set." -ForegroundColor Yellow
}
function StartIntelNativeCommandPromt($IntelVersion, $Arch, $VSVersion)
{
Invoke-BatchFile "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_$IntelVersion\windows\bin\compilervars.bat" $Arch $VSVersion
}
function StartVS12x64NativeCommandPromt { StartVSNativeCommandPromt "12.0" "2013" "amd64"}
function StartVS12x86NativeCommandPromt { StartVSNativeCommandPromt "12.0" "2013" "x86"}
function StartVS14x64NativeCommandPromt { StartVSNativeCommandPromt "14.0" "2015" "amd64"}
function StartVS14x86NativeCommandPromt { StartVSNativeCommandPromt "14.0" "2015" "x86"}
function StartVS15x64NativeCommandPromt { StartVSNativeCommandPromt "15.0" "2017" "amd64" "Professional"}
function StartVS15x86NativeCommandPromt { StartVSNativeCommandPromt "15.0" "2017" "x86" "Professional"}
function StartVS15x64140NativeCommandPromt { StartVSNativeCommandPromt "15.0" "2017" "amd64" "Professional" "-vcvars_ver=14.0"}
function StartVS15x86140NativeCommandPromt { StartVSNativeCommandPromt "15.0" "2017" "x86" "Professional" "-vcvars_ver=14.0"}
function StartIntel17VS15x64NativeCommandPromt {
if (-not (Test-Path env:VS2017INSTALLDIR)) { $env:VS2017INSTALLDIR = $env:VSINSTALLDIR }
StartIntelNativeCommandPromt "2017.5.267" "intel64" "vs2017"
}
function StartIntel18VS15x64NativeCommandPromt {
if (-not (Test-Path env:VS2017INSTALLDIR)) { $env:VS2017INSTALLDIR = $env:VSINSTALLDIR }
StartIntelNativeCommandPromt "2018.1.156" "intel64" "vs2017"
}
Set-Alias vs12x64 StartVS12x64NativeCommandPromt
Set-Alias vs12x86 StartVS12x86NativeCommandPromt
Set-Alias vs14x64 StartVS14x64NativeCommandPromt
Set-Alias vs14x86 StartVS14x86NativeCommandPromt
Set-Alias vs15x64 StartVS15x64NativeCommandPromt
Set-Alias vs15x86 StartVS15x86NativeCommandPromt
Set-Alias vs15x64v14 StartVS15x64140NativeCommandPromt
Set-Alias vs15x86v14 StartVS15x86140NativeCommandPromt
Set-Alias intel17x64vs15 StartIntel17VS15x64NativeCommandPromt
Set-Alias intel18x64vs15 StartIntel18VS15x64NativeCommandPromt
允许他通过调用“vs15x64”在PowerShell中设置工作环境。如果我在我的脚本中包含它,则会找到kernel32.lib,但是在同一步骤中,找不到libmmdd.lib。所以旅程继续......