Email Updates RSS Subscribe
Line

This blog is created and maintained by the technical team at Hook in an effort to preserve and share the insights and experience gained during the research and testing phases of our development process. Often, much of this information is lost or hidden once a project is completed. These articles aim to revisit, expand and/or review the concepts that seem worth exploring further. The site also serves as a platform for releasing tools developed internally to help streamline ad development.

Launch
Line

Hook is a digital production company that develops interactive content for industry leading agencies and their brands. For more information visit www.byhook.com.

Line

Alchemy Series Part 2: Environment Setup

Line
Posted on March 1st, 2011 by Jake
Line

To get started with Alchemy on a Windows box, you first need to get cygwin installed. Cygwin is a pseudo linux environment that runs under Windows. This gives us access the the LLVM and the gcc compilers. This is how we are going to take C/C++ code and create a swc that we can access directly from flash.

To get started we are going to first need the Adobe Flex SDK, please download this and unzip it to c:\flexsdk
http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK

Currently the latest release is Flex4.1 Update 4.1.0.16076.

Now we can grab Adobe Alchemy:
http://labs.adobe.com/downloads/alchemy.html

Just check the box at the bottom and download the “Alchemy Toolkit for Cygwin on Windows”
When that finishes downloading, unzip it into c:\alchemy (make sure that you don’t unzip it into folders within that, you want the folder structionto be c:\alchemy and then a bunch of folders such as c:\alchemy\achacks, c:\alchemy\bin, etc…

Next you will need to make sure you have Java installed. If you do, please continue. If you do not, please download and install it from here:
http://www.java.com/en/download/index.jsp

Last up is Cygwin’s setup.exe file:
http://www.cygwin.com/

Look for setup.exe about half way down the page, and download that to c:\cygwin (you can put this wherever you like, but I will be using c:\cygwin and c:\alchemy through out the post for simplicity)

This setup file is basically a client front end that allows you to download and install whatever linux packages you will need to get the job done.

Double click on the setup.exe to get things started.
- Click next on the first screen.
- On the second screen select “install from internet” and click next.
- Set your root directory on the third screen to c:\cygwin and install for all users. Click Next
- Set your local package directory to be c:\cygwin as well, click next.
- Set up your proxy settings if you have any (if you are behind a corporate firewall or something) otherwise select “Direct Connection” and click next.
- Select a mirror, I usually use http://mirrors.kernel.org click next.
- You may get a Setup Alert warning you that this is your first install, so you should check out the docs. This is normal, and fine, just click OK.
- This takes you to the package selection screen.

Yes I know, its scary, but you’ll be fine :) There are a few packages that we need to install for the Alchemy setup, and a few that I install for convenience. Here are the required packages (you can type the name in the search box to help narrow down the list) Once you find the package, click on the “Skip” button on the left, and that will change to a version number. That means that package will download. The next column over has 2 check boxes. The first says Download Binaries, the second says Download Source. For this we only need the binaries.
Required:
- All -> Devel -> gcc-g++: C++ compiler

- All -> Archive -> zip: Info-ZIP compression utility

- All -> Perl -> perl: Larry Wall’s Practical Extracting and Report Language

Optional:
- All -> Shells -> rxvt: VT102 terminal emulator

- All -> Editors -> emacs: The extensible, customizable, real-time display editor

Once all of the packages are selected, you can click Next

This will bring up a screen about Resolving Dependencies. Make sure the check box is checked at the bottom of the window, and click Next.
The great download starts. Might be a good time to take a quick break as this will take a few minutes.
When the download/install is complete, just click finish.

Finally with everything installed, we can configure it all :)

Parts of the next section were learned from:
http://www.developria.com/2009/04/setting-up-adobe-alchemy.html
and
http://labs.adobe.com/wiki/index.php/Alchemy:Documentation:Getting_Started
Both are excellent articles for getting the Alchemy Environment setup and running.

Now we have to add some things to cygwin’s path. In the c:\cygwin\etc folder there will be a file called “profile”. Please open that in Notepad++ or other proper text editor (in other words, not Microsoft WORD!).

The first line that isn’t a comment should be:

PATH=/usr/local/bin:/usr/bin:/bin:$PATH

We need to add alchemy and the flexsdk to that path:

PATH=/usr/local/bin:/usr/bin:/bin:/cygdrive/c/alchemy/achacks:/cygdrive/c/flexsdk/bin:$PATH

