I have a static library file (.lib) called SampleArithmetic.lib
and the header file for it SampleArithmetic.h
. Now using these files, I want to generate a DLL files for the functions present in the SampleArithmetic.lib
.
What I did:
Created a new project in VS2022 of type
Class Library
Configured include folder path (to access
SampleArithmetic.h
)Configured lib path and the lib required (i.e.
SampleArithmetic.lib
)and finally, added the code below in a .cpp file called
SampleArithmeticDLLGenerator.cpp
#include "SampleArithmetic.h" #include "pch.h" extern "C" { __declspec(dllexport) int add(int a, int b) { SampleArithmetic obj; return obj.Add(a, b); } __declspec(dllexport) int subtract(int a, int b) { SampleArithmetic obj; return obj.Subtract(a, b); } __declspec(dllexport) int multiply(int a, int b) { SampleArithmetic obj; return obj.Multiply(a, b); } }
PROBLEM:
I am getting the following errors:
Severity Code Description Project File Line Suppression State Error C2065 'SampleArithmetic': undeclared identifier CPlusPlusDLLWrapper C:\Users\Downloads\TestProject\TestCppLibIntegrationInCSharp\CPlusPlusDLLWrapper\SampleArithmeticDLLGenerator.cpp 7
Severity Code Description Project File Line Suppression State Error C2065 'obj': undeclared identifier CPlusPlusDLLWrapper C:\Users\Downloads\TestProject\TestCppLibIntegrationInCSharp\CPlusPlusDLLWrapper\SampleArithmeticDLLGenerator.cpp 7