0

I have followed this example on how to mix C# and C++ code in single assembly and all compiles fine. But all this is from the developer command prompt. I want to put all this in one Visual Studio solution and can't succeed. Does anybody know how to do that? (I am still very inexperienced with Visual Studio)

I have found several articles about this, but all give examples from the command prompt. This SO answer even recommends not doing this at all, not sure why?

Also, many of those articles talk about creating a managed DLL (using dllexport/dllimport, but I need to link the obj/lib files directly in the same C# assembly.

Note: The reason I need to do this, is to add a licensing static library to my C# desktop application project. The library is written in C/C++ and is already used in my back-end, I would like to use the same logic for the front-end. Loading the library as a DLL would defeat the purpose since anybody could just change it for a fake one. Therefore linking it in the same assembly is essential.

jav
  • 583
  • 5
  • 15
  • According to [this link](https://stackoverflow.com/questions/729562/how-to-compile-c-sharp-application-with-c-static-library), it is hard for you to do it. I suggest that you can recreate a dynamic-link library to call c++ in c#. – Jack J Jun Dec 13 '19 at 02:52
  • @Jack J Jun thank you for the comment. I have seen that thread already, but I think there should be a way to do it since it is possible from the command line. In the command line you would do "link mfoo.obj ufoo.obj bar.netmodule /entry:Bar.Main" where "ufoo.obj" can be a C static library. And that links with no problems. – jav Dec 13 '19 at 10:18
  • You should be able to customize link command in the project properties. – Tanveer Badar Dec 13 '19 at 10:26
  • It seems what done in the command line cannot be reproduced in the IDE. 1) Option /c for creating OBJ files is not available in the IDE (https://learn.microsoft.com/en-us/cpp/build/reference/c-compile-without-linking?view=vs-2019), 2) Alternative to OBJ files is to create a static library, but static libraries are not supported for managed code i.e. option /clr (https://social.msdn.microsoft.com/Forums/windows/en-US/1d8e2dd4-59e8-498a-a793-4ccf64c97d7b/building-a-static-library-with-clr-and-net-45?forum=vclanguage) – jav Dec 13 '19 at 19:46

0 Answers0