RigidBody library with g++

Post Reply
cheter
Posts: 2
Joined: Wed Aug 13, 2008 12:50 am

RigidBody library with g++

Post by cheter »

Hi,

I newly started working on RigidBody SDK. I know the SDK and sample programs are tested under VC, but for various reasons I am working with mingw g++.

This is my question. I can compile the following simple code using a C compiler(gcc) but cannot compile it using a C++ compiler(g++).

Code: Select all

#include <windows.h>
#include <stdbool.h>
#include "NPRigidBody.h"

int main()
{
    RB_InitializeRigidBody();
    RB_ShutdownRigidBody();
}
"gcc test.c NPRigidBody.dll Kernel32.lib" succeeds,
while "g++ test.c NPRigidBody.dll Kernel32.lib" fails with linkage errors.
undefined reference to '_imp__Z22RB_InitializeRigidBodyv'

Since my actual project is largely written in C++, I would like to solve this problem and proceed with C++ without any painful porting. Do you have any idea about this problem?
Birch
Posts: 1139
Joined: Thu Jan 30, 2003 5:00 am
Location: Corvallis, Oregon

Re: RigidBody library with g++

Post by Birch »

We don't have experience with g++, but it would be a good idea to search for documentation on porting Visual Studio projects to g++ which might cover commonly encountered migration issues.

Also, I know its basic - I'd recommend checking the paths to make sure the linker can find everything referenced.
cheter
Posts: 2
Joined: Wed Aug 13, 2008 12:50 am

Re: RigidBody library with g++

Post by cheter »

Thank you for your suggestion, as you have guessed it was basic.

Problem: Name mangling.
g++ compiler under MinGW environment uses C++ name mangling scheme, while your compiler used C style name mangling. Thus my linker could not recognize function names in the NPRigidBody.dll file.

I solved this by changing the include statement to the following.

Code: Select all

extern "C" {
#include "NPRigidBody.h"
}
Post Reply