[Solved] Compile error: invalid use of incomplete type

Official forum for the Chipmunk2D Physics Library.

[Solved] Compile error: invalid use of incomplete type

Postby Droid_999 » Wed Mar 02, 2016 7:17 am

Hi

Have updated my test program to use the latest version (v7) - and now I'm getting the following errors on compile:

Code: Select all
||=== Build: Debug in para (compiler: GNU GCC Compiler) ===|
/home/x/storage/home/x/Devel/1_Current/physicsTest/Original/src/system/sys_startup.cpp||In function ‘bool sys_startOnce()’:|
/home/x/storage/home/x/Devel/1_Current/physicsTest/Original/src/system/sys_startup.cpp|111|error: invalid use of incomplete type ‘cpSpace {aka struct cpSpace}’|
hdr/chipmunk/chipmunk.h|115|note: forward declaration of ‘cpSpace {aka struct cpSpace}’|
/home/x/storage/home/x/Devel/1_Current/physicsTest/Original/src/system/sys_startup.cpp|116|error: invalid use of incomplete type ‘cpSpace {aka struct cpSpace}’|
hdr/chipmunk/chipmunk.h|115|note: forward declaration of ‘cpSpace {aka struct cpSpace}’|
/home/x/storage/home/x/Devel/1_Current/physicsTest/Original/src/system/sys_startup.cpp|119|error: invalid use of incomplete type ‘cpSpace {aka struct cpSpace}’|
hdr/chipmunk/chipmunk.h|115|note: forward declaration of ‘cpSpace {aka struct cpSpace}’|
/home/x/storage/home/x/Devel/1_Current/physicsTest/Original/src/system/sys_startup.cpp|122|error: invalid use of incomplete type ‘cpSpace {aka struct cpSpace}’|
hdr/chipmunk/chipmunk.h|115|note: forward declaration of ‘cpSpace {aka struct cpSpace}’|
/home/x/storage/home/x/Devel/1_Current/physicsTest/Original/src/system/sys_startup.cpp|125|error: invalid use of incomplete type ‘cpSpace {aka struct cpSpace}’|
hdr/chipmunk/chipmunk.h|115|note: forward declaration of ‘cpSpace {aka struct cpSpace}’|
/home/x/storage/home/x/Devel/1_Current/physicsTest/Original/src/system/sys_startup.cpp|130|error: invalid use of incomplete type ‘cpSpace {aka struct cpSpace}’|
hdr/chipmunk/chipmunk.h|115|note: forward declaration of ‘cpSpace {aka struct cpSpace}’|
/home/x/storage/home/x/Devel/1_Current/physicsTest/Original/src/system/sys_startup.cpp|131|error: invalid use of incomplete type ‘cpSpace {aka struct cpSpace}’|
hdr/chipmunk/chipmunk.h|115|note: forward declaration of ‘cpSpace {aka struct cpSpace}’|
||=== Build failed: 7 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|


This is a snippet of the code

Code: Select all
gravity = cpv(0, 2);
space = cpSpaceNew();
cpSpaceSetGravity(space, gravity);
//
// Compile stops here
ground = cpSegmentShapeNew(space->staticBody, cpv(50, 200), cpv(350, 200), 0);


In my main header file I am declaring like this:

Code: Select all
extern cpSpace             *space;
extern cpShape             *ground;
extern cpVect              gravity;


and then using them globally like this:

Code: Select all
cpSpace     *space;
cpVect      gravity;
cpShape     *ground;


I include chipmunk.h as the first include in my main header file.

This is on Linux (Debian Stretch with latest GCC compiler) and Codeblocks.

Any ideas on how to fix this?

Thanks
Last edited by Droid_999 on Thu Mar 03, 2016 5:40 am, edited 1 time in total.
Droid_999
 
Posts: 9
Joined: Sat Nov 03, 2012 5:04 pm

Re: Compile error: invalid use of incomplete type

Postby slembcke » Wed Mar 02, 2016 9:21 am

Hmm. That's odd that it's giving you an error trying to make a pointer to an incomplete struct. Are you declaring non-pointer variables of them in your C++ file? Possibly not what you meant to do.

