-
Notifications
You must be signed in to change notification settings - Fork 374
Open
Description
I was testing integrating cxx to Unreal Engine custom plugin to call a simple rust function from c++.
this is my file structure
this is src/lib.rs
#[cxx::bridge(namespace = "dwebble")]
pub mod ffi {
extern "Rust" {
pub fn test() -> u8;
}
}
pub fn test() -> u8 {
return 22;
}
build.rs
extern crate cxx_build;
use std::fs;
fn main() {
let out_lib_dir = "Bindings";
fs::remove_dir_all(out_lib_dir).unwrap();
cxx_build::bridge("src/lib.rs")
.out_dir(out_lib_dir)
.compile("dwebble");
}
unreal build.cs
public class Dwebble : ModuleRules
{
public Dwebble(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
Type = ModuleType.CPlusPlus;
PublicAdditionalLibraries.AddRange(
[
Path.Combine(PluginDirectory, @"Bindings\dwebble.lib"),
]);
// PublicPreBuildLibraries.Add(Path.Combine(PluginDirectory, @"Bindings\dwebble.lib"));
PublicIncludePaths.AddRange(
new string[]
{
// ... add public include paths required here ...
Path.Combine(PluginDirectory, @"target\cxxbridge")
}
);
...
c++ code in unreal
#include "DwebbleSubsystem.h"
#include "dwebble/src/lib.rs.h"
void UDwebbleSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);
UE_LOG(LogTemp, Warning, TEXT("UDwebbleSubsystem::Initialize with %d"), dwebble::test());
}
when building in unreal a compiler error prompted
11>dwebble.lib(08496bdb74dbd239-lib.rs.o): Error LNK2019 : unresolved external symbol dwebble$cxxbridge1$test referenced in function "unsigned char __cdecl dwebble::test(void)" (?test@dwebble@@YAEXZ)
11>UnrealEditor-Dwebble-Win64-DebugGame.dll: Error LNK1120 : 1 unresolved externals
What am i missing to do?
using msvc 14.44.
Metadata
Metadata
Assignees
Labels
No labels