Sunday, February 8, 2009

A possible future fundation for Naro

Qt jumps to LGPL for future versions. This can bring a lot of new chances for projects like Naro to use different platforms.

This weekend I had tried to make on Linux using Mono an OpenCascade project. As they were some samples using Qt 4 I wanted do see how hard is to make all runs on top of Mono. So the rules are simple: make mono to run first and create a QT application that in it's own start an OpenCascade sample.

The good news is that I had used Ubuntu 9.04 which brings OpenCascade (6.2, not 6.3 which is the latest stable) libraries in the default repository! The same about Qt and Mono development (excluding that MonoDevelop IDE package is broken but will be fixed till the final release). So it can make NaroCad to be a very Ubuntu developer friendly project.

I took a Qt4/OCC working project and I had move all code in a QMake/QT library project. The changes are pretty minimalist (mostly is to move sources around and change the template of project from app to lib). Second step was to export to a C interface and I chose to export the main method using another function namely: startMain like this:


#include "QtGuiBackEnd_global.h"

extern "C"
int startMain(int argc, char** argv);


and in cpp file:

#include "qtguibackend.h"

#include <stdio.h>

int main(int argc, char** argv);

int startMain(int argc, char** argv)
printf("hello world from lib\n");
return main(argc, argv);

After test that all compiles I did the mono work that uses P/Invoke as is explained here.

So I created a class named Starter and the code is:

using System;
using System.Runtime.InteropServices;

public class Starter
[DllImport ("/home/ciprian/Desktop/QtGuiBackEnd/")]
private static extern int startMain (int argc, string[] argv);

public static void Main(string[] argv)
Console.WriteLine("Try start");
startMain(argv.Length, argv);

The path is hardcoded but can be changed easily using a .config file but I did decide to try the minimalist path lately and viola, here is the result you see.

1 comment:

kent said...

Hi, Im a final year engineering student trying to use openCascade for my final year project. But i have failed to install OCC into linux.The error message says something about flags, and certain libraries cannot be found by occ, but i do have them on my directory. Can u give me some help on that?
my email:
Thank you