Please take note of the /cygdrive/c portions of the path. This is how you access your drives from within cygwin. If you want to access the “e” drive for instance it would be /cygdrive/e/ and not e: as it is within windows.

We also need to make sure all of the Alchemy setup scripts run when we start cygwin. So right before the “PATH=” line that you just edited, we need to add the following:

source /cygdrive/c/alchemy/alchemy-setup

You can now save and close the “profile” file.

If you installed the rxvt package (its a replacement terminal, because the default terminal for cygwin is terrible) then please open your c:\cygwin\cygwin.bat file and make it look like this:

@echo off
 C:
 chdir \cygwin\bin
 start rxvt -sr -sl 10000 -fg white -bg black -fn fixedsys -fb fixedsys -tn cygwin -e /bin/bash --login -i

Now run the cygwin.bat file and it will drop you into a cygwin terminal. We have to do one last bit of configuration and then we are done! Yay!

You will probably get a bit of messaging about Skeleton files being copied over. This is good :)
Here we have to setup alchemy. So from the terminal type:

cd /cygdrive/c/alchemy

This will put you in the Alchemy directory on your C: drive.
From here type:

./config

You should get a screen that looks like this:

Now close the cygwin window, and in your text editor open the c:\alchemy\alchemy_setup file.
Find the lines:

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

and replace the #export line with the following (be sure to remove the # at the beginning of the line)

export ADL=/cygdrive/c/flexsdk/bin/adl.exe

You will also need to locate this line:

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

and change it to:

export ASC=$ALCHEMY_HOME/bin/asc.jar

The POSIX to Windows path conversion doesn’t seem to work. This change will throw a warning about POSIX file paths, but everything will work just fine.
Save that, and restart cygwin (c:\cygwin\cygwin.bat)

That should do it! You should have have function cygwin/alchemy environment.
So lets compile something shall we?
Type:

cd /cygdrive/c/alchemy/samples/stringecho

Then type this to remove the old .swc:

rm stringecho.swc

Now you can compile this sample provided by Adobe to make sure everything is cool.

First turn on the Alchemy gcc compiler, type:
(you will only need to do this once per cygwin session)

alc-on

Then run the actual link and compile, type:

gcc stringecho.c -O3 -Wall -o stringecho.swc

If you run into troubles with the swc being corrupt you may need to include the -swc switch as suggested by “coderyy” in the comments. Thanks for the tip!

gcc stringecho.c -O3 -Wall -swc -o stringecho.swc

With any luck you will get a screen that looks like this:

(yes you can ignore the “Arguments Dropped” warning)

if you type ‘ls’ (short for list, same as ‘dir’ in dos) you will see your shiny new stringecho.swc :)

In the next episode we will go over how to use that .swc and how to create your very own .c files that you can access from Flash!

As always if you want to get notified of new posts in this series, (or any of our labs posts) please ‘Like’ us on Facebook:

Or you can Follow me on Twitter:
Follow JakeCallery on Twitter

Thanks for reading and good luck!

Line
6 Responses to “Alchemy Series Part 2: Environment Setup”
  1. Michael says:

    Love this! Thanks!

  2. Jason says:

    My compile looks like this, it seems to make the swc, but gives a file not found error, is this a problem?

    $ gcc stringecho.c -O3 -Wall -swc -o stringecho.swc
    File not found – *.l.bc
    WARNING: While resolving call to function ‘main’ arguments were dropped!

    5740.achacks.swf, 261075 bytes written…..

    • Jake says:

      @jason, to be honest, I haven’t seen that error before, and a quick google search shows that at least a couple of people are having that issue, but no one has seemed to resolve it. At the moment I don’t have a good answer for you, but if I come across it, I’ll be sure to post it here… good luck and please let us know if you get it sorted

    • Jake says:

      You may want to try this patch here:
      http://forums.adobe.com/message/221789

      And make sure you have alc-on from the beginning, if that fails, you might want to try restarting cygwin, then turning on alc-on, then do the compile… I’ve had issues where I seem to be able to break the cygwin envrionment with the adobe toolchain…

  3. coderyy says:

    The document is so useful, thank you but you should change this line

    gcc stringecho.c -O3 -Wall -o stringecho.swc

    To

    gcc stringecho.c -O3 -Wall -swc -o stringecho.swc

    otherwise, it compiles but it creates a corrupted file.

    • Jake says:

      Interesting, I didn’t have an issue with file corruption, but it can’t hurt to throw that switch in there, I’ve updated the post. Thanks!


Leave a Reply

*

Line
Line
Pony