In-source way to call any C Library

Jacob Carlborg doob at me.com
Fri Mar 18 12:38:12 PDT 2011


On 2011-03-18 19:54, Adrian Iliescu wrote:
> Is there a way to call a C function without having to screw around with the
> linker on the command line?  In C#, for example, this is all you have to do:
>
>          [DllImport( @"..\Debug\CLibTest.dll" )]    //location
>          internal static extern int MyTestResult(); //name of function
>
>          void CSUsingCLib()
>          {
>              int result = MyTestResult(); //use it
>          }

With pragma(lib, "lib"); you can link to a library: 
http://www.digitalmars.com/d/2.0/pragma.html

And then using extern(C) as usual to declare the function. You can also 
use "dlopen" and friends on Posix and whatever the equivalent is for 
Windows.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list