CppSharp icon indicating copy to clipboard operation
CppSharp copied to clipboard

Unable to load DLL when running the C# project.

Open Joel0129 opened this issue 2 years ago • 1 comments

Brief Description

I am attempting to develop a simple CppSharp project. The implementation of the Setup function in the ILibrary interface is as follows:

public void Setup(Driver driver)
{
    //throw new NotImplementedException(); 
    var options = driver.Options;
    options.GeneratorKind = GeneratorKind.CSharp;
    options.OutputDir = @"D:\Project\Cppsharp\Sample\output";
    var module = options.AddModule("CppClass");
    module.IncludeDirs.Add(@"D:\Project\Cppsharp\Sample\include");
    module.Headers.Add("Sample.h");
}

Upon execution of ConsoleDriver.Run(new CppClass()), two files named CppClass.cs and CppClass-symbols.cpp are generated within the designated folder. The files CppClass.cs and CppClass-symbols.cpp are copied into the C# project, and a Sample object is instantiated using CppClass.Sample sample = new CppClass.Sample(1,2).

However, upon running the C# project, an error message of "Unable to load DLL 'CppClass' or one of its dependencies" arises. Could you kindly advise on what steps I may be omitting?

OS: Windows

Used headers
class Sample 
{
public:
	int a;
	int b;
	Sample(int a, int b){
		this->a=a;
		this->b=b;
	};
};
Used settings

Target: MSVC/GCC/Clang

Other settings

Stack trace or incompilable generated code

Joel0129 avatar Nov 14 '23 14:11 Joel0129

Not sure, maybe you need to annotate the declarations with __declspec(dllexport)?

tritao avatar Nov 14 '23 19:11 tritao