Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error compiling cxx.cc on Windows #1349

Open
ClayCore opened this issue May 16, 2024 · 1 comment
Open

Error compiling cxx.cc on Windows #1349

ClayCore opened this issue May 16, 2024 · 1 comment

Comments

@ClayCore
Copy link

My project uses CMake and corrosion-rs for C++ and Rust interopt. I've got an executable written in C++ and a Rust cdylib library.

The Rust library contains the following:

// src/lib.rs
#[cxx::bridge]
mod ffi {
    extern "Rust" {
        fn greet();
    }
}

pub fn greet() {
    println!("Hello from Rust!")
}
// build.rs
fn main() {
    let _build = cxx_build::bridge("src/lib.rs");

    println!("cargo:rerun-if-changed=src/lib.rs")
}

I'm adding the library as a target via corrosion-rs and linking it with the executable as follows:

CPMAddPackage(
  NAME corrosion
  VERSION 0.5
  GITHUB_REPOSITORY
  "corrosion-rs/corrosion"
)

corrosion_import_crate(
  MANIFEST_PATH
  ${CMAKE_SOURCE_DIR}/lib/Cargo.toml
)

target_link_libraries(fileDiffCLI PUBLIC lib)

The C++ code isn't even trying to call that greet function yet, because the entire setup is failing during building of the Rust library.

When I run the configure step I get the following log, with --log-level=Debug

$ cmake -S . -B build -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -Ddev_WARNINGS_AS_ERRORS=OFF --log-level=DEBUG

-- CPM: Adding package [email protected] (v0.5)
-- Using Corrosion 0.5.0 with CMake 3.27.4 and the `Ninja` Generator
-- Rust Toolchain: stable-x86_64-pc-windows-msvc
-- Rust toolchain stable-x86_64-pc-windows-msvc
-- Rust toolchain path Q:\Users\Claymore\.rustup\toolchains\stable-x86_64-pc-windows-msvc
-- Rust Target: x86_64-pc-windows-msvc
-- Parsed Target triple: arch: x86_64, vendor: pc, OS: windows, env: msvc
-- Parsed Target triple: arch: x86_64, vendor: pc, OS: windows, env: msvc
-- Cargo target x86_64-pc-windows-msvc is an official target-triple
-- Installed targets: wasm32-unknown-unknown;x86_64-pc-windows-msvc
-- Using Corrosion as a subdirectory
-- Found 2 targets in package lib
-- TARGET lib produces byproducts lib.dll.lib;lib.dll;lib.pdb
-- Corrosion created the following CMake targets: lib
--  * trying to find and to run 'vcvarsall.bat'...
--  * S:/msys64/opt/bin/ccache.exe found and enabled
--  * setting clang-tidy globally...
-- Output directory property (target lib): LIBRARY_OUTPUT_DIRECTORY dir: output_directory-NOTFOUND
-- Setting IMPORTED_LOCATION for target lib-shared to `S:/wplace/cpp/FileDiffMain/build/lib.dll`.
-- Output directory property (target lib): ARCHIVE_OUTPUT_DIRECTORY dir: output_directory-NOTFOUND
-- Setting IMPORTED_IMPLIB for target lib-shared to `S:/wplace/cpp/FileDiffMain/build/lib.dll.lib`.
-- Adding command to copy byproducts `lib.dll.lib` to S:/wplace/cpp/FileDiffMain/build/lib.dll.lib
-- Adding command to copy byproducts `lib.dll` to S:/wplace/cpp/FileDiffMain/build/lib.dll
-- Adding command to copy byproducts `lib.pdb` to S:/wplace/cpp/FileDiffMain/build/lib.pdb
-- Configuring done (4.5s)
-- Generating done (0.0s)
-- Build files have been written to: S:/wplace/cpp/FileDiffMain/build

So far so good, some of these *-NOTFOUND are a bit worrysome, but it's probably me not setting ARCHIVE_OUTPUT_DIRECTORY explicitly for the target pulled by corrosion

