Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Compile AutoHotkey using Visual C++ 2005 Express Edition


  • Please log in to reply
90 replies to this topic
corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Here's a list of instructions that I have pieced together based on installing Microsoft Visual C++ 2005 Express Edition and using it to compile AutoHotkey on XP Pro SP2 and Vista Home Premium). Note: The files in the steps listed were from an XP Pro SP2 installation. Other Win versions may have different downloads (Vista does). Please check the system requirements for the downloads if you are not sure.

If you had previously gone through the steps to get Microsoft Visual C++ 2005 Express Edition installed and don't want to through the steps listed below to manually make the necessary modifications then you can download modified sln and vcproj files for version 1.0.46.16 in a zip file. After downloading and extracting the AutoHotkey source files, extract the 2 files in the zip file, replace the 2 existing project files and open the sln file in VC++. The conversion wizard will still start but after completing the wizard (and copying upx.exe to the source directory if necessary) AutoHotkey should compile ok. If anyone decides to try this method then please let me know if it works ok for you.

Modified sln and vcproj files for version:
1.0.47.01
1.0.46.17
1.0.46.16


Install and configure Microsoft Visual C++ 2005 Express Edition

Download and install - Visual C++ 2005 Express Edition (install the IDE if asked)
<!-- m -->http://msdn.microsof...ress/downloads/<!-- m -->

Download and install - Microsoft ® Windows Server® 2003 R2 Platform SDK Web Install
<!-- m -->http://www.microsoft... ... laylang=en<!-- m -->

Download and install - Microsoft® Visual Studio® 2005 Express Editions Service Pack 1
<!-- m -->http://www.microsoft... ... laylang=en<!-- m -->

Important: go to <!-- m -->http://msdn.microsof... ... usingpsdk/<!-- m --> and follow the directions in Step 4 to update the corewin_express.vsprops file.

Open Visual C++ and go to Tools->Options->Projects and Solutions->VC++ Directories
On the right there will be a list of paths. There is also a drop-down list on the top right (Show directories for:)
Make sure to fill in the correct paths for the paths for the Executable files, Include files, and Library files sections. To change a path, double click the path in the list then click ... on the right to navigate to the path requested. When finished entering the paths, click Ok

Here's an example of what the modifed sections might look like:
Posted Image
Posted Image
Posted Image

Load, Configure and Compile AutoHotkey Source

Go to <!-- m -->http://www.autohotkey.com/download/<!-- m --> and download the latest AutoHotkey source code (note: version 1.0.46.15 was used in this example)

Run the downloaded file and unzip the project into a new folder in your /My Documents/Visual Studio 2005/Projects/ folder
(example: C:\My Documents\Visual Studio 2005\Projects\ahksrc104615)

Go to File->Open->Project/Solution... in VC++ then browse and open the AutoHotkey.sln file in the source folder where the AutoHotkey source was extracted. That will start a Conversion wizard. Click Next to proceed and convert the project. Since I still have the original from the download, I chose no when asked if I wanted to create a backup. Once the project has finished converting, a report can optionally be displayed. AutoHotkey.sln should show that it was converted successfully and the AutoHotkey and lib_pcre Projects should have a list of conversion issues.

In the Solution Explorer pane (on the left in the IDE), browse to the file stdafx.h and double-click on it to open the file in the right pane
on the line below the existing line
#define WIN32_LEAN_AND_MEAN
add the following line:
#define _CRT_SECURE_NO_DEPRECATE
then save the file (use the save icon at the top left - 4th from the left - in the IDE).

In the file menu:
Navigate to Build->Configuration Manager and change the Active solution configuration to Release using the drop-down list provided then click close


Next, Navigate to Project->AutoHotkey Properties...

Under Configuration Properties->C/C++->Precompiled Headers
change Create/Use Precompiled Header to say Create Precompiled Header (/Yc)

Under Configuration Properties->C/C++->General
change Treat Warnings As Errors to NO

Under Configuration Properties->C/C++->Advanced
change Omit Default Library Names to Yes(/ZI)

Under Configuration Properties->C/C++->Advanced
change Calling Convention to something else then change it back to _cdecl(/Gd)

Under Configuration Properties->Linker->Input
remove LibCMT; from the Ignore Specific Library line

Under Configuration Properties->Linker->Optimization
change Link Time Code Generation to Use Link Time Code Generation (/ltcg)

(note: these settings will likely need to be changed for each solution configuration - Debug Release, SC, etc... if you change to use a different Active solution configuration later)

Open Notepad and edit the file AutoHotkey.rc in the /source/resources/ folder in the AutoHotkey source directory. Look for the line
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST             "AutoHotkey.exe.manifest"
and change it to
// CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST             "AutoHotkey.exe.manifest"
then save the file and close Notepad.

In the Solution Explorer pane on the left in the IDE in the /Source Files folder, browse to script_autoit.cpp and double-click to open it in the right pane. In the file menu: navigate to Edit->Go To... then type in 1785 for the line number and click Ok. Change line 1785 from
lpTemp = strchr(szDest, '*');
to
lpTemp = (char*)strchr(szDest, '*');
then save the file (use the icon at top in the IDE...)

Go to <!-- m -->http://upx.sourceforge.net/<!-- m --> , download the win32 console version of UPX version 3.00 , then extract upx.exe to the AutoHotkey source folder
(to the same folder as AutoHotkey.sln) or to a system path.

Finally, in the file menu of the IDE, navigate to Build->Build Solution (or to Build->Rebuild Solution if you had preiously attempted to build AutoHotkey) and compile AutoHotkey

If all goes well the end of the output should be similar to:

Finished pass 2
Embedding manifest...
Performing Post-Build Event...
Ultimate Packer for eXecutables
Copyright © 1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007
UPX 3.00w Markus Oberhumer, Laszlo Molnar & John Reiser Apr 27th 2007
File size Ratio Format Name
-------------------- ------ ----------- -----------
536576 -> 254464 47.42% win32/pe AutoHotkey.exe
Packed 1 file.
Build log was saved at "file://c:\My Documents\Visual Studio 2005\Projects\ahksrc104615\Release\BuildLog.htm"
AutoHotkey - 0 error(s), 16 warning(s)
========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========


If everything went ok, the compiled file will be in the /Release folder in the Project directory (example: C:\My Documents\Visual Studio 2005\Projects\ahksrc104615\Release)

If AutoHotkey doesn't compile ok then I may have missed adding a step or two in the steps above. Please let me know if that seems to be the case and/or if something needs clarification so that I can update this post.

If you're having difficulties or have questions then feel free to ask.

Thanks. Enjoy :)

Edit: corrected typo: stafx.h should have been stdafx.h

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Thanks for putting all this together. Finally there's a free compiler that doesn't require a major overhaul of the AutoHotkey source.

I've moved this topic from "General Chat" to "Scripts" because it seems more appropriate here.

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Thanks Chris :) . I wasn't sure where to post this. Also, thanks for the tips in getting things to compile. Now it's time to play... :)

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
An alternate method to using Notepad to comment out the manifest line in the AutoHotkey.rc file is to change the Project Options instead. To make the change:

In the file menu in the IDE navigate to Project->Properties then to Configuration Properties->Linker->Manifest File then change Generate Manifest to No

This change will also reduce the exe size slightly (from 254464 to 251904).

adding resource. type:MANIFEST, name:1, language:0x0409, flags:0x30, size:545



toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Thanks corrupt for this comprehensive wrap up. Now I only have to learn C/C++ :) (fixed two small typos in your posts.)

I hope that this will lower the barrier for people who know C/C++ to help and add development time to AHK.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Great, it was a long awaited capability.
I will try as soon as I can.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

foom
  • Members
  • 386 posts
  • Last active: Jul 04 2007 04:53 PM
  • Joined: 19 Apr 2006
Sticky? :roll:

Grumpy
  • Guests
  • Last active:
  • Joined: --

Sticky? :roll:

I doubt it will interest many AHK users... :-)
But this surely should be linked from somewhere in the site (perhaps next the download source code link, or just in some ReadMe.txt in the download file).

foom
  • Members
  • 386 posts
  • Last active: Jul 04 2007 04:53 PM
  • Joined: 19 Apr 2006
The users? Who cares about the users? Its about attracting developers to have a look on ahk and maybe help Chris develop AHK (if this is in his interesst).

@Chris:
If someone would create a working copy for gcc would you be willing to change the source so that its gcc compatible "out of the box" ?

Edit: Ohh and is there any place i can talk to you in realtime like irc or im?

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006

The users , the users? Who cares about the users? Its about attracting developers to have a look on ahk and maybe help Chris with developing.

Oh, FINALY somebody sane here. Gratz foom about deduction.
Posted Image

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

Important: go to <!-- m -->http://msdn.microsof... ... usingpsdk/<!-- m --> and follow the directions in Step 4 to update the corewin_express.vsprops file.

Aargh, I just see this after trying to compile SciTE with VS 2005 and discovering via Google bribes of the steps described in the above link...
Don't follow only the Step 4, but all the steps (well, you gave the first two in your excellent article).
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Grumpy, thanks for the suggestion. In the next release of the source code, I'll include a file "How to compile.txt":
AutoHotkey is developed and compiled on Microsoft Visual C++ 2003 (7.1).

However, it is also known to compile on:
Microsoft Visual C++ 2005 (8.x): Requires a few modifications to project settings.
Microsoft Visual C++ 2005 Express (a free compiler): For detailed instructions,
see http://www.autohotkey.com/forum/topic19154.html
Corrupt: To make things even easier for people, perhaps you can provide a ready-made solution/project file for Visual C++ Express. On the other hand, maybe it would just get out-of-date too quickly and be too much work for you to keep up-to-date.

