Mono P/invoke: dllimport

Source: Internet
Author: User

Mono was originally designed to attract more windows. Net programmers to join the development of the Linux platform. However, in the Linux World, C language is still the mainstream. Most of the time, some key applications (such as the calculation of the product of a large flute card and the call of platform hardware functions) have to rely on C to complete the operation.

Mono is described through dllimport. The following is a sample code:
[Dllimport ("libc. So")]

Private Static extern int getpid ();
Of course, do not forget to add the namespace: system. runtime. interopservices
When this code is executed, Mono runtime will attempt to call getpid () in libc. So in the local system. If it is found, getpid () will be executed. Otherwise, dllnotfoundexception will be thrown.

The order of sharing library search for dllimport on Linux is as follows:

1./lib, for example, in/usr/lib
2. Most library files are cached in/etc/lD. so. cache, the file is written by/etc/lD. so. after the conf file is edited, run the ldconfig command to generate the file. then you can. so. add the directory of the so file in conf and run ldconfig.
3. Environment VariablesLD_LIBRARY_PATHDirectory

 

Related Articles:

How to use C to generate. So for mono call

C # precautions for dllimport C ++ DLL

Added copymemory support for C # in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.