-1

I understand C# is available for Linux specifically Centos8: https://learn.microsoft.com/en-us/dotnet/core/install/linux-centos But can an application developed in C# for Linux/Centos8 call into libraries compiled for other languages, e.g., C++ or C?

  • "libraries compiled for other languages" -- Libraries (or executes) aren't compiled for languages. They are written in some programming language and then compiled for some CPU or interpreter/runtime architecture. So your question is confusing. – sticky bit Apr 10 '21 at 16:07
  • A Windows DLL, compiled by Visual Studio from C++ source, is not directly accessible by a C# application. Windows utility AXIMP.EXE must be used upon the DLL to produce a bridge interface between C# and the C++ DLL. Are Linux libraries, compiled from C++, directly callable by C# for Linux? If not, does something equivalent to AXIMP.EXE exist for Linux to bridge between C# and C++? – Frank Detrez Apr 10 '21 at 16:13
  • 1
    You can use P/Invoke to call functions in a C API from C#. See e.g. this [article](https://developers.redhat.com/blog/2019/03/25/using-net-pinvoke-for-linux-system-functions/) – Klaus Gütter Apr 11 '21 at 02:06
  • Does this answer your question? [P-Invoke in .net core with Linux](https://stackoverflow.com/questions/38202027/p-invoke-in-net-core-with-linux) – Klaus Gütter Apr 11 '21 at 02:09

1 Answers1

0

If you are looking to write c/c++ functions and call them , you could try unsafe blocks. Also you can run any other executable for result using the Process api. These are two options not mentioned by others.

Snippy Valson
  • 231
  • 3
  • 9
  • Actually, my assignment is the reverse. An existing library, written and compiled from C++, is ordinarily used by C++ programs. We wish to also allow C# programs to call the existing library. Since C# is interpretive and C++ is compiled/machine code, my understanding is the former cannot directly call into the latter, but some additional layer is required. My efforts to understand what is possible have so far earned a "your question is confusing" and a downvote on the question itself. Nevertheless, I still need to learn if C# under Linux can call into libraries written in C++ under Linux. – Frank Detrez Apr 10 '21 at 16:51
  • "Since C# is interpretive" - certainly not. – Klaus Gütter Apr 11 '21 at 02:04