Home  >  

Getting Started With Adobe Alchemy

Author photo
AddThis Social Bookmark Button

With the ability compile C and C++ code and leverage it via ActionScript, Adobe's project Alchemy should be on your radar. If you haven't heard of it yet, here's a direct quote from Alchemy's labs page giving a little more description:

“With Alchemy, Web application developers can now reuse hundreds of millions of lines of existing open source C and C++ client or server-side code on the Flash Platform. Alchemy brings the power of high performance C and C++ libraries to Web applications with minimal degradation on AVM2. The C/C++ code is compiled to ActionScript 3.0 as a SWF or SWC that runs on Adobe Flash Player 10 or Adobe AIR 1.5.” via Adobe Labs

So, let's jump right into the nitty-gritty and get Alchemy setup so you can start compiling some C code.  I will be running through the steps for setting up Alchemy on a Windows machine, so some of this may be different depending on your platform.

Start by heading to Alchemy's download page and pick up the correct Alchemy download package for your platform.  Once the download completes, unzip the archive.  I unzipped my archive to C:\alchemy so that in the folder 'alchemy' are all the files that were inside the 'alchemy-cygwin-v0.5a' folder.  

Now head over to Cygwin (Direct EXE Download) and pick up their command line tool so we can execute Linux like commands.  Start the installation process and when you reach the package selection screen, select the following packages (do so by clicking the refresh looking icon next to each package):

  • Perl (1st image)
  • Archive->zip (2nd image)
  • Devel->gcc-g++ (3rd image)

perl.jpg

zip.jpg

gcc.jpg

Once you've selected those packages, finish the installation process.  The installation may take some time, depending on the download speeds you get from the mirror you choose.  I would recommend against the "www.very-clever.com" mirror since the two times I used it I got 4kb download speeds!  So, it took about 2 hours to download and install, which was very painful.  Also, once Cygwin is installed completely, move the setup.exe and any folders it produced to the C:\cygwin folder. 

While that is downloading, lets make sure you have Java installed.  Go to Start->My Computer->Local Disk->Program Files, and you should see a Java folder in there.  If you don't, head to the Java download page and download and install the latest "Java SE Runtime Environment".  Make sure this is done before installing Cygwin, otherwise restart Cygwin after you install Java.

So, now you should have Alchemy downloaded and unzipped to your hard drive, Java downloaded and installed if it wasn't already, and Cygwin downloaded and installed with the above packages added.  Next we need to get the Flex SDK if you don't have it already, which can be found here under "Adobe Flex SDK" (The first listed, the largest package): http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+3. Go ahead and just grab a Milestone Release Build, unless you're feeling a little daring ;) Make sure you unzip the archive into a folder that will not be moved or deleted.  I added it to my C:\ drive where both alchemy and cygwin are sitting, example: C:\FlexSDK.

Let's now add the source path to achacks, and the Flex SDK bin folder to Cygwin's path.  Go to Cygwins home folder (for me C:/cygwin), then open the 'etc' folder and open up the file "profile".  Open the file in real text editor, otherwise saving the file may change the file structure and you'll get errors.  Find the following:

PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:$PATH. 
Change it to:

source /cygdrive/c/alchemy/alchemy-setup
PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/cygdrive/c/alchemy/achacks:/cygdrive/c/FlexSDK/bin:$PATH

Make note that it should become two lines.  You'll need to change the path names if they aren't the same as yours.  Remember that '/cygdrive/c/' for me stands for 'C:/'.  Save the file and open Cygwin.  Navigate to your Alchemy folder using the cd (change directory) command.  For me, the command looks like so:

cd C:/alchemy
Now that we're in the proper directory, run the following command:

./config
You should see something similar to this, but if you see warnings or errors about adl.exe, make sure your Path is correct to the bin directory in the FlexSDK folder from the PATH above.

config_ActiveWindow.png

Now go to your Alchemy folder on your hard drive and open the alchemy_setup file.  Look for this line

