tags:

views:

59

answers:

1

I'm attempting to P/Invoke a C library from F#, and have encountered a peculiar issue. I have a module containing all my extern functions. The underlying C library has two functions with the same name, but different arguments. This, of course, is not allowed in an F# module.

module C =

  open System.Runtime.InteropServices

  [<DllImport("libc", CallingConvention = CallingConvention.Cdecl)>]
  extern int setValue(nativeint source, int value)

  [<DllImport("libc", CallingConvention = CallingConvention.Cdecl)>]
  extern int setValue(nativeint source, string value)

  // the previous function declaration cause the following compile-time error:
  // Duplicate definition of value 'setValue'

Is there some special way to work around this? I can not alter the C library.

+6  A: 

The EntryPoint attribute should work (e.g. with an ordinal), if MSDN can be trusted (haven't tested in F#). Name your imported functions e.g. setValueInt() and setValueString().

Pontus Gagge
Thanks. I'm new to this whole P/Invoke scene.
pblasucci