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...
Related
Trying to install Boost as static library, so I can include it in my binary to not need to install it on system. But it seems to failed of this error below:
Run cmake . -G "Visual Studio 16 2019" -B build -DSTATIC=true
-DDO_TESTS=OFF -DCMAKE_C_FLAGS="-fassociative-math" -DCMAKE_CXX_FLAGS="-fassociative-math" -DCMAKE_BUILD_TYPE=Release -DBOOST_ROOT=C:\boost_1_74_0\boost_1_74_0
-- The C compiler identification is MSVC 19.29.30147.0
-- The CXX compiler identification is MSVC 19.29.30147.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe
- skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe
- skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE CMake Warning (dev) at CMakeLists.txt:43 (set): implicitly converting 'TYPE' to 'STRING' type.
-- FORCE_USE_HEAP: ENABLED This warning is for project developers. Use -Wno-dev to suppress it.
-- HW AES: ENABLED
-- OPTIMIZED_ARM_MULTIPLICATION: ENABLED
-- Found Git: C:/Program Files/Git/bin/git.exe CMake Error at C:/Program Files/CMake/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find Boost (missing: system filesystem thread date_time chrono regex serialization program_options) (found version "1.74.0") Call Stack (most recent call first): C:/Program Files/CMake/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE) C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2376 (find_package_handle_standard_args) CMakeLists.txt:270 (find_package)
-- Configuring incomplete, errors occurred! See also "D:/a/kryptokrona/kryptokrona/build/CMakeFiles/CMakeOutput.log". See also "D:/a/kryptokrona/kryptokrona/build/CMakeFiles/CMakeError.log". Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework Copyright (C) Microsoft Corporation. All rights reserved.
MSBUILD : error MSB1009: Project file does not exist. Switch: ALL_BUILD.vcxproj Error: Process completed with exit code 1.
So this is how I set it up in CMake:
# Go get us some static BOOST libraries
set(Boost_NO_BOOST_CMAKE ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
# Checker if we build on GitHub Actions and building for Visual C++
if(DEFINED ENV{CI} AND MSVC)
set(Boost_USE_STATIC_RUNTIME ON)
set(Boost_NO_SYSTEM_PATHS ON)
else()
set(Boost_USE_STATIC_RUNTIME ON) # ON was before
endif()
In GitHub workflow:
# install dependencies
- name: Install Windows 2019 Dependencies
if: matrix.config.os == 'windows-2019'
uses: microsoft/setup-msbuild#v1.1
with:
msbuild-architecture: x64
- name: Install Windows Boost
if: matrix.config.os == 'windows-2019'
run: |
Invoke-WebRequest -Uri https://boostorg.jfrog.io/artifactory/main/release/1.74.0/source/boost_1_74_0.zip -OutFile C:\boost_1_74_0.zip
Expand-Archive C:\boost_1_74_0.zip -DestinationPath C:\boost_1_74_0
Set-Location C:\boost_1_74_0\boost_1_74_0\tools\build
C:\boost_1_74_0\boost_1_74_0\tools\build\bootstrap.bat
.\b2 toolset=msvc variant=release optimization=space threading=multi link=static address-model=64 install
- name: Build Windows 2019
if: matrix.config.os == 'windows-2019'
run: |
cmake . -G "Visual Studio 16 2019" -B build -DSTATIC=true -DDO_TESTS=OFF -DCMAKE_C_FLAGS="-fassociative-math" -DCMAKE_CXX_FLAGS="-fassociative-math" -DCMAKE_BUILD_TYPE=Release -DBOOST_ROOT=C:\boost_1_74_0\boost_1_74_0
cmake --build ./build --config Release
How can I make this work to load Boost so it loads Boosts? It works on macOS and Ubuntu since I install them system wide first. But then compile it as static.
After passing debug options on for Boost this is the output:
- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1689 ] _boost_TEST_VERSIONS = "1.80.0;1.80;1.79.0;1.79;1.78.0;1.78;1.77.0;1.77;1.76.0;1.76;1.75.0;1.75;1.74.0;1.74;1.73.0;1.73;1.72.0;1.72;1.71.0;1.71;1.70.0;1.70;1.69.0;1.69;1.68.0;1.68;1.67.0;1.67;1.66.0;1.66;1.65.1;1.65.0;1.65;1.64.0;1.64;1.63.0;1.63;1.62.0;1.62;1.61.0;1.61;1.60.0;1.60;1.59.0;1.59;1.58.0;1.58;1.57.0;1.57;1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53;1.52.0;1.52;1.51.0;1.51;1.50.0;1.50;1.49.0;1.49;1.48.0;1.48;1.47.0;1.47;1.46.1;1.46.0;1.46;1.45.0;1.45;1.44.0;1.44;1.43.0;1.43;1.42.0;1.42;1.41.0;1.41;1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1690 ] Boost_USE_MULTITHREADED = "ON"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1691 ] Boost_USE_STATIC_LIBS = "ON"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1692 ] Boost_USE_STATIC_RUNTIME = "ON"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1693 ] Boost_ADDITIONAL_VERSIONS = <unset>
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1694 ] Boost_NO_SYSTEM_PATHS = "ON"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1726 ] BOOST_ROOT = "C:\boost_1_74_0\boost_1_74_0"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1727 ] ENV{BOOST_ROOT} = <unset>
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1728 ] BOOST_INCLUDEDIR = <unset>
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1729 ] ENV{BOOST_INCLUDEDIR} = <unset>
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1730 ] BOOST_LIBRARYDIR = <unset>
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1731 ] ENV{BOOST_LIBRARYDIR} = <unset>
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1803 ] _boost_INCLUDE_SEARCH_DIRS = "C:\boost_1_74_0\boost_1_74_0/include;C:\boost_1_74_0\boost_1_74_0;NO_CMAKE_SYSTEM_PATH;NO_SYSTEM_ENVIRONMENT_PATH"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1804 ] _boost_PATH_SUFFIXES = "boost-1_80_0;boost_1_80_0;boost/boost-1_80_0;boost/boost_1_80_0;boost-1_80;boost_1_80;boost/boost-1_80;boost/boost_1_80;boost-1_79_0;boost_1_79_0;boost/boost-1_79_0;boost/boost_1_79_0;boost-1_79;boost_1_79;boost/boost-1_79;boost/boost_1_79;boost-1_78_0;boost_1_78_0;boost/boost-1_78_0;boost/boost_1_78_0;boost-1_78;boost_1_78;boost/boost-1_78;boost/boost_1_78;boost-1_77_0;boost_1_77_0;boost/boost-1_77_0;boost/boost_1_77_0;boost-1_77;boost_1_77;boost/boost-1_77;boost/boost_1_77;boost-1_76_0;boost_1_76_0;boost/boost-1_76_0;boost/boost_1_76_0;boost-1_76;boost_1_76;boost/boost-1_76;boost/boost_1_76;boost-1_75_0;boost_1_75_0;boost/boost-1_75_0;boost/boost_1_75_0;boost-1_75;boost_1_75;boost/boost-1_75;boost/boost_1_75;boost-1_74_0;boost_1_74_0;boost/boost-1_74_0;boost/boost_1_74_0;boost-1_74;boost_1_74;boost/boost-1_74;boost/boost_1_74;boost-1_73_0;boost_1_73_0;boost/boost-1_73_0;boost/boost_1_73_0;boost-1_73;boost_1_7...
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1819 ] location of version.hpp: C:/boost_1_74_0/boost_1_74_0/boost/version.hpp
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1859 ] Boost_VERSION = "107400"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1860 ] Boost_VERSION_STRING = "1.74.0"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1861 ] Boost_VERSION_MACRO = "107400"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1862 ] Boost_VERSION_MAJOR = "1"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1863 ] Boost_VERSION_MINOR = "74"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1864 ] Boost_VERSION_PATCH = "0"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1865 ] Boost_VERSION_COUNT = "3"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1889 ] Boost_LIB_PREFIX = "lib"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1890 ] Boost_NAMESPACE = "boost"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:953 ] _boost_COMPILER = "-vc142;-vc141;-vc140" (guessed)
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:1926 ] _boost_MULTITHREADED = "-mt"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2004 ] _boost_ARCHITECTURE_TAG = "-x64" (detected)
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2008 ] _boost_RELEASE_ABI_TAG = "-s"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2009 ] _boost_DEBUG_ABI_TAG = "-sgd"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2069 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = "C:\boost_1_74_0\boost_1_74_0/lib;C:\boost_1_74_0\boost_1_74_0/stage/lib;C:\boost_1_74_0\boost_1_74_0/lib64-msvc-14.2;C:\boost_1_74_0\boost_1_74_0/lib64-msvc-14.1;C:\boost_1_74_0\boost_1_74_0/lib64-msvc-14.0;C:/boost_1_74_0/boost_1_74_0/lib;C:/boost_1_74_0/boost_1_74_0/../lib;C:/boost_1_74_0/boost_1_74_0/stage/lib;C:/boost_1_74_0/boost_1_74_0/../lib64-msvc-14.2;C:/boost_1_74_0/boost_1_74_0/../lib64-msvc-14.1;C:/boost_1_74_0/boost_1_74_0/../lib64-msvc-14.0;C:/boost_1_74_0/boost_1_74_0/lib64-msvc-14.2;C:/boost_1_74_0/boost_1_74_0/lib64-msvc-14.1;C:/boost_1_74_0/boost_1_74_0/lib64-msvc-14.0;NO_CMAKE_SYSTEM_PATH;NO_SYSTEM_ENVIRONMENT_PATH"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2070 ] _boost_LIBRARY_SEARCH_DIRS_DEBUG = "C:\boost_1_74_0\boost_1_74_0/lib;C:\boost_1_74_0\boost_1_74_0/stage/lib;C:\boost_1_74_0\boost_1_74_0/lib64-msvc-14.2;C:\boost_1_74_0\boost_1_74_0/lib64-msvc-14.1;C:\boost_1_74_0\boost_1_74_0/lib64-msvc-14.0;C:/boost_1_74_0/boost_1_74_0/lib;C:/boost_1_74_0/boost_1_74_0/../lib;C:/boost_1_74_0/boost_1_74_0/stage/lib;C:/boost_1_74_0/boost_1_74_0/../lib64-msvc-14.2;C:/boost_1_74_0/boost_1_74_0/../lib64-msvc-14.1;C:/boost_1_74_0/boost_1_74_0/../lib64-msvc-14.0;C:/boost_1_74_0/boost_1_74_0/lib64-msvc-14.2;C:/boost_1_74_0/boost_1_74_0/lib64-msvc-14.1;C:/boost_1_74_0/boost_1_74_0/lib64-msvc-14.0;NO_CMAKE_SYSTEM_PATH;NO_SYSTEM_ENVIRONMENT_PATH"
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2255 ] Searching for SYSTEM_LIBRARY_RELEASE: libboost_system-vc142-mt-s-x64-1_74;libboost_system-vc142-mt-s-x64;libboost_system-vc142-mt-s;libboost_system-vc141-mt-s-x64-1_74;libboost_system-vc141-mt-s-x64;libboost_system-vc141-mt-s;libboost_system-vc140-mt-s-x64-1_74;libboost_system-vc140-mt-s-x64;libboost_system-vc140-mt-s;libboost_system-mt-s-x64-1_74;libboost_system-mt-s-x64;libboost_system-mt-s;libboost_system-mt;libboost_system
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2310 ] Searching for SYSTEM_LIBRARY_DEBUG: libboost_system-vc142-mt-sgd-x64-1_74;libboost_system-vc142-mt-sgd-x64;libboost_system-vc142-mt-sgd;libboost_system-vc141-mt-sgd-x64-1_74;libboost_system-vc141-mt-sgd-x64;libboost_system-vc141-mt-sgd;libboost_system-vc140-mt-sgd-x64-1_74;libboost_system-vc140-mt-sgd-x64;libboost_system-vc140-mt-sgd;libboost_system-mt-sgd-x64-1_74;libboost_system-mt-sgd-x64;libboost_system-mt-sgd;libboost_system-mt;libboost_system
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2255 ] Searching for FILESYSTEM_LIBRARY_RELEASE: libboost_filesystem-vc142-mt-s-x64-1_74;libboost_filesystem-vc142-mt-s-x64;libboost_filesystem-vc142-mt-s;libboost_filesystem-vc141-mt-s-x64-1_74;libboost_filesystem-vc141-mt-s-x64;libboost_filesystem-vc141-mt-s;libboost_filesystem-vc140-mt-s-x64-1_74;libboost_filesystem-vc140-mt-s-x64;libboost_filesystem-vc140-mt-s;libboost_filesystem-mt-s-x64-1_74;libboost_filesystem-mt-s-x64;libboost_filesystem-mt-s;libboost_filesystem-mt;libboost_filesystem
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2310 ] Searching for FILESYSTEM_LIBRARY_DEBUG: libboost_filesystem-vc142-mt-sgd-x64-1_74;libboost_filesystem-vc142-mt-sgd-x64;libboost_filesystem-vc142-mt-sgd;libboost_filesystem-vc141-mt-sgd-x64-1_74;libboost_filesystem-vc141-mt-sgd-x64;libboost_filesystem-vc141-mt-sgd;libboost_filesystem-vc140-mt-sgd-x64-1_74;libboost_filesystem-vc140-mt-sgd-x64;libboost_filesystem-vc140-mt-sgd;libboost_filesystem-mt-sgd-x64-1_74;libboost_filesystem-mt-sgd-x64;libboost_filesystem-mt-sgd;libboost_filesystem-mt;libboost_filesystem
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2255 ] Searching for THREAD_LIBRARY_RELEASE: libboost_thread-vc142-mt-s-x64-1_74;libboost_thread-vc142-mt-s-x64;libboost_thread-vc142-mt-s;libboost_thread-vc141-mt-s-x64-1_74;libboost_thread-vc141-mt-s-x64;libboost_thread-vc141-mt-s;libboost_thread-vc140-mt-s-x64-1_74;libboost_thread-vc140-mt-s-x64;libboost_thread-vc140-mt-s;libboost_thread-mt-s-x64-1_74;libboost_thread-mt-s-x64;libboost_thread-mt-s;libboost_thread-mt;libboost_thread
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2310 ] Searching for THREAD_LIBRARY_DEBUG: libboost_thread-vc142-mt-sgd-x64-1_74;libboost_thread-vc142-mt-sgd-x64;libboost_thread-vc142-mt-sgd;libboost_thread-vc141-mt-sgd-x64-1_74;libboost_thread-vc141-mt-sgd-x64;libboost_thread-vc141-mt-sgd;libboost_thread-vc140-mt-sgd-x64-1_74;libboost_thread-vc140-mt-sgd-x64;libboost_thread-vc140-mt-sgd;libboost_thread-mt-sgd-x64-1_74;libboost_thread-mt-sgd-x64;libboost_thread-mt-sgd;libboost_thread-mt;libboost_thread
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2255 ] Searching for DATE_TIME_LIBRARY_RELEASE: libboost_date_time-vc142-mt-s-x64-1_74;libboost_date_time-vc142-mt-s-x64;libboost_date_time-vc142-mt-s;libboost_date_time-vc141-mt-s-x64-1_74;libboost_date_time-vc141-mt-s-x64;libboost_date_time-vc141-mt-s;libboost_date_time-vc140-mt-s-x64-1_74;libboost_date_time-vc140-mt-s-x64;libboost_date_time-vc140-mt-s;libboost_date_time-mt-s-x64-1_74;libboost_date_time-mt-s-x64;libboost_date_time-mt-s;libboost_date_time-mt;libboost_date_time
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2310 ] Searching for DATE_TIME_LIBRARY_DEBUG: libboost_date_time-vc142-mt-sgd-x64-1_74;libboost_date_time-vc142-mt-sgd-x64;libboost_date_time-vc142-mt-sgd;libboost_date_time-vc141-mt-sgd-x64-1_74;libboost_date_time-vc141-mt-sgd-x64;libboost_date_time-vc141-mt-sgd;libboost_date_time-vc140-mt-sgd-x64-1_74;libboost_date_time-vc140-mt-sgd-x64;libboost_date_time-vc140-mt-sgd;libboost_date_time-mt-sgd-x64-1_74;libboost_date_time-mt-sgd-x64;libboost_date_time-mt-sgd;libboost_date_time-mt;libboost_date_time
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2255 ] Searching for CHRONO_LIBRARY_RELEASE: libboost_chrono-vc142-mt-s-x64-1_74;libboost_chrono-vc142-mt-s-x64;libboost_chrono-vc142-mt-s;libboost_chrono-vc141-mt-s-x64-1_74;libboost_chrono-vc141-mt-s-x64;libboost_chrono-vc141-mt-s;libboost_chrono-vc140-mt-s-x64-1_74;libboost_chrono-vc140-mt-s-x64;libboost_chrono-vc140-mt-s;libboost_chrono-mt-s-x64-1_74;libboost_chrono-mt-s-x64;libboost_chrono-mt-s;libboost_chrono-mt;libboost_chrono
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2310 ] Searching for CHRONO_LIBRARY_DEBUG: libboost_chrono-vc142-mt-sgd-x64-1_74;libboost_chrono-vc142-mt-sgd-x64;libboost_chrono-vc142-mt-sgd;libboost_chrono-vc141-mt-sgd-x64-1_74;libboost_chrono-vc141-mt-sgd-x64;libboost_chrono-vc141-mt-sgd;libboost_chrono-vc140-mt-sgd-x64-1_74;libboost_chrono-vc140-mt-sgd-x64;libboost_chrono-vc140-mt-sgd;libboost_chrono-mt-sgd-x64-1_74;libboost_chrono-mt-sgd-x64;libboost_chrono-mt-sgd;libboost_chrono-mt;libboost_chrono
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2255 ] Searching for REGEX_LIBRARY_RELEASE: libboost_regex-vc142-mt-s-x64-1_74;libboost_regex-vc142-mt-s-x64;libboost_regex-vc142-mt-s;libboost_regex-vc141-mt-s-x64-1_74;libboost_regex-vc141-mt-s-x64;libboost_regex-vc141-mt-s;libboost_regex-vc140-mt-s-x64-1_74;libboost_regex-vc140-mt-s-x64;libboost_regex-vc140-mt-s;libboost_regex-mt-s-x64-1_74;libboost_regex-mt-s-x64;libboost_regex-mt-s;libboost_regex-mt;libboost_regex
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2310 ] Searching for REGEX_LIBRARY_DEBUG: libboost_regex-vc142-mt-sgd-x64-1_74;libboost_regex-vc142-mt-sgd-x64;libboost_regex-vc142-mt-sgd;libboost_regex-vc141-mt-sgd-x64-1_74;libboost_regex-vc141-mt-sgd-x64;libboost_regex-vc141-mt-sgd;libboost_regex-vc140-mt-sgd-x64-1_74;libboost_regex-vc140-mt-sgd-x64;libboost_regex-vc140-mt-sgd;libboost_regex-mt-sgd-x64-1_74;libboost_regex-mt-sgd-x64;libboost_regex-mt-sgd;libboost_regex-mt;libboost_regex
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2255 ] Searching for SERIALIZATION_LIBRARY_RELEASE: libboost_serialization-vc142-mt-s-x64-1_74;libboost_serialization-vc142-mt-s-x64;libboost_serialization-vc142-mt-s;libboost_serialization-vc141-mt-s-x64-1_74;libboost_serialization-vc141-mt-s-x64;libboost_serialization-vc141-mt-s;libboost_serialization-vc140-mt-s-x64-1_74;libboost_serialization-vc140-mt-s-x64;libboost_serialization-vc140-mt-s;libboost_serialization-mt-s-x64-1_74;libboost_serialization-mt-s-x64;libboost_serialization-mt-s;libboost_serialization-mt;libboost_serialization
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2310 ] Searching for SERIALIZATION_LIBRARY_DEBUG: libboost_serialization-vc142-mt-sgd-x64-1_74;libboost_serialization-vc142-mt-sgd-x64;libboost_serialization-vc142-mt-sgd;libboost_serialization-vc141-mt-sgd-x64-1_74;libboost_serialization-vc141-mt-sgd-x64;libboost_serialization-vc141-mt-sgd;libboost_serialization-vc140-mt-sgd-x64-1_74;libboost_serialization-vc140-mt-sgd-x64;libboost_serialization-vc140-mt-sgd;libboost_serialization-mt-sgd-x64-1_74;libboost_serialization-mt-sgd-x64;libboost_serialization-mt-sgd;libboost_serialization-mt;libboost_serialization
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2255 ] Searching for PROGRAM_OPTIONS_LIBRARY_RELEASE: libboost_program_options-vc142-mt-s-x64-1_74;libboost_program_options-vc142-mt-s-x64;libboost_program_options-vc142-mt-s;libboost_program_options-vc141-mt-s-x64-1_74;libboost_program_options-vc141-mt-s-x64;libboost_program_options-vc141-mt-s;libboost_program_options-vc140-mt-s-x64-1_74;libboost_program_options-vc140-mt-s-x64;libboost_program_options-vc140-mt-s;libboost_program_options-mt-s-x64-1_74;libboost_program_options-mt-s-x64;libboost_program_options-mt-s;libboost_program_options-mt;libboost_program_options
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2310 ] Searching for PROGRAM_OPTIONS_LIBRARY_DEBUG: libboost_program_options-vc142-mt-sgd-x64-1_74;libboost_program_options-vc142-mt-sgd-x64;libboost_program_options-vc142-mt-sgd;libboost_program_options-vc141-mt-sgd-x64-1_74;libboost_program_options-vc141-mt-sgd-x64;libboost_program_options-vc141-mt-sgd;libboost_program_options-vc140-mt-sgd-x64-1_74;libboost_program_options-vc140-mt-sgd-x64;libboost_program_options-vc140-mt-sgd;libboost_program_options-mt-sgd-x64-1_74;libboost_program_options-mt-sgd-x64;libboost_program_options-mt-sgd;libboost_program_options-mt;libboost_program_options
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2255 ] Searching for ATOMIC_LIBRARY_RELEASE: libboost_atomic-vc142-mt-s-x64-1_74;libboost_atomic-vc142-mt-s-x64;libboost_atomic-vc142-mt-s;libboost_atomic-vc141-mt-s-x64-1_74;libboost_atomic-vc141-mt-s-x64;libboost_atomic-vc141-mt-s;libboost_atomic-vc140-mt-s-x64-1_74;libboost_atomic-vc140-mt-s-x64;libboost_atomic-vc140-mt-s;libboost_atomic-mt-s-x64-1_74;libboost_atomic-mt-s-x64;libboost_atomic-mt-s;libboost_atomic-mt;libboost_atomic
-- [ C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2310 ] Searching for ATOMIC_LIBRARY_DEBUG: libboost_atomic-vc142-mt-sgd-x64-1_74;libboost_atomic-vc142-mt-sgd-x64;libboost_atomic-vc142-mt-sgd;libboost_atomic-vc141-mt-sgd-x64-1_74;libboost_atomic-vc141-mt-sgd-x64;libboost_atomic-vc141-mt-sgd;libboost_atomic-vc140-mt-sgd-x64-1_74;libboost_atomic-vc140-mt-sgd-x64;libboost_atomic-vc140-mt-sgd;libboost_atomic-mt-sgd-x64-1_74;libboost_atomic-mt-sgd-x64;libboost_atomic-mt-sgd;libboost_atomic-mt;libboost_atomic
CMake Error at C:/Program Files/CMake/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Boost (missing: system filesystem thread date_time chrono
regex serialization program_options) (found version "1.74.0")
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
-- Configuring incomplete, errors occurred!
C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2376 (find_package_handle_standard_args)
See also "D:/a/kryptokrona/kryptokrona/build/CMakeFiles/CMakeOutput.log".
CMakeLists.txt:270 (find_package)
See also "D:/a/kryptokrona/kryptokrona/build/CMakeFiles/CMakeError.log".
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
MSBUILD : error MSB1009: Project file does not exist.
Switch: ALL_BUILD.vcxproj
Error: Process completed with exit code 1.
I'm trying to make a Rust program that statically links against libusb, using the MSVC toolchain, but it blows up at run-time from a missing DLL:
error: process didn't exit successfully: `target\debug\test_libusb.exe` (exit code: 0xc0000135, STATUS_DLL_NOT_FOUND)
I used Dependency Walker to find that the missing DLL is LIBUSB-1.0.DLL. Adding it to the project solves the problem and so does dynamically linking everything, but I would like to avoid this solution.
My starting point was this libusb-sys crate, but since it didn't work I made a simpler similar crate. I got libusb from vcpkg.
libusb-sys/src/lib.rs
extern crate libc;
use libc::c_char;
#[repr(C)]
pub struct libusb_version {
pub major: u16,
pub minor: u16,
pub micro: u16,
pub nano: u16,
pub rc: *const c_char,
pub describe: *const c_char,
}
#[link(name = "libusb-1.0", kind = "static")]
extern "C" {
pub fn libusb_get_version() -> *const libusb_version;
}
libusb-sys/Cargo.toml
[package]
name = "libusb-sys"
version = "0.1.0"
build = "build.rs"
link = "libusb-1.0"
[dependencies]
libc = "0.2"
libusb-sys/build.rs
fn main() {
println!("
cargo:rustc-link-lib=static=libusb-1.0
cargo:rustc-link-search=native=C:/vcpkg/packages/libusb_x64-windows/lib")
}
Then I used this on my program's crate:
test_libusb/src/main.rs
extern crate libusb_sys as ffi;
fn main() {
unsafe {
let version = ffi::libusb_get_version();
println!(
"libusb v{}.{}.{}.{}",
(*version).major,
(*version).minor,
(*version).micro,
(*version).nano
);
}
}
test_libusb/Cargo.toml
[package]
name = "test_libusb"
version = "0.1.0"
[dependencies]
"libusb-sys" = { path = "../libusb-sys" }
Here's the entire compiler output, in case it's helpful:
G:\programming\rust\test_libusb> cargo run --verbose
Compiling libc v0.2.58
Compiling libusb-sys v0.1.0 (G:\programming\rust\libusb-sys)
Running `rustc --crate-name build_script_build C:\Users\slysherz\.cargo\registry\src\github.com-1ecc6299db9ec823\libc-0.2.58\build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg "feature=\"default\"" --cfg "feature=\"std\"" -C metadata=f83941a94611be11 -C extra-filename=-f83941a94611be11 --out-dir G:\programming\rust\test_libusb\target\debug\build\libc-f83941a94611be11 -L dependency=G:\programming\rust\test_libusb\target\debug\deps --cap-lints allow`
Running `rustc --crate-name build_script_build G:\programming\rust\libusb-sys\build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=71e53c2aee584c72 -C extra-filename=-71e53c2aee584c72 --out-dir G:\programming\rust\test_libusb\target\debug\build\libusb-sys-71e53c2aee584c72 -C incremental=G:\programming\rust\test_libusb\target\debug\incremental -L dependency=G:\programming\rust\test_libusb\target\debug\deps`
Running `G:\programming\rust\test_libusb\target\debug\build\libusb-sys-71e53c2aee584c72\build-script-build`
Running `G:\programming\rust\test_libusb\target\debug\build\libc-f83941a94611be11\build-script-build`
Running `rustc --crate-name libc C:\Users\slysherz\.cargo\registry\src\github.com-1ecc6299db9ec823\libc-0.2.58\src\lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg "feature=\"default\"" --cfg "feature=\"std\"" -C metadata=b67580e06366e753 -C extra-filename=-b67580e06366e753 --out-dir G:\programming\rust\test_libusb\target\debug\deps -L dependency=G:\programming\rust\test_libusb\target\debug\deps --cap-lints allow --cfg libc_priv_mod_use --cfg libc_union --cfg libc_const_size_of --cfg libc_align --cfg libc_core_cvoid --cfg libc_packedN`
Running `rustc --crate-name libusb_sys G:\programming\rust\libusb-sys\src\lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=94e8ef72b03c18f5 -C extra-filename=-94e8ef72b03c18f5 --out-dir G:\programming\rust\test_libusb\target\debug\deps -C incremental=G:\programming\rust\test_libusb\target\debug\incremental -L dependency=G:\programming\rust\test_libusb\target\debug\deps --extern libc=G:\programming\rust\test_libusb\target\debug\deps\liblibc-b67580e06366e753.rlib -L native=C:/vcpkg/packages/libusb_x64-windows/lib -l static=libusb-1.0`
Compiling test_libusb v0.1.0 (G:\programming\rust\test_libusb)
Running `rustc --crate-name test_libusb src\main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=8f2bb1a8f56e2223 -C extra-filename=-8f2bb1a8f56e2223 --out-dir G:\programming\rust\test_libusb\target\debug\deps -C incremental=G:\programming\rust\test_libusb\target\debug\incremental -L dependency=G:\programming\rust\test_libusb\target\debug\deps --extern libusb_sys=G:\programming\rust\test_libusb\target\debug\deps\liblibusb_sys-94e8ef72b03c18f5.rlib -L native=C:/vcpkg/packages/libusb_x64-windows/lib`
Finished dev [unoptimized + debuginfo] target(s) in 1.20s
Running `target\debug\test_libusb.exe`
error: process didn't exit successfully: `target\debug\test_libusb.exe` (exit code: 0xc0000135, STATUS_DLL_NOT_FOUND)
Even after compiling libusb from scratch with VS 2017 I still get a link error:
= note: test_libusb-528eb6acc7e5c681.3w5rrhap2r2yw5if.rcgu.o : error LNK2019: unresolved external symbol libusb_get_version referenced in function _ZN11test_libusb4main17hcb0c36db62706c3bE
G:\programming\rust\test_libusb\target\debug\deps\test_libusb-528eb6acc7e5c681.exe : fatal error LNK1120: 1 unresolved externals
When I call this function directly from the first crate it works though.
I've started to learn Rust recently, so I'm not sure about how any of this works. Why does Rust try to load a DLL in this situation?
#Shepmaster was right, the libusb:x64-windows triplet for vcpkg only contains definitions that try to call the real functions from the DLL.
I tried to load this library from a simple C program and I got the exact same error:
test.c
#include "C:\vcpkg\installed\x64-windows\include\libusb-1.0\libusb.h"
int main()
{
const struct libusb_version *version = libusb_get_version();
printf("Version %d.%d.%d", version->major, version->minor, version->micro);
}
compiled with:
cl test.c /link C:\vcpkg\installed\x64-windows\lib\libusb-1.0.lib
results in the same missing DLL error. But if I do with with the different libusb:x64-windows-static triplet:
test.c
#pragma comment(lib, "Advapi32.lib")
#include "C:\vcpkg\installed\x64-windows-static\include\libusb-1.0\libusb.h"
int main()
{
const struct libusb_version *version = libusb_get_version();
printf("Version %d.%d.%d", version->major, version->minor, version->micro);
}
compiled with:
cl test.c /link C:\vcpkg\installed\x64-windows-static\lib\libusb-1.0.lib
works just fine:
>test.exe
Version 1.0.22
To sum it up, if you want to statically link a Rust program against libusb, download vspkg and install
vcpkg.exe install libusb:x64-windows-static.
Set an environment variable LIBUSB_DIR that points to C:\vcpkg\installed\x64-windows-static and use the patched version of libusb-sys by putting this in your
Cargo.toml:
[dependencies]
libusb = "0.3"
libusb-sys = "0.2.3"
[patch.crates-io]
"libusb-sys" = { git = "https://github.com/cmsd2/libusb-sys" }
I want to link libzmq with my Rust program. I have this in ~\.cargo\config:
[target.x86_64-pc-windows-gnu.chainsaw]
rustc-link-search = ["C:\\Program Files\\ZeroMQ 4.0.4\\bin"]
Running cargo test results in this error:
Compiling chainsaw v0.0.1 (file:///D:/chainsaw)
error: linking with `gcc` failed: exit code: 1
|
= note: "gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-m64" "C:\\Rust
\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\crt2.o" "C:\\Rust\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsbegin.o" "-L"
"C:\\Rust\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "D:\\chainsaw\\target\\debug\\deps\\chainsaw-0154e16e13da8295.0.o"
"-o" "D:\\chainsaw\\target\\debug\\deps\\chainsaw-0154e16e13da8295.exe" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "D:\\
chainsaw\\target\\debug\\deps" "-L" "C:\\Rust\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-Wl,-Bstatic" "-Wl,-Bdynamic"
"-l" "zmq" "D:\\chainsaw\\target\\debug\\deps\\liblibc-29ef97a68464c2b7.rlib" "C:\\Rust\\lib\\rustlib\\x86_64-pc-windows
-gnu\\lib\\libtest-f5a209a9.rlib" "C:\\Rust\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libterm-f5a209a9.rlib" "C:\\Rust\
\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libgetopts-f5a209a9.rlib" "C:\\Rust\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib
\\libstd-f5a209a9.rlib" "C:\\Rust\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libpanic_unwind-f5a209a9.rlib" "C:\\Rust\\l
ib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libunwind-f5a209a9.rlib" "C:\\Rust\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\l
ibrand-f5a209a9.rlib" "C:\\Rust\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcollections-f5a209a9.rlib" "C:\\Rust\\lib\
\rustlib\\x86_64-pc-windows-gnu\\lib\\librustc_unicode-f5a209a9.rlib" "C:\\Rust\\lib\\rustlib\\x86_64-pc-windows-gnu\\li
b\\liblibc-f5a209a9.rlib" "C:\\Rust\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\liballoc-f5a209a9.rlib" "C:\\Rust\\lib\\r
ustlib\\x86_64-pc-windows-gnu\\lib\\liballoc_system-f5a209a9.rlib" "C:\\Rust\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\
libcore-f5a209a9.rlib" "C:\\Rust\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\libcompiler_builtins-f5a209a9.rlib" "-l" "ke
rnel32" "-l" "ws2_32" "-l" "userenv" "-l" "shell32" "-l" "advapi32" "-l" "gcc_eh" "-lmingwex" "-lmingw32" "-lgcc" "-lmsv
crt" "-luser32" "-lkernel32" "C:\\Rust\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsend.o"
= note: ld: cannot find -lzmq
As you can see, -L "C:\Program Files\ZeroMQ 4.0.4\bin" is not being passed to the linker.
Why does setting rustc-link-search in the Cargo config file not work?
I have already checked these things:
Cargo actually reads the config file
The directory exists
x86_64-pc-windows-gnu is my target triple
"chainsaw" is the name of my target
The same error occurs when doing a clean build
I'm trying to setup Mingw-w64 as the mex compiler in MATLAB 2013a. My laptop has x86_64 architecture and runs windows 7. The program I want to compile uses c++11-style threading, so I'm using mingw-w64 version 4.9.0 with posix threads.
According to instruction I found here and here, I modified my mexopts.bat file. The code seems to compile successfully, but the linker reports an error. Does anyone have suggestions what I might be doing wrong?
By the way, I tried using gnumex to setup the compiler, but that didn't work either.
Here's the output and error message that MATLAB gives:
>mex -v Gomoku_mex.cpp
-> Default options filename found in C:\Users\Bas\AppData\Roaming\MathWorks\MATLAB\R2013a
-> Options file = C:\Users\Bas\AppData\Roaming\MathWorks\MATLAB\R2013a\mexopts.bat
MATLAB = C:\Program Files\MATLAB\R2013a
-> COMPILER = x86_64-w64-mingw32-g++
-> Compiler flags:
COMPFLAGS = -std=c++11 -fexceptions -I"C:\Program Files\MATLAB\R2013a\extern\include"
OPTIMFLAGS = -O3 -fexpensive-optimizations -DNDEBUG
DEBUGFLAGS = -g -Wall -Wextra
arguments =
Name switch = -o
-> Pre-linking commands=
-> LINKER = x86_64-w64-mingw32-g++
-> Link directives:
LINKFLAGS = -shared mex.def -L"C:\Program Files\MATLAB\R2013a\bin\win64" -static-libstdc++
LINKDEBUGFLAGS = -g -Wall
LINKFLAGSPOST = -lmex -lmx -lmat -lmwlapack -lmwblas
Name directive = -o "Gomoku_mex.mexw64"
File link directive =
Lib. link directive =
Rsp file indicator =
-> Resource Compiler =
-> Resource Linker =
----------------------------------------------------------------
--> x86_64-w64-mingw32-g++ -std=c++11 -fexceptions -I"C:\Program Files\MATLAB\R2013a\extern\include" -oC:\Users\Bas\AppData\Local\Temp\mex_r7jRw0\Gomoku_mex.obj -I"C:\Program Files\MATLAB\R2013a\extern\include" -I"C:\Program Files\MATLAB\R2013a\simulink\include" -O3 -fexpensive-optimizations -DNDEBUG -DMX_COMPAT_32 Gomoku_mex.cpp
C:\Users\Bas\AppData\Local\Temp\cc4hwD3A.o:Gomoku_mex.cpp:(.text+0x9d1c): undefined reference to `mxGetPr'
C:\Users\Bas\AppData\Local\Temp\cc4hwD3A.o:Gomoku_mex.cpp:(.text+0x9d83): undefined reference to `mxCreateDoubleScalar'
C:/PROGRA~1/mingw-w64/x86_64-4.9.0-posix-seh-rt_v3-rev2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Bas\AppData\Local\Temp\cc4hwD3A.o: bad reloc address 0x0 in section `.pdata$_ZNKSt5ctypeIcE8do_widenEc'
collect2.exe: error: ld returned 1 exit status
C:\PROGRA~1\MATLAB\R2013A\BIN\MEX.PL: Error: Compile of 'Gomoku_mex.cpp' failed.
Error using mex (line 206)
Unable to complete successfully.
Edit: As extra information, this is my mexopts.bat file. I got this directly from one of the two links above and modified directory & compiler names and added -std=c++11
set MATLAB=%MATLAB%
set PATH=%PATH%;C:\PROGRA~1\mingw-w64\x86_64-4.9.0-posix-seh-rt_v3-rev2\mingw64\bin
set MW_TARGET_ARCH=win64
rem ********************************************************************
rem Compiler parameters
rem ********************************************************************
set COMPILER=x86_64-w64-mingw32-g++
set COMPFLAGS=-std=c++11 -fexceptions -I"%MATLAB%\extern\include"
set OPTIMFLAGS=-O3 -fexpensive-optimizations -DNDEBUG
set DEBUGFLAGS=-g -Wall -Wextra
set NAME_OBJECT=-o
rem ********************************************************************
rem Linker parameters
rem ********************************************************************
set PRELINK_CMDS1=echo EXPORTS > mex.def & echo mexFunction >> mex.def
set LINKER=x86_64-w64-mingw32-g++
set LINKFLAGS= -static-libstdc++ -shared mex.def -L"%MATLAB%\bin\win64" -L"%MATLAB%\extern\lib\win64\microsoft"
set LINKFLAGSPOST= -lmex -lmx -lmat -lmwlapack -lmwblas
set LINKOPTIMFLAGS=-O3
set LINKDEBUGFLAGS= -g -Wall
set LINK_FILE=
set LINK_LIB=
set NAME_OUTPUT=-o "%OUTDIR%%MEX_NAME%%MEX_EXT%"
set RSP_FILE_INDICATOR=
set POSTLINK_CMDS1=del mex.def
Take the following configuration file that I'm using (you'll need to adjust the path pointing to MinGW-w64 location accordingly):
mingw_mexopts.bat
#echo off
set MATLAB=%MATLAB%
set MW_TARGET_ARCH=win64
set PATH=C:\MinGW-w64\mingw64\bin;%PATH%
set COMPILER=x86_64-w64-mingw32-g++
set COMPFLAGS=-c -m64 -mwin32 -mdll -Wall -std=c++11 -DMATLAB_MEX_FILE
set OPTIMFLAGS=-DNDEBUG -O2
set DEBUGFLAGS=-g
set NAME_OBJECT=-o
set LINKER=x86_64-w64-mingw32-g++
set LINKFLAGS=-shared -L"%MATLAB%\extern\lib\win64\microsoft" -L"%MATLAB%\bin\win64"
set LINKFLAGSPOST=-lmx -lmex -lmat
set LINKOPTIMFLAGS=-O2
set LINKDEBUGFLAGS=-g
set LINK_FILE=
set LINK_LIB=
set NAME_OUTPUT=-o "%OUTDIR%%MEX_NAME%%MEX_EXT%"
Next here is a simple MEX-function that uses C++11 threads:
test.cpp
#include "mex.h"
#include <vector>
#include <thread>
void say_hello(int tid) {
mexPrintf("hello from %d\n", tid);
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
std::vector<std::thread> threads;
for (int i=0; i<10; i++) {
threads.push_back(std::thread(say_hello, i));
}
for(auto& t : threads) {
t.join();
}
}
Finally we compile and run it in MATLAB:
>> mex -f mingw_mexopts.bat -largeArrayDims test.cpp
>> setenv('PATH', ['C:\MinGW-w64\mingw64\bin;', getenv('PATH')])
>> test
hello from 0
hello from 4
hello from 2
hello from 3
hello from 5
hello from 1
hello from 6
hello from 8
hello from 7
hello from 9
Note that if you're going to deploy this to another machine, you'll have to also copy a few dependent DLL's (you'll find them in MinGW bin folder), and place them next to the MEX-file. Use Dependency Walker to list them. In my case it was:
libstdc++-6.dll
libgcc_s_seh-1.dll
libwinpthread-1.dll
I am using GCC 4.8.2 with MATLAB R2014a running on 64-bit Windows.
Note these error messages:
C:\Users\Bas\AppData\Local\Temp\cc4hwD3A.o:Gomoku_mex.cpp:(.text+0x9d1c): undefined reference to `mxGetPr'
C:\Users\Bas\AppData\Local\Temp\cc4hwD3A.o:Gomoku_mex.cpp:(.text+0x9d83): undefined reference to `mxCreateDoubleScalar'
The library search path for libmex, libmx, libmat, ... is not added in your link command. The directory in your script is the bin directory containing DLLs. That's not correct here.
LINKFLAGS = -shared mex.def -L"C:\Program Files\MATLAB\R2013a\extern\lib\win64\microsoft" -static-libstdc++
I am having a issue where nmake is not linking the boost library cmake is providing. I am not exactly sure why it is doing this.
cmake_minimum_required(VERSION 2.8)
project(BoostLibTest)
set(Boost_USE_STATIC_LIBS TRUE)
set(Boost_MULTITHREADED TRUE)
set(Boost_DEBUG TRUE)
find_package(Boost COMPONENTS regex)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
add_executable(Example example.cpp)
target_link_libraries(Example ${Boost_LIBRARIES})
CMake output:
-- Building for: NMake Makefiles
-- The C compiler identification is MSVC
-- The CXX compiler identification is MSVC
-- Check for CL compiler version
-- Check for CL compiler version - 1500
-- Check if this is a free VC compiler
-- Check if this is a free VC compiler - no
-- Check CL platform
-- Check CL platform - 64 bit
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/amd64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/amd64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/amd64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:362 ] Boost not in cache
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:365 ] _boost_TEST_VERSIONS = 1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:367 ] Boost_USE_MULTITHREADED = TRUE
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:369 ] Boost_USE_STATIC_LIBS = TRUE
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:428 ] Declared as CMake or Environmental Variables:
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:430 ] BOOST_ROOT =
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:432 ] BOOST_INCLUDEDIR =
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:434 ] BOOST_LIBRARYDIR =
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:436 ] _boost_TEST_VERSIONS = 1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:485 ] Include debugging info:
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:487 ] _boost_INCLUDE_SEARCH_DIRS = C:/boost/include;C:/boost;C:\Program Files (x86)/boost/include;C:\Program Files (x86)/boost;/sw/local/include
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:489 ] _boost_PATH_SUFFIXES = boost-1_40_0;boost_1_40_0;boost-1_40;boost_1_40;boost-1_39_0;boost_1_39_0;boost-1_39;boost_1_39;boost-1_38_0;boost_1_38_0;boost-1_38;boost_1_38;boost-1_37_0;boost_1_37_0;boost-1_37;boost_1_37;boost-1_36_1;boost_1_36_1;boost-1_36_0;boost_1_36_0;boost-1_36;boost_1_36;boost-1_35_1;boost_1_35_1;boost-1_35_0;boost_1_35_0;boost-1_35;boost_1_35;boost-1_34_1;boost_1_34_1;boost-1_34_0;boost_1_34_0;boost-1_34;boost_1_34;boost-1_33_1;boost_1_33_1;boost-1_33_0;boost_1_33_0;boost-1_33;boost_1_33
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:513 ] location of version.hpp: C:/Program Files (x86)/boost/boost_1_40/boost/version.hpp
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:532 ] version.hpp reveals boost 1.40.0
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:623 ] guessed _boost_COMPILER = -vc90
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:633 ] _boost_MULTITHREADED = -mt
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:650 ] _boost_STATIC_TAG = -s
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:652 ] _boost_ABI_TAG = gd
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:685 ] _boost_LIBRARIES_SEARCH_DIRS = C:/Program Files (x86)/boost/boost_1_40/lib;C:/Program Files (x86)/boost/boost_1_40/../lib;C:/boost/lib;C:/boost;C:\Program Files (x86)/boost/boost_1_40_0/lib;C:\Program Files (x86)/boost/boost_1_40/lib;C:\Program Files (x86)/boost/lib;C:\Program Files (x86)/boost;/sw/local/lib
-- [ C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:814 ] Boost_FOUND = TRUE
-- Boost version: 1.40.0
-- Found the following Boost libraries:
-- regex
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/blewisjr/Documents/BoostLibTest/bin
NMake output:
Scanning dependencies of target Example
[100%] Building CXX object CMakeFiles/Example.dir/example.cpp.obj
example.cpp
Linking CXX executable Example.exe
example.cpp.obj : error LNK2019: unresolved external symbol "private: class boost::basic_regex > > & __cdecl boost::basic_regex > >::do_assign(char const *,char const *,unsigned int)" (?do_assign#?$basic_regex#DU?$regex_traits#DV?$w32_regex_traits#D#boost###boost###boost##AEAAAEAV12#PEBD0I#Z) referenced in function "public: class boost::basic_regex > > & __cdecl boost::basic_regex > >::assign(char const *,char const *,unsigned int)" (?assign#?$basic_regex#DU?$regex_traits#DV?$w32_regex_traits#D#boost###boost###boost##QEAAAEAV12#PEBD0I#Z)
example.cpp.obj : error LNK2019: unresolved external symbol "public: bool __cdecl boost::re_detail::perl_matcher,class std::allocator >,class std::allocator,class std::allocator > > >,struct boost::regex_traits > >::match(void)" (?match#?$perl_matcher#V?$_String_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#U?$sub_match#V?$_String_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std###boost###2#U?$regex_traits#DV?$w32_regex_traits#D#boost###boost###re_detail#boost##QEAA_NXZ) referenced in function "bool __cdecl boost::regex_match,class std::allocator >,class std::allocator,class std::allocator > > >,char,struct boost::regex_traits > >(class std::_String_const_iterator,class std::allocator >,class std::_String_const_iterator,class std::allocator >,class boost::match_results,class std::allocator >,class std::allocator,class std::allocator > > > > &,class boost::basic_regex > > const &,enum boost::regex_constants::_match_flags)" (??$regex_match#V?$_String_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#U?$sub_match#V?$_String_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std###boost###2#DU?$regex_traits#DV?$w32_regex_traits#D#boost###boost###boost##YA_NV?$_String_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std##0AEAV?$match_results#V?$_String_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#U?$sub_match#V?$_String_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std###boost###2##0#AEBV?$basic_regex#DU?$regex_traits#DV?$w32_regex_traits#D#boost###boost###0#W4_match_flags#regex_constants#0##Z)
example.cpp.obj : error LNK2019: unresolved external symbol "private: void __cdecl boost::re_detail::perl_matcher,class std::allocator >,class std::allocator,class std::allocator > > >,struct boost::regex_traits > >::construct_init(class boost::basic_regex > > const &,enum boost::regex_constants::_match_flags)" (?construct_init#?$perl_matcher#V?$_String_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#U?$sub_match#V?$_String_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std###boost###2#U?$regex_traits#DV?$w32_regex_traits#D#boost###boost###re_detail#boost##AEAAXAEBV?$basic_regex#DU?$regex_traits#DV?$w32_regex_traits#D#boost###boost###3#W4_match_flags#regex_constants#3##Z) referenced in function "public: __cdecl boost::re_detail::perl_matcher,class std::allocator >,class std::allocator,class std::allocator > > >,struct boost::regex_traits > >::perl_matcher,class std::allocator >,class std::allocator,class std::allocator > > >,struct boost::regex_traits > >(class std::_String_const_iterator,class std::allocator >,class std::_String_const_iterator,class std::allocator >,class boost::match_results,class std::allocator >,class std::allocator,class std::allocator > > > > &,class boost::basic_regex > > const &,enum boost::regex_constants::_match_flags,class std::_String_const_iterator,class std::allocator >)" (??0?$perl_matcher#V?$_String_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#U?$sub_match#V?$_String_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std###boost###2#U?$regex_traits#DV?$w32_regex_traits#D#boost###boost###re_detail#boost##QEAA#V?$_String_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std##0AEAV?$match_results#V?$_String_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#U?$sub_match#V?$_String_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std###boost###2##2#AEBV?$basic_regex#DU?$regex_traits#DV?$w32_regex_traits#D#boost###boost###2#W4_match_flags#regex_constants#2#0#Z)
Example.exe : fatal error LNK1120: 3 unresolved externals
LINK Pass 1 failed. with 2
After the failed link NMake is throwing fatal error U1077
Turns out I was targeting x64 with boost libs only built for x86 issues solved by switching compiler to x86