[CMake] C++/CLI Wrapper with C#

J. Caleb Wherry calebwherry at gmail.com
Wed Sep 20 10:36:06 EDT 2017


All,

I recently upgraded to CMake 3.8 to get support for C# as a first class
language and it works nicely. However, I am seeking clarification on
something:

I currently compile my C++/CLI wrapper as a SHARED lib. This produces a
linking lib which I didn't expect and don't want (using the lib works fine
in my build with no issues). After reading the docs (
https://cmake.org/cmake/help/v3.8/command/add_library.html), it seems like
I should be compiling the lib as a MODULE since I do not want unmanaged
symbols exported.

However, when I change to MODULE and try to link that to a C# console app,
it doesn't work anymore, I get the "MODULE_LIBRARY may not be linked into
another target".

My question: am I doing something wrong here? What is the standard way to
build a C++/CLI lib and link it to a C# app?

Some things to note:

   - When I link to the C# app, I use target_link_libraries, I don't put it
   as a reference. I was hoping I could just use this macro and not have to
   explicitly place it as a reference.
   - My C++/CLI wrapper lib does have some public C symbols which I believe
   is causing the linking lib to be created so I will investigate that.
   However, that doesn't answer the question of how to correctly compile a
   C++/CLI lib.

If there isn't a simple answer, I can create a SSCCE (http://sscce.org/) to
replicate the issue I am having.

Thanks!
Caleb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170920/4dd2ad62/attachment.html>


More information about the CMake mailing list