Running cmake --build build --config Debug --verbose reveals a lot of errors related to the standard not being C++14 or above, but not for the user code (since i'm not trying to use C++ code in Rust) and instead of the cxx.cc

$ cmake --build build --config Debug --verbose

Change Dir: 'S:/wplace/cpp/FileDiffMain/build'

Run Build Command(s): S:/wplace/sdk/Python/Python310/Scripts/ninja.exe -v
[0/6] cmd.exe /C "cd /D S:\wplace\cpp\FileDiffMain\lib && "E:\Program Files\CMake\bin\cmake.exe" -E env CC_x86_64_pc_windows_msvc=S:/wplace/sdk/compilers/clang/bin/clang.exe CXX_x86_64_pc_windows_msvc=S:/wplace/sdk/compilers/clang/bin/clang++.exe CORROSION_BUILD_DIR=S:/wplace/cpp/FileDiffMain/build CARGO_BUILD_RUSTC=Q:/Users/Claymore/.rustup/toolchains/stable-x86_64-pc-windows-msvc/bin/rustc.exe Q:/Users/Claymore/.rustup/toolchains/stable-x86_64-pc-windows-msvc/bin/cargo.exe rustc --lib --target=x86_64-pc-w   Compiling cxx v1.0.122
The following warnings were emitted during compilation:

warning: [email protected]: In file included from Q:\Users\Claymore\.cargo\registry\src\index.crates.io-6f17d22bba15001f\cxx-1.0.122\src/cxx.cc:1:
warning: [email protected]: In file included from Q:\Users\Claymore\.cargo\registry\src\index.crates.io-6f17d22bba15001f\cxx-1.0.122\src\../include/cxx.h:2:
warning: [email protected]: In file included from E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\algorithm:10:
warning: [email protected]: In file included from E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xmemory:15:
warning: [email protected]: In file included from E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:11:
warning: [email protected]: In file included from E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\__msvc_iter_core.hpp:10:
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\utility:162:22: error: 'auto' return without trailing return type; deduced return types are a C++14 extension
warning: [email protected]:   162 | _NODISCARD constexpr auto&& _Tuple_get(tuple<_Types...>&& _Tuple) noexcept;
warning: [email protected]:       |                      ^
warning: [email protected]: In file included from Q:\Users\Claymore\.cargo\registry\src\index.crates.io-6f17d22bba15001f\cxx-1.0.122\src/cxx.cc:1:
warning: [email protected]: In file included from Q:\Users\Claymore\.cargo\registry\src\index.crates.io-6f17d22bba15001f\cxx-1.0.122\src\../include/cxx.h:2:
warning: [email protected]: In file included from E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\algorithm:10:
warning: [email protected]: In file included from E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xmemory:15:
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:546:15: error: deduced return types are a C++14 extension
warning: [email protected]:   546 |     constexpr decltype(auto) operator()(_Args&&... _Vals) noexcept(
warning: [email protected]:       |               ^
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:559:22: error: 'auto' return without trailing return type; deduced return types are a C++14 extension
warning: [email protected]:   559 | _NODISCARD constexpr auto _Pass_fn(_Fn& _Func) noexcept {
warning: [email protected]:       |                      ^
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1162:16: error: constexpr function's return type 'void' is not a literal type
warning: [email protected]:  1162 | constexpr void _Adl_verify_range(const _Iter& _First, const _Sentinel& _Last) {
warning: [email protected]:       |                ^
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1184:22: error: deduced return types are a C++14 extension
warning: [email protected]:  1184 | _NODISCARD constexpr decltype(auto) _Get_unwrapped(_Iter&& _It) noexcept(
warning: [email protected]:       |                      ^
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1212:22: error: deduced return types are a C++14 extension
warning: [email protected]:  1212 | _NODISCARD constexpr decltype(auto) _Get_unwrapped_unverified(_Iter&& _It) {
warning: [email protected]:       |                      ^
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1251:22: error: deduced return types are a C++14 extension
warning: [email protected]:  1251 | _NODISCARD constexpr decltype(auto) _Get_unwrapped_n(_Iter&& _It, const _Diff _Off) {
warning: [email protected]:       |                      ^
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1285:16: error: constexpr function's return type 'void' is not a literal type
warning: [email protected]:  1285 | constexpr void _Seek_wrapped(_Iter& _It, _UIter&& _UIt) {
warning: [email protected]:       |                ^
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1346:22: error: 'auto' return without trailing return type; deduced return types are a C++14 extension
warning: [email protected]:  1346 | _NODISCARD constexpr auto _Idl_distance(const _Iter& _First, const _Iter& _Last) {
warning: [email protected]:       |                      ^
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1351:16: error: no viable conversion from returned value of type '_Distance_unknown' to function return type 'int'
warning: [email protected]:  1351 |         return _Distance_unknown{};
warning: [email protected]:       |                ^~~~~~~~~~~~~~~~~~~
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1647:27: error: constexpr function's return type 'void' is not a literal type
warning: [email protected]:  1647 |     friend constexpr void _Verify_range(
warning: [email protected]:       |                           ^
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1653:20: error: constexpr function's return type 'void' is not a literal type
warning: [email protected]:  1653 |     constexpr void _Verify_offset(const difference_type _Off) const noexcept {
warning: [email protected]:       |                    ^
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1672:20: error: constexpr function's return type 'void' is not a literal type
warning: [email protected]:  1672 |     constexpr void _Seek_to(const reverse_iterator<_Src>& _It) noexcept(noexcept(current._Seek_to(_It.current))) {
warning: [email protected]:       |                    ^
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:4071:18: error: 'auto' return without trailing return type; deduced return types are a C++14 extension
warning: [email protected]:  4071 |     _CONSTEXPR17 auto operator++(int) noexcept(
warning: [email protected]:       |                  ^
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:4175:27: error: constexpr function's return type 'void' is not a literal type
warning: [email protected]:  4175 |     friend constexpr void _Verify_range(const move_iterator& _First, const move_iterator<_Iter2>& _Last) noexcept {
warning: [email protected]:       |                           ^
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:4188:20: error: constexpr function's return type 'void' is not a literal type
warning: [email protected]:  4188 |     constexpr void _Verify_offset(const difference_type _Off) const noexcept {
warning: [email protected]:       |                    ^
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:4206:20: error: constexpr function's return type 'void' is not a literal type
warning: [email protected]:  4206 |     constexpr void _Seek_to(const move_iterator<_Src>& _It) noexcept(noexcept(_Current._Seek_to(_It._Get_current()))) {
warning: [email protected]:       |                    ^
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:4210:20: error: constexpr function's return type 'void' is not a literal type
warning: [email protected]:  4210 |     constexpr void _Seek_to(move_iterator<_Src>&& _It) noexcept(
warning: [email protected]:       |                    ^
warning: [email protected]: E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:4368:22: error: 'auto' return without trailing return type; deduced return types are a C++14 extension
warning: [email protected]:  4368 | _NODISCARD constexpr auto _To_address(const _Iter& _Val) noexcept {
warning: [email protected]:       |                      ^
warning: [email protected]: fatal error: too many errors emitted, stopping now [-ferror-limit=]
warning: [email protected]: 20 errors generated.

error: failed to run custom build command for `cxx v1.0.122`

Caused by:
  process didn't exit successfully: `S:/wplace/cpp/FileDiffMain/build/./cargo/build\debug\build\cxx-a8f87278adda9a6f\build-script-build` (exit code: 1)
  --- stdout
  TARGET = Some("x86_64-pc-windows-msvc")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-pc-windows-msvc")
  cargo:rerun-if-env-changed=CXX_x86_64-pc-windows-msvc
  CXX_x86_64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=CXX_x86_64_pc_windows_msvc
  CXX_x86_64_pc_windows_msvc = Some("S:/wplace/sdk/compilers/clang/bin/clang++.exe")
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  cargo:rerun-if-env-changed=CXXFLAGS_x86_64-pc-windows-msvc
  CXXFLAGS_x86_64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=CXXFLAGS_x86_64_pc_windows_msvc
  CXXFLAGS_x86_64_pc_windows_msvc = None
  cargo:rerun-if-env-changed=HOST_CXXFLAGS
  HOST_CXXFLAGS = None
  cargo:rerun-if-env-changed=CXXFLAGS
  CXXFLAGS = None
  cargo:warning=In file included from Q:\Users\Claymore\.cargo\registry\src\index.crates.io-6f17d22bba15001f\cxx-1.0.122\src/cxx.cc:1:
  cargo:warning=In file included from Q:\Users\Claymore\.cargo\registry\src\index.crates.io-6f17d22bba15001f\cxx-1.0.122\src\../include/cxx.h:2:
  cargo:warning=In file included from E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\algorithm:10:
  cargo:warning=In file included from E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xmemory:15:
  cargo:warning=In file included from E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:11:
  cargo:warning=In file included from E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\__msvc_iter_core.hpp:10:
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\utility:162:22: error: 'auto' return without trailing return type; deduced return types are a C++14 extension
  cargo:warning=  162 | _NODISCARD constexpr auto&& _Tuple_get(tuple<_Types...>&& _Tuple) noexcept;
  cargo:warning=      |                      ^
  cargo:warning=In file included from Q:\Users\Claymore\.cargo\registry\src\index.crates.io-6f17d22bba15001f\cxx-1.0.122\src/cxx.cc:1:
  cargo:warning=In file included from Q:\Users\Claymore\.cargo\registry\src\index.crates.io-6f17d22bba15001f\cxx-1.0.122\src\../include/cxx.h:2:
  cargo:warning=In file included from E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\algorithm:10:
  cargo:warning=In file included from E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xmemory:15:
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:546:15: error: deduced return types are a C++14 extension
  cargo:warning=  546 |     constexpr decltype(auto) operator()(_Args&&... _Vals) noexcept(
  cargo:warning=      |               ^
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:559:22: error: 'auto' return without trailing return type; deduced return types are a C++14 extension
  cargo:warning=  559 | _NODISCARD constexpr auto _Pass_fn(_Fn& _Func) noexcept {
  cargo:warning=      |                      ^
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1162:16: error: constexpr function's return type 'void' is not a literal type
  cargo:warning= 1162 | constexpr void _Adl_verify_range(const _Iter& _First, const _Sentinel& _Last) {
  cargo:warning=      |                ^
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1184:22: error: deduced return types are a C++14 extension
  cargo:warning= 1184 | _NODISCARD constexpr decltype(auto) _Get_unwrapped(_Iter&& _It) noexcept(
  cargo:warning=      |                      ^
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1212:22: error: deduced return types are a C++14 extension
  cargo:warning= 1212 | _NODISCARD constexpr decltype(auto) _Get_unwrapped_unverified(_Iter&& _It) {
  cargo:warning=      |                      ^
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1251:22: error: deduced return types are a C++14 extension
  cargo:warning= 1251 | _NODISCARD constexpr decltype(auto) _Get_unwrapped_n(_Iter&& _It, const _Diff _Off) {
  cargo:warning=      |                      ^
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1285:16: error: constexpr function's return type 'void' is not a literal type
  cargo:warning= 1285 | constexpr void _Seek_wrapped(_Iter& _It, _UIter&& _UIt) {
  cargo:warning=      |                ^
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1346:22: error: 'auto' return without trailing return type; deduced return types are a C++14 extension
  cargo:warning= 1346 | _NODISCARD constexpr auto _Idl_distance(const _Iter& _First, const _Iter& _Last) {
  cargo:warning=      |                      ^
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1351:16: error: no viable conversion from returned value of type '_Distance_unknown' to function return type 'int'
  cargo:warning= 1351 |         return _Distance_unknown{};
  cargo:warning=      |                ^~~~~~~~~~~~~~~~~~~
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1647:27: error: constexpr function's return type 'void' is not a literal type
  cargo:warning= 1647 |     friend constexpr void _Verify_range(
  cargo:warning=      |                           ^
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1653:20: error: constexpr function's return type 'void' is not a literal type
  cargo:warning= 1653 |     constexpr void _Verify_offset(const difference_type _Off) const noexcept {
  cargo:warning=      |                    ^
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:1672:20: error: constexpr function's return type 'void' is not a literal type
  cargo:warning= 1672 |     constexpr void _Seek_to(const reverse_iterator<_Src>& _It) noexcept(noexcept(current._Seek_to(_It.current))) {
  cargo:warning=      |                    ^
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:4071:18: error: 'auto' return without trailing return type; deduced return types are a C++14 extension
  cargo:warning= 4071 |     _CONSTEXPR17 auto operator++(int) noexcept(
  cargo:warning=      |                  ^
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:4175:27: error: constexpr function's return type 'void' is not a literal type
  cargo:warning= 4175 |     friend constexpr void _Verify_range(const move_iterator& _First, const move_iterator<_Iter2>& _Last) noexcept {
  cargo:warning=      |                           ^
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:4188:20: error: constexpr function's return type 'void' is not a literal type
  cargo:warning= 4188 |     constexpr void _Verify_offset(const difference_type _Off) const noexcept {
  cargo:warning=      |                    ^
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:4206:20: error: constexpr function's return type 'void' is not a literal type
  cargo:warning= 4206 |     constexpr void _Seek_to(const move_iterator<_Src>& _It) noexcept(noexcept(_Current._Seek_to(_It._Get_current()))) {
  cargo:warning=      |                    ^
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:4210:20: error: constexpr function's return type 'void' is not a literal type
  cargo:warning= 4210 |     constexpr void _Seek_to(move_iterator<_Src>&& _It) noexcept(
  cargo:warning=      |                    ^
  cargo:warning=E:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility:4368:22: error: 'auto' return without trailing return type; deduced return types are a C++14 extension
  cargo:warning= 4368 | _NODISCARD constexpr auto _To_address(const _Iter& _Val) noexcept {
  cargo:warning=      |                      ^
  cargo:warning=fatal error: too many errors emitted, stopping now [-ferror-limit=]
  cargo:warning=20 errors generated.

  --- stderr


  error occurred: Command "S:/wplace/sdk/compilers/clang/bin/clang++.exe" "-O0" "--target=x86_64-pc-windows-msvc" "-ffunction-sections" "-fdata-sections" "-g" "-fno-omit-frame-pointer" "-m64" "--target=x86_64-pc-windows-msvc" "-std=c++11" "-Wall" "-Wextra" "-o" "S:/wplace/cpp/FileDiffMain/build/./cargo/build\\debug\\build\\cxx-f9da14951b32e447\\out\\cb664adeb7db9b26-cxx.o" "-c" "Q:\\Users\\Claymore\\.cargo\\registry\\src\\index.crates.io-6f17d22bba15001f\\cxx-1.0.122\\src/cxx.cc" with args clang++.exe did not execute successfully (status code exit code: 1).


indows-msvc --package lib --manifest-path S:/wplace/cpp/FileDiffMain/lib/Cargo.toml --target-dir S:/wplace/cpp/FileDiffMain/build/./cargo/build -- -Cdefault-linker-libraries=yes"
FAILED: CMakeFiles/_cargo-build_lib S:/wplace/cpp/FileDiffMain/build/CMakeFiles/_cargo-build_lib
cmd.exe /C "cd /D S:\wplace\cpp\FileDiffMain\lib && "E:\Program Files\CMake\bin\cmake.exe" -E env CC_x86_64_pc_windows_msvc=S:/wplace/sdk/compilers/clang/bin/clang.exe CXX_x86_64_pc_windows_msvc=S:/wplace/sdk/compilers/clang/bin/clang++.exe CORROSION_BUILD_DIR=S:/wplace/cpp/FileDiffMain/build CARGO_BUILD_RUSTC=Q:/Users/Claymore/.rustup/toolchains/stable-x86_64-pc-windows-msvc/bin/rustc.exe Q:/Users/Claymore/.rustup/toolchains/stable-x86_64-pc-windows-msvc/bin/cargo.exe rustc --lib --target=x86_64-pc-windows-msvc --package lib --manifest-path S:/wplace/cpp/FileDiffMain/lib/Cargo.toml --target-dir S:/wplace/cpp/FileDiffMain/build/./cargo/build -- -Cdefault-linker-libraries=yes"
ninja: build stopped: subcommand failed.

My specs if it helps:

  • OS: Windows 10 Enterprise LTSC (1809)
  • rustc version: 1.78.0
  • CXX and CC are set to clang++ and clang respectively
  • cxx: "1.0" in Cargo.toml
  • cxx-build: "1.0" in Cargo.toml
  • cmake version: 3.27.4

I suppose it would help if I was able to explicitly set the cxx compile flag to something above c++11, but I'm not sure if I can do that and adding .std("c++20") to the chain in build.rs didn't help

@ClayCore
Copy link
Author

This specific issue was fixed by adding features = ["c++20"] to cxx dependency in the Cargo.toml however it highlights a small issue.

With corrosion on its own and maintaining my own building with custom commands, I was able to produce a Rust cdylib that linked against the executables without cxx. This required the use of extern "C" for function declarations in the C++ source, as well as adding #[no_mangle] pub extern "C" to functions in the Rust library and I didn't expect it to be necessary for cxx (since none of the examples I could find include those decorations on either C++ or Rust's side)

However now my build is throwing undefined references to symbols.

C++ code:

// main.cpp
#include "src/lib.rs.h"

auto main() -> int
{
    greet();

    return 0;
}

Rust code:

// src/lib.rs
#[cxx::bridge]
mod ffi {
    extern "Rust" {
        pub fn greet();
    }
}

pub fn greet() {
    println!("Hello from Rust!")
}

Cargo.toml:

[package]
name = "lib"
version = "0.1.0"
edition = "2021"


[lib]
path = "src/lib.rs"
name = "lib"
crate-type = ["cdylib"]

[dependencies]
cxx = { version = "1.0", features = ["c++20"] }

[build-dependencies]
cxx-build = "1.0"

CMakeLists for the executable (part of a giant template, so it's not the full picture):

add_executable(
  fileDiffCLI
  main.cpp
)
add_executable(dev::fileDiffCLI ALIAS fileDiffCLI)

target_link_libraries(fileDiffCLI PRIVATE dev_options dev_warnings)
target_link_libraries(fileDiffCLI PUBLIC lib)
target_include_directories(
  fileDiffCLI
  ${WARNING_GUARD}
  PUBLIC
  $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/bin/fileDiffCLI>
  $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/lib/target/cxxbridge/lib>
  $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/bin/fileDiffCLI>
)
target_compile_features(fileDiffCLI PUBLIC cxx_std_20)

set_target_properties(
  fileDiffCLI
  PROPERTIES
  VERSION ${PROJECT_VERSION}
  CXX_VISIBILITY_PRESET hidden
  VISIBILITY_INLINES_HIDDEN YES
)

if(BUILD_TESTING)
  message(TRACE "Building tests...")
  add_subdirectory(test)
endif()

add_custom_command(
  TARGET
  fileDiffCLI
  POST_BUILD
  COMMAND
  ${CMAKE_COMMAND} -E copy $<TARGET_FILE:fileDiffCLI> ${PROJECT_SOURCE_DIR}/target
)

The lib target present in the above cmake file was generated using corrosion, same as in the original post, however I updated it to add all *_OUTPUT_DIRECTORY properties to the lib target, so that it's easier to copy and move around later. Code below

include(cmake/CPM.cmake)
include(cmake/AddDir.cmake)

function(dev_deps_setup)
  if(NOT TARGET lib)
    CPMAddPackage(
      NAME corrosion
      VERSION 0.5
      GITHUB_REPOSITORY
      "corrosion-rs/corrosion"
    )

    # creates a directory if it doesn't already exist.
    dev_add_dir("${CMAKE_BINARY_DIR}/lib")

    corrosion_import_crate(
      MANIFEST_PATH
      ${CMAKE_SOURCE_DIR}/lib/Cargo.toml
    )

    set_target_properties(
      lib
      PROPERTIES
      ARCHIVE_OUTPUT_DIRECTORY
      ${CMAKE_BINARY_DIR}/lib
    )

    set_target_properties(
      lib
      PROPERTIES
      LIBRARY_OUTPUT_DIRECTORY
      ${CMAKE_BINARY_DIR}/lib
    )

    set_target_properties(
      lib
      PROPERTIES
      RUNTIME_OUTPUT_DIRECTORY
      ${CMAKE_BINARY_DIR}/lib
    )
  endif()
endfunction()

Finally, this is the build log using cmake --build build --config Debug --verbose

Change Dir: 'S:/wplace/cpp/FileDiffMain/build'

Run Build Command(s): S:/wplace/sdk/Python/Python310/Scripts/ninja.exe -v
-- CPM: Adding package [email protected] (v0.5)
-- Rust Toolchain: stable-x86_64-pc-windows-msvc
-- Rust Target: x86_64-pc-windows-msvc
-- Using Corrosion as a subdirectory
--  * trying to find and to run 'vcvarsall.bat'...
--  * S:/msys64/opt/bin/ccache.exe found and enabled
--  * setting clang-tidy globally...
-- Configuring done (3.8s)
-- Generating done (0.0s)
-- Build files have been written to: S:/wplace/cpp/FileDiffMain/build
[0/1] "E:\Program Files\CMake\bin\cmake.exe" --regenerate-during-build -SS:\wplace\cpp\FileDiffMain -BS:\wplace\cpp\FileDiffMain\build
[0/5] cmd.exe /C "cd /D S:\wplace\cpp\FileDiffMain\lib && "E:\Program Files\CMake\bin\cmake.exe" -E env CC_x86_64_pc_windows_msvc=S:/wplace/sdk/compilers/clang/bin/clang.exe CXX_x86_64_pc_windows_msvc=S:/wplace/sdk/compilers/clang/bin/clang++.exe CORROSION_BUILD_DIR=S:/wplace/cpp/FileDiffMain/build CARGO_BUILD_RUSTC=Q:/Users/Claymore/.rustup/toolchains/stable-x86_64-pc-windo    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s
ws-msvc/bin/rustc.exe Q:/Users/Claymore/.rustup/toolchains/stable-x86_64-pc-windows-msvc/bin/cargo.exe rustc --lib --target=x86_64-pc-windows-msvc --package lib --manifest-path S:/wplace/cpp/FileDiffMain/lib/Cargo.toml --target-dir S:/wplace/cpp/FileDiffMain/build/./cargo/build -- -Cdefault-linker-libraries=yes"
[2/5] cmd.exe /C "cd /D S:\wplace\cpp\FileDiffMain\build && "E:\Program Files\CMake\bin\cmake.exe" -E make_directory S:/wplace/cpp/FileDiffMain/build/lib && "E:\Program Files\CMake\bin\cmake.exe" -E copy_if_different S:/wplace/cpp/FileDiffMain/build/./cargo/build/x86_64-pc-windows-msvc/debug/lib.dll.lib S:/wplace/cpp/FileDiffMain/build/lib && cd /D S:\wplace\cpp\FileDiffMain\build && "E:\Program Files\CMake\bin\cmake.exe" -E make_directory S:/wplace/cpp/FileDiffMain/build/lib && "E:\Program Files\CMake\bin\cmake.exe" -E copy_if_different S:/wplace/cpp/FileDiffMain/build/./cargo/build/x86_64-pc-windows-msvc/debug/lib.dll S:/wplace/cpp/FileDiffMain/build/lib && cd /D S:\wplace\cpp\FileDiffMain\build && "E:\Program Files\CMake\bin\cmake.exe" -E make_directory S:/wplace/cpp/FileDiffMain/build && "E:\Program Files\CMake\bin\cmake.exe" -E copy_if_different S:/wplace/cpp/FileDiffMain/build/./cargo/build/x86_64-pc-windows-msvc/debug/lib.pdb S:/wplace/cpp/FileDiffMain/build"
[3/4] "E:\Program Files\CMake\bin\cmake.exe" -E __run_co_compile --launcher=S:/msys64/opt/bin/ccache.exe --tidy="E:/Program Files/LLVM/bin/clang-tidy.exe;-extra-arg=-Wno-unknown-warning-option;-extra-arg=-Wno-ignored-optimization-argument;-extra-arg=-Wno-unused-command-line-argument;-p;--extra-arg-before=--driver-mode=g++" --source=S:\wplace\cpp\FileDiffMain\bin\fileDiffCLI\main.cpp -- S:\wplace\sdk\compilers\clang\bin\clang++.exe  -IS:/wplace/cpp/FileDiffMain/bin/fileDiffCLI -IS:/wplace/cpp/FileDiffMain/lib/target/cxxbridge/lib -IS:/wplace/cpp/FileDiffMain/build/bin/fileDiffCLI -O0 -g -Xclang -gcodeview -std=c++20 -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -flto=thin -fvisibility-inlines-hidden -fcolor-diagnostics -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wpedantic -Wconversion -Wsign-conversion -Wnull-dereference -Wdouble-promotion -Wformat=2 -Wimplicit-fallthrough -MD -MT bin/fileDiffCLI/CMakeFiles/fileDiffCLI.dir/main.cpp.obj -MF bin\fileDiffCLI\CMakeFiles\fileDiffCLI.dir\main.cpp.obj.d -o bin/fileDiffCLI/CMakeFiles/fileDiffCLI.dir/main.cpp.obj -c S:/wplace/cpp/FileDiffMain/bin/fileDiffCLI/main.cpp
[4/4] cmd.exe /C "cd . && S:\wplace\sdk\compilers\clang\bin\clang++.exe -fuse-ld=lld-link -nostartfiles -nostdlib -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -flto=thin -Xlinker /subsystem:console bin/fileDiffCLI/CMakeFiles/fileDiffCLI.dir/main.cpp.obj -o bin\fileDiffCLI\fileDiffCLI.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:bin\fileDiffCLI\fileDiffCLI.lib -Xlinker /pdb:bin\fileDiffCLI\fileDiffCLI.pdb -Xlinker /version:0.1   lib/lib.dll.lib  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames  && cmd.exe /C "cd /D S:\wplace\cpp\FileDiffMain\build\bin\fileDiffCLI && "E:\Program Files\CMake\bin\cmake.exe" -E copy S:/wplace/cpp/FileDiffMain/build/bin/fileDiffCLI/fileDiffCLI.exe S:/wplace/cpp/FileDiffMain/target""
FAILED: bin/fileDiffCLI/fileDiffCLI.exe
cmd.exe /C "cd . && S:\wplace\sdk\compilers\clang\bin\clang++.exe -fuse-ld=lld-link -nostartfiles -nostdlib -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -flto=thin -Xlinker /subsystem:console bin/fileDiffCLI/CMakeFiles/fileDiffCLI.dir/main.cpp.obj -o bin\fileDiffCLI\fileDiffCLI.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:bin\fileDiffCLI\fileDiffCLI.lib -Xlinker /pdb:bin\fileDiffCLI\fileDiffCLI.pdb -Xlinker /version:0.1   lib/lib.dll.lib  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames  && cmd.exe /C "cd /D S:\wplace\cpp\FileDiffMain\build\bin\fileDiffCLI && "E:\Program Files\CMake\bin\cmake.exe" -E copy S:/wplace/cpp/FileDiffMain/build/bin/fileDiffCLI/fileDiffCLI.exe S:/wplace/cpp/FileDiffMain/target""
lld-link: error: undefined symbol: void __cdecl greet(void)
>>> referenced by S:/wplace/cpp/FileDiffMain/bin/fileDiffCLI/main.cpp
>>>               bin/fileDiffCLI/CMakeFiles/fileDiffCLI.dir/main.cpp.obj
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

lld-link is failing, and I found out (at least with corrosion) that the extern "C" directives were necessary on both sides, is this still the case with cxx?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant