I'm writing a PowerShell script that is supposed to use CMake to create a Ninja Build for a Fortran project:
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
However, CMake cannot sucessfully compile a C test program because 'kernel32.lib' cannot be found:
...
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" kann nicht ge├Àffnet werden.
means "File "kernel32.lib" cannot be opened". I'm assuming this means it could not be found.
Multiple things I don't get here: I thought that
& 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\vsdevcmd'
would basically set up the environment for me?! And also, I pointed the PATH directly to the necessary library:
$env:Path+=";C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\SDK\ScopeCppSDK\SDK\lib\kernel32.Lib"
but that didn't help (I tried without the explicit kernel32.Lib - didn't help; and why is there a capital 'L'?!)
From what I read, it looks like the Linux environment variables PATH and LD_LIBRARY_PATH both correspond to PATH on Windows?!
What am I missing here? What's the best way to set up a working build environment in PowerShell?
EDIT: Calling
& 'C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018\windows\bin\compilervars.bat' intel64
Also doesn't help.
EDIT2:
Windows Version is "Windows Server 2012 R2 Standard" 64bit
Compilers: Intel Compilers 2018 Update 1
CMake version 3.10-rc3
Update: A colleague gave me the following script:
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
which allows him to set up a working environment in PowerShell by calling "vs15x64". If I include that in my script, kernel32.lib is found, however then in the same step, libmmdd.lib isn't found. So the journey continues...