Help! How can I access a C++ library from c#?

  • Thread starter Thread starter Luq
  • Start date Start date
L

Luq

I am confused....
My plan is to write a program for some scientific computing in c#,
because I heard that c# codes are much better and easier to write and
manage. But the problem is that I have to use some c++ library, for
example the GSL (GNU Scientific library) for some numerical functions
and the library for HDF5 data format. They are xxxx.a files under
Linux. So how can I access these libraries from the c# programs? Is
that possible on earth?
Thx a lot!

Simon
 
Luq said:
I am confused....
My plan is to write a program for some scientific computing in c#,
because I heard that c# codes are much better and easier to write and
manage. But the problem is that I have to use some c++ library, for
example the GSL (GNU Scientific library) for some numerical functions
and the library for HDF5 data format. They are xxxx.a files under
Linux. So how can I access these libraries from the c# programs? Is
that possible on earth?

The GSL is a pure "C" library, not C++, so you have the option of using
DllImport.

However, when you start calling external DLLs, much of the safety that C#
offers is gone. Also the speed using C# will be much worse (pure C# is
quite fast, but calls from C# to C functions are not).
 
Luq said:
I am confused....
My plan is to write a program for some scientific computing in c#,
because I heard that c# codes are much better and easier to write and
manage. But the problem is that I have to use some c++ library, for
example the GSL (GNU Scientific library) for some numerical functions
and the library for HDF5 data format. They are xxxx.a files under
Linux. So how can I access these libraries from the c# programs? Is
that possible on earth?
Thx a lot!

Simon

If you are programming for Windows only you have the option of using
C++/CLI to wrap the library with managed objects and use them from C#
directly. Otherwise you have only the option to use PInvoke (DllImport),
since I don't think porting the library isn't a (very good) option ;-).

Andre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top