I am using SWIG to generate a DLL that will expose C++ functionality to a C# project. At the moment I:
Define a SWIG interface file
%module example %{ /* Includes the header in the wrapper code */ #include "../pointmatcher/PointMatcher.h" %} ... %include "../pointmatcher/PointMatcher.h"
Use SWIG to generate a .cxx wrapper
swig.exe -c++ -csharp -outdir csharp example.i
Compile the .cxx wrapper with MSBUILD via CMake
# create wrapper DLL add_library(example SHARED ${WRAP_CSHARP_FILE}) target_link_libraries(example pointmatcher) install(TARGETS example ARCHIVE DESTINATION ${INSTALL_LIB_DIR} LIBRARY DESTINATION ${INSTALL_LIB_DIR} RUNTIME DESTINATION ${INSTALL_BIN_DIR})
I then have a DLL file (example.dll
) which I can inspect via Dependency Walker, and confirm that methods are being exposed as follows:
However, when I try to add this MSVC DLL as a reference to a C# project I get the error "It is not a valid assembly or COM component".
Based on answers at How can I add a VC++ DLL as a reference in my C# Visual Studio project? I have confirmed that SWIG itself generates P/Invoke calls, and that tlbimp
doesn't recognise the DLL either.