添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
有情有义的菠萝  ·  Laravel - ...·  6 月前    · 
销魂的风衣  ·  《Exploring in ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm getting to know Mono development in Linux, in baby steps. I'm trying to call Linux C libraries. This page , in theory, tells me how, but when I type the code below in MonoDevelop 2.2.2 (Fedora 13), I get a "Parsing Error (CS8025)" in "private static extern int getpid();". Moreover, the help system doesn't work.

using System;
using System.Runtime.InteropServices;
[DllImport("libc.so")]
private static extern int getpid();
namespace LinuxCaller
    class MainClass
        public static void Main (string[] args)
            Console.WriteLine ("Hello World!");
                Please don't edit your question to include the correct answers by removing the problem code. It then becomes useless to others years later..
– IanNorton
                Jan 11, 2012 at 19:42

Function definitions cannot appear in the namespace scope in C#. This includes DLL import definitions. To fix this just move the function definition inside a type.

class MainClass {
  [DllImport("libc.so")]
  private static extern int getpid();
                Yes, but intriguingly, it only has 238 bytes. Eek. It contains just some text! I used "libc.so.6" instead and it works now.
– JCCyC
                Aug 27, 2010 at 17:59
                @IanNorton - Do you have a reference for this shortcut?  Does it work uniformly on linux/mac/windows?
– Matt Johnson-Pint
                Dec 17, 2012 at 23:38

If you just need to access some common *nix system calls, check out the Mono.Unix namespace which provides wrappers around a lot of functions.

http://www.go-mono.com/docs/index.aspx?link=N%3aMono.Unix

Actually what I need is to call some UNcommon functions in third-party libraries, but that is indeed useful information. – JCCyC Aug 27, 2010 at 18:02

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.