Calendar

July 2014
Mo Tu We Th Fr Sa Su
<< >>
123456
78910111213
14151617181920
21222324252627
28293031

Langs

Haxe 2.04 with C++ support

Posted on Jul 26 2009

Today Haxe 2.04 was released.

Thanks to the hard work of Hugh Sanderson, Haxe now have support for the C++ platform.

It then mean that you can compile any Haxe program directly to C++, and get the performances of the one of the world fastest languages ! C++ support open also a lot of new possibilities for Haxe targets, including huge progress on running Haxe on iPhone

In order to use the C++ platform, you will have to use the -cpp target, but before that you need to install the hxcpp library that contains all things needed to compile. This is easily done by running the following command :

haxelib install hxcpp

Now, you can simply write a small Haxe program :

class Test {
    static function main() {
        trace("Hello World !");
    }
}

And compile it with :

haxe -cpp out -main Test

This will give you a file out/Test.exe that when run will simply display Hello World.

Easy, isn't it ?

In order to go further, you can use the APIs that have been made accessible from Haxe/C++, they are fully listed on the Haxe API pages.

It's of course possible to interoperate with other C++ programs, but these details will be soon documented.

Actually, C++ is the 6th platform supported by Haxe, since there is already :

  • Flash (for Flash Player versions <=8)
  • Flash9 (AVM2, for Flash Player versions >= 9)
  • Javascript
  • Neko
  • PHP
  • ... and now C++

Which will be next one ? ;)