If someone would create a working copy for gcc would you be willing to change the source so that its gcc compatible "out of the box" ?

It depends on the nature and extent of the changes (when I last checked a couple years ago, it seemed likely that the changes would be extensive). Also, I'd be against any changes that increase the size of AutoHotkey.exe or reduce its performance.

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004

Don't follow only the Step 4, but all the steps (well, you gave the first two in your excellent article).

Thanks :) . I gave instructions for step 3 also (with images ;) ) but does it seem like it might be better to suggest modifying the VCProjectEngine.dll.express.config file instead? I haven't tried that method yet.

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004

Corrupt: To make things even easier for people, perhaps you can provide a ready-made solution/project file for Visual C++ Express. On the other hand, maybe it would just get out-of-date too quickly and be too much work for you to keep up-to-date.

I don't mind since I'll likely try and keep up to date anyway but I might end up lagging behind the official release once in a while.

foom
  • Members
  • 386 posts
  • Last active: Jul 04 2007 04:53 PM
  • Joined: 19 Apr 2006

It depends on the nature and extent of the changes (when I last checked a couple years ago, it seemed likely that the changes would be extensive). Also, I'd be against any changes that increase the size of AutoHotkey.exe or reduce its performance.


by uncommenting #ifdef _MSC_VER from stdafx.h i get the error count down to 13 (missing definitions/declarations).

D:\DESKTOP\AutoHotkey104615_source\source\clipboard.h:71: error: invalid conversion from `const char*' to `char*'
D:\DESKTOP\AutoHotkey104615_source\source\clipboard.h:74: error: invalid conversion from `const char*' to `char*'
D:\DESKTOP\AutoHotkey104615_source\source\util.h:53: warning: cast to pointer from integer of different size
D:\DESKTOP\AutoHotkey104615_source\source\util.h:53: warning: cast from pointer to integer of different size
D:\DESKTOP\AutoHotkey104615_source\source\util.h:57: warning: cast to pointer from integer of different size
D:\DESKTOP\AutoHotkey104615_source\source\util.h:57: warning: cast from pointer to integer of different size
D:\DESKTOP\AutoHotkey104615_source\source\util.h:60: error: `isspace' was not declared in this scope
D:\DESKTOP\AutoHotkey104615_source\source\util.h:180: warning: comparison between signed and unsigned integer expressions
D:\DESKTOP\AutoHotkey104615_source\source\util.h:203: warning: comparison between signed and unsigned integer expressions
D:\DESKTOP\AutoHotkey104615_source\source\util.h:236: warning: comparison between signed and unsigned integer expressions
D:\DESKTOP\AutoHotkey104615_source\source\util.h:313: error: `isxdigit' was not declared in this scope
D:\DESKTOP\AutoHotkey104615_source\source\util.h:339: error: `_strtoi64' was not declared in this scope
D:\DESKTOP\AutoHotkey104615_source\source\util.h:344: error: `_strtoui64' was not declared in this scope
D:\DESKTOP\AutoHotkey104615_source\source\util.h:373: error: `_strtoi64' was not declared in this scope
D:\DESKTOP\AutoHotkey104615_source\source\script.h:247: error: `LPPICTURE' does not name a type
D:\DESKTOP\AutoHotkey104615_source\source\script.h:353: warning: converting of negative value `-0x000000002' to `DWORD'
D:\DESKTOP\AutoHotkey104615_source\source\script.h:1183: error: `MIXERCONTROL_CONTROLTYPE_BASS_BOOST' was not declared in this scope
D:\DESKTOP\AutoHotkey104615_source\source\script.h:1351: error: `isdigit' was not declared in this scope
D:\DESKTOP\AutoHotkey104615_source\source\script.h:1638: error: `IDCONTINUE' was not declared in this scope
D:\DESKTOP\AutoHotkey104615_source\source\script.h:1639: error: `IDTRYAGAIN' was not declared in this scope
D:\DESKTOP\AutoHotkey104615_source\source\script.h:2148: warning: converting of negative value `-0x000000001' to `GuiIndexType'
D:\DESKTOP\AutoHotkey104615_source\source\script.h:2270: warning: extra tokens at end of #endif directive
D:\DESKTOP\AutoHotkey104615_source\source\AutoHotkey.cpp:40: warning: converting of negative value `-0x000000001' to `size_t'
:: === Build finished: 12 errors, 11 warnings ===
for the *toi64 functions and maybe the other ones some on a mailing list mentioned that its missing in the headers but he can declare it in its app and link it against the appropriate library.
quote from : <!-- m -->http://osdir.com/ml/... ... 00019.html<!-- m -->

_strtoi64() is missing in stdlib.h and libmsvcrt.a but
it is present in msvcrt.dll (works if I declare it in
my app and link against msvcrt.dll).


As for the speed/size tradeoff against msvc we have to see when its done ;).

Edit: Ohh i forgot to mention that i had to replace all occurences of __forceinline with inline since gcc ain't happy about that.