(SOLVED) Problems with FFI [Racket/Scheme R6RS]

Official forum for the Chipmunk2D Physics Library.
Post Reply
Freezerburn
Posts: 2
Joined: Sun Jun 03, 2012 11:58 am
Contact:

(SOLVED) Problems with FFI [Racket/Scheme R6RS]

Post by Freezerburn »

I am honestly not sure at which point things are failing, but right now I am unable to find any of the defined functions in the chipmunk library in an FFI I am attempting to put together in Racket. (there was an older one, but it was last updated about 3 years ago)

I am using a dll I built in Visual Studio 2008 from the most recent source code. It is set to "Release DLL", with the product being a dll instead of a static library, and it is supposed to create a multi-threaded DLL. I have CHIPMUNK_FFI defined in chipmunk.h, so it is definitely getting to the MAKE_REFs. According to Visual Studio, it is going down the define path to "#define MAKE_REF(name)". (I'm pretty sure those are the most pertinent settings, let me know if you need more details)

Currently the exact error I am getting is:
ffi-obj: couldn't get "cpvadd" from "chipmunk.dll" (The specified procedure could not be found.; errno=127)
It seems to be loading the actual dll fine, as that would be a different error (which I dealt with), but it's like the functions do not exist to it.

Here is the code I am using to attempt to load the dll and function:

Code: Select all

#lang scheme

(require ffi/unsafe
         ffi/unsafe/define)

(define chipmunk (ffi-lib "./chipmunk"))
(define-ffi-definer define-chipmunk chipmunk)

(define _cpFloat _double)
(define cpFloat? real?)
(define _cpDataPointer _pointer)
(define _size_t _ulong)
(define _cpHashValue _size_t)

(define-cstruct _cpVect
                ([x _cpFloat]
                 [y _cpFloat]))

(define cpv
  (get-ffi-obj "cpvadd" chipmunk (_fun _cpVect _cpVect -> _cpVect)))
If anyone can help me out at all, I would really appreciate it. And let me know of any further details you need.
Last edited by Freezerburn on Sun Jun 03, 2012 2:31 pm, edited 1 time in total.
Freezerburn
Posts: 2
Joined: Sun Jun 03, 2012 11:58 am
Contact:

Re: Problems with FFI [Racket/Scheme R6RS]

Post by Freezerburn »

I apologize for the double post, but I figured I should put this into a separate one. I finally got it to work, and here's how I recommend someone do this if they attempt this in the future.

1) Get the chipmunk.dll file from the pymunk project. pymunk
2) Make sure the dll is in a place that your program can access it from, such as the same directory as the .rkt script file you are running. You can leave it as "chipmunk.dll", but it is likely a good idea to name it something unique so that you can be sure you are loading the correct dll.
3) When using get-ffi-obj, add an underscore in front of the function name. For example "_cpvadd", in particular when the function is defined in chimpunk_ffi.h. There might be cases where you don't need the underscore, but I haven't done much so I don't know of any, if they exist.
4) And there you go, you can start linking your Racket/Scheme code to Chipmunk.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 11 guests