#export ADL=/path/to/your/adl (or adl.exe)
Replace the entire line including the pound sign (#) with the following:

export ADL=/cygdrive/c/FlexSDK/bin/adl
Make sure to change the path to reflect your path to the Flex SDK adl.  Also, just above this line you should see:

export ASC=$(cygpath -m -s -p $ALCHEMY_HOME/bin/asc.jar)
I had to change that to read:

export ASC=$ALCHEMY_HOME/bin/asc.jar
Now make sure everything is saved and close Cygwin then re-open it.  Change to the Alchemy/bin directory by using cd (change directory) command:

cd C:/alchemy/bin
Run the following command:

ln -s llvm-stub llvm-stub.exe
Now change to the Alchemy/samples/stringecho by running the following command (if you're still in the Alchemy/bin directory:

cd ../samples/stringecho
This basically says, go back one directory and look in samples for stringecho folder.  If you're not in the bin directory, use the full path.  Before compiling we need to turn alchemy on by running the following command:

alc-on;
Now type in the following command to compile the sample:

gcc stringecho.c -O3 -Wall -swc -o stringecho.swc
You should see something similar to this

compiled.png

If you do see something similar to the above, congratulations!  You have a working install of Adobe's Alchemy!  Let's finish this up by compiling the sample.  We should already be in the Alchemy/samples/stringecho folder, so let's get into the 'as3' folder.  Do so by again using the cd command "cd as3".  Now type the following and hit enter to compile the source:

mxmlc.exe -library-path+=../stringecho.swc --target-player=10.0.0 EchoTest.as
That should have spit out an EchoTest.swf in the as3 folder.  If you run the SWF in the debug player, it will trace "foo".  The next article will explore Alchemy a little deeper when we create our very own first Alchemy project.  Keep in mind each time you open a Cygwin terminal, before compiling with gcc you should turn "alc-on;".

Thanks for reading!

Read more from Damon Edwards. Damon Edwards's Atom feed desktube on Twitter

Comments

23 Comments

zedia.net said:

Looks fairly easy, thx for the instructions.

So ... Alchemy is a designer tool?

Thanks for reading!

I wouldn't really say it's a designer tool, but it's a tool for anyone that wants to compile C/C++ libraries into usable SWCs.

Devon O said:

after installing cygwin as you describe, when I execute the ./config command I get ERROR: "perl" not available. I reinstalled the Perl package and restarted the pc and get the same thing. Is there something else I'm missing? Thanks for the article. Really like to get this up and running.

Hi Devon, I really can't say for sure what's happening. My first instinct would be to completely remove cygwin from my computer, and restart the process making sure the Perl package is selected, along with zip and gcc. Maybe even try installing from a different mirror, and keep an eye on the install process for any errors.

Graham Phillips said:

to Devon... I haven't followed this tutorial yet, just the instructions from Adobe. After installing Cygwin on WinXP I tried to verify installation by running gcc but got a command not found error. I assumed I had made a mistake, but on looking through the installed libraries it showed gcc was there. I thought I'd have to uninstall/reinstall Cygwin, and was worried I'd be left with a corrupt installation. I fiddled around a bit, selected/deselected gcc and related components, rebooted, gave it another try and found it worked ok. Perhaps it was the reboot, as I didn't change anything.

ajitpals said:

alc-on; command is not running, actually i'm just writing, {alc-on;} and its say command don't exit. Could you plz tell me the reason

ct said:

Thanks for the write up.

Devon O said:

@Damon & @Graham Thank you for the suggestions, but it turns out I made a stupid mistake and included a space in the directory name that contained my Flex SDK. Curse Windows for allowing such bad habits. Only admitting such a silly user error in case anyone else does the same. Thanks again for the help and for this article.

Pablo said:

I'm seriously expecting that next article of Alchemy, creating the first alchemy project and so..

Pablo said:

I expect to see sooner than later that second article about Alchemy, sounds at least as interesting as this first one

Hi Pablo, thanks for reading. I haven't had the time to start the second article yet, but there will be one in due time!

MAH said:

I had a few issues getting things set up, and I'm still not quite there. To get to where I am though, I had to edit the /etc/passwd file and set my ID from 1000 to 544 so I could get permissions to the files. (I'm running Vista 64, but I don't know if that matters.)

I had to modify my /etc/profile to place the source command _after_ setting up the path, since the file being sourced needed a valid path to do its thing.

I've been able to compile stringecho.c to stringecho.swc (but my output only showed the warning, nothing else).

Where I'm stuck: the past part... the mxmlc command. When I try this, I'm given an error indicating that the JRE cannot be found, though I've installed it already. I've closed and restarted cygwin (the bash shell, that is), but it hasn't picked up what it needs (and even in a normal dos window, there are no environment variables I might expect, like CLASSPATH and JAVA_HOME. I tried setting those two within cygwin, but it didn't change anything.

pallzoltan said:

really really cool
looking forward to part 2, curious what it will bring :)

Dave Harrison said:

Thanks for this Damon.
I seem to have gone through with no problems except that I get no trace output from the swf. I'm using the debug players and have tested on firefox, chrome, and ie, with no luck. Any ideas?

Thanks
Dave

Jason said:

My alias' are not being created properly.
The installation seems to go smoothly (no errors, everything looks the same as yours) until I get to the step where I need to use:
alc-on;
at which point I get:
bash: alc-on: command not found

Everything seems to have worked, so I am not sure where the problems is occurring. Any help would be appreciated.

Here is my alchemy-setup...I'm not sure if it will help.
Thanks again.

#
# NOTICE: Adobe permits you to use, modify, and distribute this file in
# accordance with the terms of the Adobe license agreement accompanying it.
# If you have received this file from a source other than Adobe, then your use,
# modification, or distribution of it requires the prior written permission of Adobe.
#

# Add Alchemy settings to your environment
export ALCHEMY_HOME=/cygdrive/c/alchemy/alch
export ALCHEMY_VER=0.4a
export PATH=$ALCHEMY_HOME/bin:$PATH
export ASC=$ALCHEMY_HOME/bin/asc.jar
export SWFBRIDGE=$ALCHEMY_HOME/bin/swfbridge.exe

# Set this variable if you do not want to use the adl executable from your path
export ADL=/cygdrive/c/flex/adl (or adl.exe)

# Uncomment this if you want to leave intermediate build products around for debugging
# Leave this off if you are not actively debugging as these can be large
#export ACHACKS_TMPS=1

# Uncomment this to turn on logging when building with achacks
#export LOG=1

# Uncomment this as set the LOGLEVEL to enable additional runtime logging
# Higher values mean more information is logged. 1, 2, 3 are defined currently.
# NOTE This must be set when your project is compiled
#export LOGLEVEL=1

# These are helper functions
alias alc-home='cd $ALCHEMY_HOME'
alias alc-on='export PRE_ALCHEMY_PATH=$PATH; export PATH=$ALCHEMY_HOME/achacks:$PATH'
alias alc-off='export PATH=$PRE_ALCHEMY_PATH'

Chris said:

when trying to run the ./config I get an Error: "java" not found.
I have jre6 installed and have rebooted and still get the error.
Please help this is driving me nuts.

Bhanu said:

hi,

thanks for your post. Can we use sound api in c++ for recording the microphone input on local hard disk

Thanks,

Bhanu

Jason said:

No need to answer my question above.
This line:
export ADL=/cygdrive/c/flex/adl (or adl.exe)

Obviously needed the "(or adl.exe)" removed....

Great tutorial.

Leo Fang said:

Hi, Can you tell me how to compile multiple c source files in alchemy?
My alchemy was installed and the stringecho.c example is running well.
Thanks,
Leo

Lync Su said:

"Chris said:
when trying to run the ./config I get an Error: "java" not found.
I have jre6 installed and have rebooted and still get the error.
Please help this is driving me nuts."

I'm stuck in this problem too,looking forward for helping!

Case said:

ditto Chris and Lync. I've installed alchemy using this tutorial before, which is excellent.

Trying on a different machine I get:
ERROR: "java" not available ... upon running ./config.

My system drive letter is oddly "G", so I though maybe it was unable to find the java RE in it's default location? "C:\Program Files\Java\jre6" ?

I tried adding my weird java path to the PATH variable.. but no dice. I don't really know what I'm doing. Any ideas?

Thanks!


Hey all, I'm sorry I haven't gotten around to diving deeper into Alchemy. I've been so busy the past couple of months I've barely come up to breath.

I will continue this series, I just need to find the time. I'll comment back here when I do make the post so that everyone is notified.

Thanks everyone!

Damon

Thanks for writing this. The part where you instruct to replace

export ASC=$(cygpath -m -s -p $ALCHEMY_HOME/bin/asc.jar)
with
export ASC=$ALCHEMY_HOME/bin/asc.jar

really saved me some time.

Thanks

Tim

Leave a comment


Tag Cloud

Question of the Week: Open Source Flex Projects

What would you say are the 5 most prominent open source projects in the Flex world?

Answer

Latest Features

Recommended for You

@InsideRIA on Twitter

Archives

  • Or, visit our complete archive.  

About This Site

Welcome to the premiere community site for all things RIA sponsored by O'Reilly Media and Adobe Systems Incorporated.