PDA

View Full Version : Strange Newton Error


Nick
2005.05.21, 07:10 PM
I started trying to learn Newton but ran into a problem fairly quickly. When compiling I get this:

HeightFieldCollision.cpp:415: error: `assert' undeclared (first use this function) (Each undeclared identifier is reported only once for each function it appears in.)


Any ideas? I looked at the code and that line is this:

(HeightFieldCollision.cpp)
_ASSERTE (det > 0.0f);


I assumed _ASSERTE was a macro and looked for it and found this:

(stdafx.h)
#ifdef _MSC_VER
#pragma warning (disable: 4100) //unreferenced formal parameter
#pragma warning (disable: 4505) //unreferenced local function has been removed
#pragma warning (disable: 4201) //nonstandard extension used : nameless struct/union
#pragma warning (disable: 4127) //conditional expression is constant


#else
#define _ASSERTE(x) assert(x)
#ifndef min
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#endif

#ifndef asinf
#define asinf(x) ((dFloat32) asin(x))
#define acosf(x) ((dFloat32) acos(x))
#endif
#endif


My problem is that all of this is the code Newton provided. Is there something I need to do to fix this? Any help is appreciated.

NCarter
2005.05.21, 07:45 PM
Try adding "#include <assert.h>" to the affected files.

Nick
2005.05.21, 08:08 PM
I tried adding it to HeightFieldCollision.h, HeighFieldCollision.cpp, and stdafx.h (where the last of the code I posted was found) and each time I got 868 errors and 200-and-something warnings.
Thanks for the try. Any other advice?

OneSadCookie
2005.05.22, 12:02 AM
neil is correct, you need to include assert.h. Who knows whether the other errors are related. I assume this is someone else's code; I'd suggest starting with one of Will Thimbleby's examples which are Mac-centric. You should find a link by searching the forums.

Nick
2005.05.22, 08:01 AM
The problem is that he doesn't use all the Newton files. He doesn't have the stdafx.h or a bunch of the others, including the one giving me trouble. I'm sure that the other errors are related because they are mostly syntax errors on lines without syntax errors and only show up if I include assert.h. Does anyone know how to fix this problem?

NCarter
2005.05.22, 09:47 AM
On reflection, you should probably include <assert.h> in your pch (precompiled header) so that it gets included everywhere, instead of hacking at the other source files.

If you're encountering other errors, it would help if you told us what the errors are, and gave further snippets of code from the trouble spots.

It's unlikely to be the case that adding assert.h makes new errors appear; more likely those errors are concealed until you fix the initial problem. Also, as you rightly observe, most of the errors are probably a consequence of the first few errors, so you should look at those first.

EDIT: Wait, did you #define _NEWTON_USE_LIB ? Do this in your pch. If you don't, it'll all fail spectacularly.
EDIT 2: Hmm, stdafx.h defines this itself if you don't have _MSC_VER defined, so maybe you don't want to do that. However, perhaps stdafx.h isn't getting included in places where it should be, so you might not be getting _NEWTON_USE_LIB everywhere. Just something to investigate....

Nick
2005.05.22, 03:08 PM
I don't see a pch anywhere. Do I manually create this? How do I go about creating it?

I'll try some things once I get the pch thing figured out.

NCarter
2005.05.22, 03:53 PM
I don't see a pch anywhere. Do I manually create this? How do I go about creating it?
Your project doesn't already have one? If you create your project using one of Xcode's template's you should get one automatically.

If not, simply create a header with .pch as its extension and type its name into the Prefix Header slot in the target build settings. Feel free to include in this header any other standard headers that you might need. Also enable Precompile Prefix Header to get the benefit of extra compilation speed.

OneSadCookie
2005.05.22, 04:46 PM
what do you mean "he doesn't use all the newton files" -- there's only one, Newton.h, and he definitely uses that :p

willThimbleby
2005.05.22, 05:32 PM
Off the top of my head the two things that might catch you out are:
1. You need to define _NEWTON_USE_LIB before including Newton.h
2. You need to include libstdc++.a in the project

also it is probably more trouble than it is worth starting with an empty project. And as mentioned earlier, my examples are here: http://will.thimbleby.net/physics/

Nick
2005.07.13, 01:43 PM
I'm back and trying to get Newton to work. Right now I have absolutely no Newton files in my project. It's a simple SDL/OpenGL app (I used the template). I've built on it and have static meshes and a simple terrain engine. I would like to now add Newton to the mix so that my terrain actually acts like a solid object. Can someone give me a quick step by step of how to do this without getting a million errors? I already downloaded and unzipped the latest Newton files from their site. In fact I've been playing Jenga for a while now. I just want to add Newton to my project. I tried a couple of things today and still can't get it to build without errors (and I'm not even trying to use it :)).

If needed, I can put a copy of the project online later but I didn't see it as necessary now. Let me know. Thanks for all the help.

OneSadCookie
2005.07.13, 05:36 PM
add Newton.h from the SDKs folder to your project
add libnewton32.a from the SDKs folder to your project
add -D_NEWTON_USE_LIB to your target's "other c flags"
using a terminal, ranlib libnewton32.a

unknown
2005.07.13, 07:13 PM
out of intrest, what does ranlib do?

OneSadCookie
2005.07.13, 07:33 PM
updates the table of contents and modification date of the static library.

due to somebody's complete stupidity, Mac OS X static libraries contain their own modification date and the linker refuses to use them if the date according to the library is substantially different to the date according to the file system, as it will be if the file has been copied.

Steven
2005.07.13, 09:19 PM
Why doesn't someone hack the linker to automatically run ranlib? ;) (only half-joking)

OneSadCookie
2005.07.13, 10:17 PM
I was going to hack on the linker, but I couldn't even get the damn thing to compile...

Nick
2005.07.14, 12:38 AM
Thanks OSC. I never realized it was that easy. When it first came out and I tried to use it, I got a ton of errors (the original posting of this thread). Now it just compiles perfectly. Awesome-sauce (don't ask. it's a family saying I suppose).

Nick
2005.07.16, 01:26 PM
Now I have another question. I'm attempting to duplicate the first tutorial in my project. I'm having an error just starting. If I include HiResTimer.h and RenderPrimitive.h, they both come up missing. I've tried putting them into my project but they still come up missing. Any ideas?

Nick
2005.07.17, 02:08 AM
Am I the only person who's run into many errors trying to use Newton Physics? I'm considering using ODE just in hopes that I will actually be able to use it. All I'm doing is what I've seen in other projects and told to do. I did exactly what OSC told me and that worked to compile with Newton.h included and libnewton32.a in the project. Then I simply typed in the code of lesson one from Newton Physics and it didn't work. I do have #define _NEWTON_USE_LIB 1 in before including Newton.h. I've tried with and without including HiResTimer.h and RenderPrimitive.h. I've tried with and without actually having the files in the project. It's frustrating. Can anyone think of something that might be going wrong?

OneSadCookie
2005.07.17, 04:49 AM
I haven't tried to reproduce the tutorials, but I have a perfectly working GLUT + Newton program here: http://onesadcookie.com/svn/repos/ThreadedNewton/ , and Will Thimbleby has posted numerous Cocoa + Newton programs with source.

IOW yes, it's just you.