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!
reference:
http://labs.byhook.com/2011/03/01/alchemy-series-part-2-environment-setup/