Using Max code in XCode

Archives Forums/MacOS X Discussion/Using Max code in XCode

ImaginaryHuman(Posted 2006) [#1]
Is it possible to write some application or piece of application in BlitzMax and then include it in an Objective C XCode project, to compile it XCode?

Or vice versa?


Winni(Posted 2006) [#2]
You can import .m (Objective-C) files directly into your BlitzMax code, if I am not mistaken. It works with .c files, but in the end they all use the same compiler.

The other way around, you will probably run into problems, because I presume that BlitzMax files will have to link against the BlitzMax runtime, and Xcode will not "know" how to do that. But there are more competent folks around here to answer that kind of question.


ImaginaryHuman(Posted 2006) [#3]
I managed to get Max to import a .m file and compile, but it won't link fully.


Retro(Posted 2006) [#4]
Seems to me there would be basically two ways to go about it:

(1) Create an Application Framework from precompiled BMax modules (or just Add them to the Project as individual libraries).

(2) Modify the Target build rules to invoke BCC instead of GCC for all BMax source modules added to the Project.


ImaginaryHuman(Posted 2006) [#5]
Does a module get compiled differently than a regular blitz app somehow? How can bitz be used to make a `library?`


ImaginaryHuman(Posted 2006) [#6]
I created the below test module:
Strict
Module angeldaniel.ctest
ModuleInfo "Version  : 1.00"
ModuleInfo "Author   : Paul West (AngelDaniel)"
ModuleInfo "Internet : none"
ModuleInfo "License  : Copyright (c) 2006 Paul West"

ModuleInfo "History  : 1.00 Initial test version"

Import brl.basic
Import brl.blitz
Import brl.filesystem


Function Test()
	Local a:TStream = WriteFile("angeldanieltest.txT")
	WriteLine(a,"Hello World")
	CloseStream(a)
End Function

I rebuilt the modules. I restarted. I reloaded blitzmax. By doing:
import "angeldaniel.ctest"
Test()

the module code works and writes the file. So the module itself is okay.

Then I created a new screensaver framework in XCode. I dragged the ctest.release.macos.ppc.a file into the `Frameworks and Libraries` section in XCode, under Frameworks and Libraries > Other Frameworks, after the foundation.framework and application.framework, and copied the file into the app's folder.

I then went into the target for the screensaver and added a `rule` that says that any files whose name matches *.a performs a custom script, and in the custom script line I put "bcc". I made a copy of `bcc` itself and put it in the developer/tools folder. Not sure if I have to specify a path here? Also do I put a path for where the output files go? Does bcc need some command line parameters? How should that appear as `script`?

I put a line in the PaulSaver.m file that says:

void extern Test(void);

right after the #import "paulsaverview.m"

(not sure if this is the right way of making the blitz function available for use? Does this define it as a prototype or as an actual function?)

When I try to compile the XCode screensaver at this point, it almost gets there but has one error with regards to the .a file:

PaulSaver:0: can't locate file for: -lctest.release.macos.ppc

I don't know what this means, what file is trying to be referenced or where.

As such the app fails to compile all the way.

Is there anything I need to do with the ctest.release.macos.ppc.i file?

If anyone could help with clarifying what each step needs to be to get this working right I'd really appreciate it. I haven't really used XCode before.


Retro(Posted 2006) [#7]
Bear in mind that your ctest module is importing three other BRL modules, none of which you have added to your Xcode project. The functions you are calling in Test() are all external references, which the linker won't be able to resolve - likewise if they in turn reference anything else in other modules. It's probably easier in the long run to add the whole lot of them to your project - or perhaps even better, to combine them into a single framework.

You don't need a script for your .a files because they're already compiled. You only need to define a build rule if you add .bmx sources, so that Xcode will know how to compile them. The .a files are archive files, which are simply libraries of individual object files. See the Unix binutils doc for the "ar" utility.

The exported symbol for your function won't be "Test". It'll be something like "_angeldaniel_ctest_Test". However, you can rename it with a prototype in your ObjC source code or header.


ImaginaryHuman(Posted 2006) [#8]
Did I define the Test() function as an extern correctly in the ObjC file, other than the name of it?

And when I include all of the referenced imported files, do they have to have a directory structure the same as the mod/ folder or just all in the same folder?

And do I have to put ALL possible referenced imported file from blitz into the xcode app before it can compile?

And to make a framework of it all, would I just copy the whole mod/ folder or something to the xcode app as a framework?


ImaginaryHuman(Posted 2006) [#9]
Man, I'm still not quite getting this. I must be doing something wrong still.

I removed the .a files that I'd inserted into the project and then I dragged over the entire mod folder from blitzmax into the project, under `other frameworks`. This seems to remove the message that was saying a file could not be found. But now the message is "undefined symbol _angeldaniel_ctest_Test()" ... and I've taken out the leading underscore in void extern angeldaniel_ctest_Test(void); and in angeldaniel_ctest_Test(); but it's putting a leading _ there and not finding it.

What would be great, if you have time, is to go through the steps of putting this module into a new XCode screensaver project, and telling me all the steps to reproduce it to get it running. That would be great, but I understand it's a tall order.

Thanks for your help so far.


ImaginaryHuman(Posted 2006) [#10]
I'm wondering if there's a different way of going about this whole thing. Isn't is possible to have everything centric around BlitzMax, ie include any necessary files into blitzmax and and have blitz compile the exe, then somehow put together a bundle, avoiding xcode altogether?

One problem I see is trying to use .nib interfaces from blitzmax, or getting maxgui to act the same within the screensaver prefs.

I am thinking I might give up on mac screensavers, it's definitely not very straightforward, and just churn out a `demo` production. Or maybe a bare bones xcode screensaver that executes an external file as a `blitz launcher` and then separate windows for configuration and preview rather than the system ones? Not exactly ideal though.

Pity because there's working code for Windows screensavers that's much easier to deal with. Pity #2 that I don't have regular PC access to test and compile stuff.


Retro(Posted 2006) [#11]
Dude, you give up too easily. There's no reason why this cannot be made to work and I'm determined to get it going because it's something I've been meaning to do myself for some time. I'd be surprised if nobody else has managed to use Xcode as an IDE for Blitz Max up until now, or at least looked into it, given the limitations of the Blitz IDE and the obvious advantages of doing all development work from within Xcode.

In reply to some of your questions, just copying the entire Blitz modules directory into your project won't work. It's a proprietary BRL structure which Xcode knows nothing about - unless you also define individual search paths (for the linker) to each folder containing a module library. Sure you can compile it ok, but the error messages you're getting are coming from the linker. It needs to locate each and every externally referenced symbol in order to build the target.

I have built two private frameworks: brl and pub, from the respective Blitz module directories. I think this is the best way to go, as you can set up dependencies in Xcode to rebuild them as targets whenever the Blitz modules are synchronized (your project in turn declares them as dependencies).

The only potential problems I see are the limitations of the interface between C/C++/ObjC and Blitz, i.e. the calling conventions etc, for which very limited documentation has been supplied. I need to take a good look at the source code, particularly for BMK. Also, the startup code for the Blitz runtime may need to be extracted or made externally accessible, so that it can be initialized by the host application.

I'll be working on it over the next few days whenever I can find some time and I'll post some more when I have anything. If I can get it all working, then on to the real challenge - fully integrating the Xcode debugger.


ImaginaryHuman(Posted 2006) [#12]
Hi Smith.

Yah well, I have zero experience with XCode and I'm by no means one to give up, nor am I generally a beginner in Blitz circles, but I really have reached the limits of my understanding of XCode and how all this combining and setting up needs to happen. Perhaps you'll be willing to post some kind of basic tutorial once you're doing figuring it out so that the community can get started making mac screensavers. That would be awesome.


ImaginaryHuman(Posted 2006) [#13]
Any progress on this yet?


skidracer(Posted 2006) [#14]

I managed to get Max to import a .m file and compile, but it won't link fully.


it's likely you will need to import a framework or two, in cocoagui i needed the following for example
Import "-framework WebKit"

If you can make a framework project from xcode it would be interesting to see if you can import those also. Would make a lot more sense than trying to learn xcode by building hybrid projects that end.


ImaginaryHuman(Posted 2006) [#15]
I'm mainly just trying to make a Mac screensaver that is recognized by the system as real screensaver and operates correctly and let me use as much BlitzMax code as possible. I just don't see how it has to be done.