Writing a cross-platform Newton module

BlitzMax Forums/BlitzMax Programming/Writing a cross-platform Newton module

JoshK(Posted 2007) [#1]
The only thing keeping my engine from being cross-platform compatible is the Newton module. Newton is offered in versions for Windows, Mac, and Linux, and I want to learn how to write a module that will work with all three systems.

In the Windows version, I load the dll and retrieve function pointers from it. I downloaded the NewtonSDK for Mac and Linux. The Macintosh and Linux versions contain some files like libnewton32.a, but when I tried to import the .a file (in Windows), BlitzMax said "file not recognized".

I do not have access to a Macintosh, and I have never even seen Linux.

Any advice?


gman(Posted 2007) [#2]
if you have the time, i can USPS Priority you a Virtual PC 2007 image with Xandros 3.0 OCE ready to install BMAX and compile. im sure others may have images as well, but if you've never experienced linux before then you will really like Xandros. once you get the linux side down i dont think you will have much of an issue since the mac .a should operate the same. im sure if you ask around there may be several volunteers with macs to help you out... me included.

to answer your question though, the .a file essentially loads the DLL for you and provides you the function pointers so you dont have to retrieve them. so your extern block would look something like:
Import "libnewton.a"

Extern
	Function NewtonCreate:Byte Ptr( mallocfunc: Byte Ptr, freefunc:Byte Ptr)
EndExtern



JoshK(Posted 2007) [#3]
Should the Linux or Mac .a file work on Windows?

Here is my code:
Import "libnewton.a"

Extern
	Function NewtonCreate:Byte Ptr(f:Byte Ptr,f2:Byte Ptr)
EndExtern

NewtonCreate(Null,Null)


And here is the compiler output:
Building test
Compiling:test.bmx
flat assembler  version 1.66
3 passes, 2124 bytes.
Linking:test.exe
C:/Documents and Settings/Joshua/Desktop/.bmx/test.bmx.gui.release.win32.x86.o(code+0xc4): undefined reference to `NewtonCreate'
Build Error: Failed to link C:/Documents and Settings/Joshua/Desktop/test.exe
Process complete



gman(Posted 2007) [#4]
nope. the .a will only work for the corrosponding OS. for windows you will find Newton.lib. .lib files dont always work this way (depends on how the functions are exported) but the Newton.lib is compatible with GCC so you can import it straight up.


JoshK(Posted 2007) [#5]
Could someone try this on Mac or Linux? I just tested it on Windows and it works.



gman(Posted 2007) [#6]
i had to rename the stock distro libs to match your imports. i also had to run ranlib on the mac .a file. i used the following code and got a valid handle on all 3 OS (mac is an intel). i would say you are on the right track :)
Local newton:Byte Ptr=NewtonCreate(PhysicsAlloc,PhysicsFree)
Print Int(newton)

NewtonDestroy(newton)

Function PhysicsAlloc:Byte Ptr(sizeInBytes:Int)
	Return MemAlloc(sizeInBytes)
EndFunction

Function PhysicsFree(memptr:Byte Ptr,sizeInBytes:Int)
	MemFree(memptr)
EndFunction



JoshK(Posted 2007) [#7]
I don't have a Mac, so it's up to someone else to finish.


klepto2(Posted 2007) [#8]
Leadwerks: Here is my crossplattform Newton module for BMax:
http://www.btbn.de/ModServer/index.php?only_mod=klepto.newton

It is mainly based on your original module but without the need of the windows dll. Also it works unfortunatly only for MacOS 10.5 and higher (thats related to newton itself).

Feel free to use it any way you want.


JoshK(Posted 2007) [#9]
What is a .zap file?


simonh(Posted 2007) [#10]
It's a BlitzMax format - a compressed module. You have to unzap it to use it.


JoshK(Posted 2007) [#11]
And how do I do that?


JoshK(Posted 2007) [#12]
Oh, I figured it out.

Where did you find libNewtonWin32.a? All I have for Windows are .lib and .dll files. I have a beta build of Newton, so I need to figure out how to do this myself.


klepto2(Posted 2007) [#13]
Well, I have it from this address:
http://www.newtondynamics.com/downloads/NewtonMinGW-1.53.zip

And found it in this post:
http://www.physicsengine.com/forum/viewtopic.php?t=2604&postdays=0&postorder=asc&highlight=mingw&start=15

If you have a beta, I think you have to ask if it is again possilble to build a static mingw lib. Else you have to stay with the small provided .a file and provide the dll on windows.

btw: Is the beta you're testing already providing things Julio Jerez has mentioned in his posts or does it only have some things you have needed?


JoshK(Posted 2007) [#14]
Seems like there are some compatability issues there. What was the final conclusion on whether that would work or not?