Skip to content

Unreal support : Error LNK2019 : unresolved external symbol ****$cxxbridge1$func #1521

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

Open
tarnishablec opened this issue May 20, 2025 · 1 comment

Comments

@tarnishablec
Copy link

tarnishablec commented May 20, 2025

I was testing integrating cxx to Unreal Engine custom plugin to call a simple rust function from c++.

this is my file structure

Image

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.

@msundvick
Copy link

We've been building a DLL for use with Unreal, and this is certainly a bit of a PITA, looks like the same issue.

This issue appears related to #1153. There are some workarounds in there, but for us they didn't work very well, with a mess of conflicting symbols coming from our dependencies (although for your basic case, they might be fine, our dependencies aren't trivial). There's probably an elegant solution, but I couldn't find one. Some other issues that seem potentially relevant:

Instead of an elegant solution, what I've currently got is a somewhat horrific hack:

Not pretty, but is does work. Would love to hear if anyone's got other workarounds.

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

2 participants