24 comments
  • Jul 26, 2009 at 20:24

    Maybe objective-c for iphone? :)

  • Jul 26, 2009 at 20:58

    Python and Java should be interesting :)

  • Jul 26, 2009 at 21:08

    Oh, maybe not a new language but a RIA framework in haxe?
    So that we can build a single haxe project and compile into a complete RIA with both server side and client side.

  • Jul 26, 2009 at 21:14

    .Net may be :D

  • Jul 27, 2009 at 01:30

    >> zproxy
    Iphone can execute c++ code natively (they compile to the same think) so objc isnt really needed. Thats how iphone i already supported.

  • Dave
    Jul 27, 2009 at 03:57

    I thought this was already available (iphone)

    http://gamehaxe.com/2009/05/22/haxe-on-iphone-simulator/

  • Jul 27, 2009 at 04:05

    A wonderful job! Thanks to everyone who worked on this, I'm really excited about this release!

  • est
    Jul 27, 2009 at 12:06

    Hi, I am using VC7's cl.exe, here's the error:

    hxObject.h(129) : error C2785: “double hxMod(TL,TR)” and “int hxMod(int,int)” have different return types

  • Jan
    Jul 27, 2009 at 17:07

    python and ruby =)

  • Draetsch
    Jul 27, 2009 at 23:58

    Great news indeed!
    Does someone else have the error "no compiler defined" on osx?
    What am I missing?

    Cheers!

  • Jed Adams
    Jul 28, 2009 at 07:02

    Draetsch it sounds like you don't have xcode / dev tools installed
    just grab the iphone sdk and you should be good to go

  • Draetsch
    Jul 28, 2009 at 07:17

    Thanks for your answer.

    I have XCode installed. Version 3 and GCC 4. Is that the problem?

  • AMIN
    Jul 28, 2009 at 09:09

    How abount using CPP API from Flash or using Flash API from CPP
    add Python i think in will bee great

  • amin
    Jul 28, 2009 at 10:46

    how abount compile with MinGW

  • ゆく
    Jul 28, 2009 at 14:17

    Wow finally we have a new release with new features!

  • erunaamo
    Jul 29, 2009 at 15:09

    The latest version of haxe seems to break the current version of swhx:

    /usr/local/lib/haxe/lib/swhx/1,2,0/swhx/Plugin.hx:93: characters 14-31 : haxe.#Http has no field request

    (Because request has been renamed requestUrl, according to haxe's change log - making that name change in Plugin.hx seems to fix it.)

    Time for a new release of swhx, I guess?

  • erunaamo
    Jul 29, 2009 at 15:20

    @Draetsch: I got the "no compiler defined" error on Mac OS X too. I was able to solve that by doing 'export OSTYPE="darwin"' before trying to compile, but I still couldn't get it to work, so far.
    It might be better to use a different OSTYPE and add to the haxecpp configuration files: It looks like the only Mac configurations 'haxe -cpp' understands are for the iPhone SDK. I'm using gcc 3 on OS X 10.3.9 and apparently it's not compatible: haxe generates the c++ source fine, but it seems haxecpp and gcc 3 don't get along. All sorts of unrecognized flags and inscrutable errors.

  • Draetsch
    Aug 01, 2009 at 14:29

    @erunaamo: Thanks for the tip with the ostype. I will try that too. Your experiences tell me, that it has nothing to do with the compiler version. I want to try, if I really need the iPhone SDK installed, because I only have the standard developer tools.

  • pix'nlove
    Aug 01, 2009 at 19:24

    I have downloaded this haxe as I have been waiting for it for a while now, by my mne no longer work ;( the following appear:
    Could not link plugin to process (hxCFFILoader.h 48)

    And when I try to complile with Cpp I get the following:

    haxelib run hxcpp Build.xml haxe -Dcpp -Dhaxe_204 -Dnme -Dtrue
    cl.exe -nologo -O2 -MT -DHX_WINDOWS -GR -Zi -c -EHsc -IC:\Program Files\Motion-T
    win\haxe\lib\hxcpp\1,0,2//include -D_CRT_SECURE_NO_DEPRECATE -wd4996 -Iinclude .
    /src/Hash.cpp -Foobj/Release/src/Hash.o
    'cl.exe' is not recognized as an internal or external command,
    operable program or batch file.
    Called from <null> line 1
    Called from BuildTool.hx line 611
    Called from BuildTool.hx line 292
    Called from BuildTool.hx line 315
    Called from BuildTool.hx line 379
    Called from BuildTool.hx line 106
    Uncaught exception - Error : 1 - build cancelled
    Error : Build failed

    I Switch back to haxe 2.03 and everything work perfectly :(

  • Aug 03, 2009 at 20:30

    cl.exe is the C compiler which is part of Microsoft Visual Studio. You need to setup a C compilation environment before being able to use Haxe/C++

  • Aug 04, 2009 at 05:26

    I second the previous mentions on adding Python support :)
    A lot of valuable applications have Python plugin support which is a great feature and can be a great time saver, but learning yet another language...ugh, well you know...
    If Haxe were to target it, what a joy it would be :)

    Again, thanks for all the hard work.

  • Fuse
    Dec 05, 2009 at 19:37

    Supporting Java would be great too, we could make both a SWF file, a Java Applet and a JavaScript file from the same source code. In addition, it would enable us to target Google Android or any mobile phone that has Java Micro Edition installed.

  • George
    Mar 19, 2010 at 18:42

    Has anyone managed to load in custom c++ classes and libraries? It should be possible by the looks of things - I'm really interested in getting ARToolkit going under this

  • Spencer
    Jun 23, 2010 at 13:46

    I have installed Microsoft Visual C++ 6 and cl.exe works via command-line
    Also I have hxcpp 2,05,1 and haxe 2.05

    Main.hx
    -----------------------------------------------------
    package ;

    import cpp.Lib;

    class Main
    {

    static function main()
    {
    Lib.println("Hello World!");
    }

    }
    --------------------------------------------------

    I ran this

    C:\Documents and Settings\elemen3\Desktop\test_test>haxe -cpp out -main Main

    I got this

    haxelib run hxcpp Build.xml haxe -Dcpp -Dhaxe_205 -Dtrue
    cl.exe -Iinclude -nologo -O2 -MT -DHX_WINDOWS -GR -Zi -c -EHsc -IC:\Program File
    s\Motion-Twin\haxe\lib\hxcpp\2,05,1//include -D_CRT_SECURE_NO_DEPRECATE -wd4996
    -Ychxcpp.h __pch.cpp /Fphxcpp.pch
    Command line warning D4002 : ignoring unknown option '-wd4996'
    __pch.cpp
    C:\Program Files\Motion-Twin\haxe\lib\hxcpp\2,05,1//include\hxcpp.h(47) : fatal
    error C1189: #error : MSVC 7.1 does not support template specialization and is
    not sopported by HXCPP
    Called from <null> line 1
    Called from BuildTool.hx line 840
    Called from BuildTool.hx line 433
    Called from BuildTool.hx line 456
    Called from BuildTool.hx line 529
    Called from BuildTool.hx line 556
    Called from BuildTool.hx line 125
    Uncaught exception - Error creating pch: 2 - build cancelled
    Error : Build failed

    What's wrong?!!1

Name : Email : Website : Message :