Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFI Issues with Racket and Chipmunk

I am trying to use the Chipmunk physics library in Racket using the FFI that it provides. However, I am currently having issues with actually getting the FFI to find the functions in the Chipmunk library, even though it seems to load the library correctly.

I am using the most recent version of Chipmunk (6.1.1) built on Windows 8 with Visual Studio 2008. I have the "CHIPMUNK_FFI" flag set so that the chipmunk_ffi.h file is loaded. I am building the code under the Release DLL configuration with "Multi-Threaded DLL" and "Build as a dll" optoins being used. The Racket code I am using is as follows:

#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)))

And I am getting the error:

ffi-obj: couldn't get "cpvadd" from "chipmunk.dll" (The specified procedure could not be found.; errno=127)

 === context ===
C:\Program Files (x86)\Racket\collects\ffi\unsafe.rkt:180:2: get-ffi-obj*
C:\Users\me.000\AppData\Roaming\Racket\planet\300\5.2.1\cache\jaymccarthy\chipmunk.plt\1\0\chipmunk-ffi-new.ss: [running body]
C:\Users\me.000\AppData\Roaming\Racket\planet\300\5.2.1\cache\jaymccarthy\chipmunk.plt\1\0\chipmunk-new.rkt: [traversing imports]
C:\Users\me.000\AppData\Roaming\Racket\planet\300\5.2.1\cache\jaymccarthy\chipmunk.plt\1\0\main.rkt: [traversing imports]
C:\Users\me.000\Dropbox\Code\workspace-racket\learning\main.rkt: [traversing imports]

Let me know if you need any further information. I would really appreciate some help with this.

like image 480
Freezerburn Avatar asked Oct 07 '22 16:10

Freezerburn


1 Answers

Some functions (such as cpvadd are exported as _cpvadd).

See http://code.google.com/p/chipmunk-physics/source/browse/trunk/include/chipmunk/chipmunk_ffi.h

like image 82
soegaard Avatar answered Oct 11 '22 03:10

soegaard