-
Notifications
You must be signed in to change notification settings - Fork 338
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
Comments
This specific issue was fixed by adding With corrosion on its own and maintaining my own building with custom commands, I was able to produce a Rust 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 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
|
My project uses CMake and
corrosion-rs
for C++ and Rust interopt. I've got an executable written in C++ and a Rustcdylib
library.The Rust library contains the following:
I'm adding the library as a target via
corrosion-rs
and linking it with the executable as follows: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
So far so good, some of these
*-NOTFOUND
are a bit worrysome, but it's probably me not settingARCHIVE_OUTPUT_DIRECTORY
explicitly for the target pulled by corrosionRunning
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 thecxx.cc
My specs if it helps:
clang++
andclang
respectivelyCargo.toml
Cargo.toml
I suppose it would help if I was able to explicitly set the
cxx
compile flag to something abovec++11
, but I'm not sure if I can do that and adding.std("c++20")
to the chain inbuild.rs
didn't helpThe text was updated successfully, but these errors were encountered: