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!");
–
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();
–
–
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
–
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.