In Chipmunk 7, instead of just saying that almost all of the struct definitions were private, I moved them to a separate header (chipmunk_structs.h) that is not normally included. You can include it if you want to access the private fields, or if the compiler needs to know the sizes of the structs because you want to inline them into to another object to avoid allocations. Importing that header should fix the issue, though it's probably because you have non-pointer variables of those types?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Compile error: invalid use of incomplete type

Postby Droid_999 » Wed Mar 02, 2016 3:43 pm

Can't see that file (chipmunk_structs.h) anywhere.

Code: Select all
-rw-r--r-- 1 user user  3093 Jul  3  2015 chipmunk_ffi.h
-rw-r--r-- 1 user user  9511 Jul  3  2015 chipmunk.h
-rw-r--r-- 1 user user 18547 Jul  3  2015 chipmunk_private.h
-rw-r--r-- 1 user user  6599 Jul  3  2015 chipmunk_types.h
-rw-r--r-- 1 user user  2934 Jul  3  2015 chipmunk_unsafe.h
-rw-r--r-- 1 user user  8853 Jul  3  2015 cpArbiter.h
-rw-r--r-- 1 user user  5503 Jul  3  2015 cpBB.h
-rw-r--r-- 1 user user  9531 Jul  3  2015 cpBody.h
-rw-r--r-- 1 user user  4808 Jul  3  2015 cpConstraint.h
-rw-r--r-- 1 user user  3112 Jul  3  2015 cpDampedRotarySpring.h
-rw-r--r-- 1 user user  3599 Jul  3  2015 cpDampedSpring.h
-rw-r--r-- 1 user user  2134 Jul  3  2015 cpGearJoint.h
-rw-r--r-- 1 user user  2620 Jul  3  2015 cpGrooveJoint.h
-rw-r--r-- 1 user user  1427 Jul  3  2015 cpHastySpace.h
-rw-r--r-- 1 user user  1669 Jul  3  2015 cpMarch.h
-rw-r--r-- 1 user user  2522 Jul  3  2015 cpPinJoint.h
-rw-r--r-- 1 user user  2415 Jul  3  2015 cpPivotJoint.h
-rw-r--r-- 1 user user  2713 Jul  3  2015 cpPolyline.h
-rw-r--r-- 1 user user  3208 Jul  3  2015 cpPolyShape.h
-rw-r--r-- 1 user user  2458 Jul  3  2015 cpRatchetJoint.h
-rw-r--r-- 1 user user   569 Jul  3  2015 cpRobust.h
-rw-r--r-- 1 user user  2403 Jul  3  2015 cpRotaryLimitJoint.h
-rw-r--r-- 1 user user  9272 Jul  3  2015 cpShape.h
-rw-r--r-- 1 user user  1976 Jul  3  2015 cpSimpleMotor.h
-rw-r--r-- 1 user user  2927 Jul  3  2015 cpSlideJoint.h
-rw-r--r-- 1 user user 17142 Jul  3  2015 cpSpace.h
-rw-r--r-- 1 user user  9856 Jul  3  2015 cpSpatialIndex.h
-rw-r--r-- 1 user user  5624 Jul  3  2015 cpTransform.h
-rw-r--r-- 1 user user  6585 Jul  3  2015 cpVect.h
user@metabox:~/Libraries/Chipmunk-Physics/Chipmunk-7.0.1/include/chipmunk$
Droid_999
 
Posts: 9
Joined: Sat Nov 03, 2012 5:04 pm

Re: Compile error: invalid use of incomplete type

Postby Droid_999 » Wed Mar 02, 2016 4:58 pm

Interestingly chipmunk_structs.h is available from github - but it's not included in the file 'ChipmunkLatest.tgz" downloaded from the front page.

I'll try using a GIT copy and see what happens.
Droid_999
 
Posts: 9
Joined: Sat Nov 03, 2012 5:04 pm

Re: Compile error: invalid use of incomplete type

Postby Droid_999 » Thu Mar 03, 2016 5:40 am

Downloaded the source from GIT, and adding #include "chipmunk_private.h" solves the problem.

Compiles now.
Droid_999
 
Posts: 9
Joined: Sat Nov 03, 2012 5:04 pm

Re: [Solved] Compile error: invalid use of incomplete type

Postby slembcke » Thu Mar 03, 2016 11:32 am

Hmm. I guess I haven't done a release since I made that fix. Whoops. I'll put it on the TODO list I guess...
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 2 guests