I am on Windows.
I downloaded the latest source from here: https://github.com/slembcke/Chipmunk2D and unzipped it.
I opened up the Chipmunk2D-master folder in VSCodium and used the CMake Tools extension to configure and then build the project. It completed successfully.
The Demo program was created and runs fine.
the build/src folder was created containing:
cmake_install.cmake
libchipmunk.a
libchipmunk.dll
libchipmunk.dll.a
Makefile
I copied libchipmunk.dll to my project's folder.
For context on the project, I was previously compiling the library's source directly with my own code. Everything was working fine except for the clunkyness of having chipmunk's 30+ .c files in my makefile. So basically all of this is just an attempt at doing it "correctly" and using the DLL.
I changed all the chipmunk #includes in my code from relative paths to #include <chipmunk.h>
, and added to the makefile:
-IC:/path/to/Chipmunk2D-master/include/chipmunk
-LC:/path/to/Chipmunk2D-master/build/src
-lchipmunk
at their appropriate places. Attempting to compile the project with minGW throws dozens of linker errors like undefined reference to `cpBodySetVelocity'
, one for each chipmunk function called in my code.
here's the compilation command:
gcc my_sources.c
-IC:/SDL/SDL2-2.26.4/i686-w64-mingw32/include/SDL2
-IC:/path/to/Chipmunk2D-master/include/chipmunk
-LC:/SDL/SDL2-2.26.4/i686-w64-mingw32/lib
-LC:/path/to/Chipmunk2D-master/build/src
-lmingw32 -lSDL2main -lSDL2 -lchipmunk
-o MyProject
I've inspected the .dll and the names are all in there. I've triple checked spellings, everything. Any insight is appreciated.
reddit user skeeto figured it out for me:
https://www.reddit.com/r/C_Programming/comments/1fagx4c/linker_problems_trying_to_compile_with_the/
I was mixing 32 and 64 bits toolchains. VSCode compiled the chipmunk dll in 64 bits (I wasn't aware of this. That was my problem.), but for my project I was compiling with mingw32-make, and the 32 bit SDL package. I switched to mingw-W64 to compile and swapped in 64 bit SDL, and it all worked fine.