In order to use QtSharp, we need CppSharp and LLVM (which CppSharp depends on).
Since this project is still under developement, it's usefull to know how to build CppSharp
CppSharp is where most of the work is done for generating the bindings
For QTSharp, we can ether use the pre-built dll's generated within the repository within the References directory or we can try to generate our own from a more recent version of CppSharp / LLVM
This documentation is based on the below link with perhaps a couple of additional notes
A couple of notes:
- It's probably a good idea to make sure to build it within directories that don't have spaces in the path name (at least for a windows box anyway)
- The version I'm using here is built to .Net 4.0
- Check the patches subdirectory in CppSharp for patches to experiment with
As part of the build, I'm currently using the following versions of software, although the latest stable versions should be fine
- Git 1.9.5 - Windows
- cmake-3.2.1 - WIndows
- Python-3.4.3 - Windows
First we need to clone CppSharp
For this example I'm using version ae4fab7db53d55a37defdc61fad4abd486f52f1d
but the latest release is probably the best for experimenting
To clone the repo at the command prompt:
mkdir C:\GITHUB
cd C:\GITHUB\
git clone https://github.com/mono/CppSharp CppSharp
cd C:\GITHUB\cppsharp
git checkout master
If you already have done a clone before, to update run
cd C:\GITHUB\cppsharp
git pull
git checkout master
To see which version your on
git rev-parse HEAD
If you want a specific version
git checkout ae4fab7db53d55a37defdc61fad4abd486f52f1d
Theres a few different forks available
Next we need to clone the LLVM Sources
For the recommended commit number to use with the latest version of CppSharp
see CppSharp - Getting Started
cd C:\GITHUB\CppSharp\deps\
git clone http://llvm.org/git/llvm.git llvm
cd C:\GITHUB\CppSharp\deps\llvm
git checkout 0e8abfa6ed986c892ec723236e32e78fd9c47b88
Next we need to clone Clang
Again check the above link for the latest commit number to use with the latest CppSharp
cd C:\GITHUB\CppSharp\deps\llvm\tools\
git clone http://llvm.org/git/clang.git clang
cd C:\GITHUB\CppSharp\deps\llvm\tools\clang
git checkout 3457cd5516ac741fa106623d9578f5ac88593f4d
Next we're going to build LLVM which is a depend of CppSharp, Clang will be built as part of this process automatically
To get things to match up we're going to use a 64 bit build
Note that while QtSharp and QtSharp.CLI run as x64 by default, it is possible just to change the arch to x32 in the project settings
Also the project / source for the wrapper for QT will actually be x32 by default
This next part is taken from the CppSharp readme
we first need to run cmake on llvm to generate the project files
Followed by msbuild to compile LLVM
Make sure to run this within a Visual Studio Command prompt so that it can find the msbuild command
This selects RelWithDebInfo as the build configuration
For 64bit:
cd C:\GITHUB\CppSharp\deps\llvm
cmake -G "Visual Studio 12 Win64" -DCLANG_BUILD_EXAMPLES=false -DCLANG_INCLUDE_DOCS=false -DCLANG_INCLUDE_TESTS=false -DCLANG_INCLUDE_DOCS=false -DCLANG_BUILD_EXAMPLES=false -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_INCLUDE_EXAMPLES=false -DLLVM_INCLUDE_DOCS=false -DLLVM_INCLUDE_TESTS=false
msbuild LLVM.sln /p:Configuration=RelWithDebInfo;Platform=x64 /m
For 32bit:
cd C:\GITHUB\CppSharp\deps\llvm
cmake -G "Visual Studio 12" -DCLANG_BUILD_EXAMPLES=false -DCLANG_INCLUDE_DOCS=false -DCLANG_INCLUDE_TESTS=false -DCLANG_INCLUDE_DOCS=false -DCLANG_BUILD_EXAMPLES=false -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_INCLUDE_EXAMPLES=false -DLLVM_INCLUDE_DOCS=false -DLLVM_INCLUDE_TESTS=false
msbuild LLVM.sln /p:Configuration=RelWithDebInfo;Platform=Win32 /m
Next we need to build CppSharp
First generate the Project / Solution files
cd C:\GITHUB\CppSharp\build
GenerateProjects.bat
Choose option 2 / Visual Studio 2013
Next you may want to have a look at the Build/patches directory
For any patches to explore
In order to get CppSharp to build on my system I had to make a couple of tweaks
- Open CppSharp.sln with Visual Studio 2013
- Ignore the warning about upgrading project files, click OK
- Select Release from the top menu of Visual Studio
- If building x64 make sure x64 is also selected to match llvm
The first change:
-
Next this appears to be needed to find the lib files during the build
-
Right click the CppSharp.CppParser (C++) Project
-
Select Properties
-
Configuration Properties -> Linker -> General -> Additional Library Directories
-
Add the following directory
C:\GITHUB\CppSharp\deps\llvm\RelWithDebInfo\lib
The second change:
- Right click the CppSharp.Parser.CLI (C++) Project
- Select Properties
- Under Configuration Properties -> General
- make sure the Platform Toolset is set to Visual Studio 2013 - Windows XP (v120_xp)
Finally to do the build:
- Right Click Build the Solution within Visual Studio
- Wait lots
- Some of the tests may fail to build, but as long as the main library's build this is what counts
I've just put this here for reference, to build CppSharp from the command line
(from a visual studio command prompt)
For 64bit:
msbuild vs2013\CppSharp.sln /p:Configuration=Release;Platform=x64
For 32bit:
msbuild vs2013\CppSharp.sln /p:Configuration=Release;Platform=x86
The .Net level should default to 4.0
Which is fine since it matches the .Net level of QtSharp
If you decide to change it to 4.5 / 4.5.1 you'll also need to change it for the QtSharp projects as well
The dll output build should now be within
C:\GITHUB\CppSharp\build\vs2013\lib\Release_x64\
Or Release_x32 for 32bit
The important files that we need are:
CppSharp.AST.dll
CppSharp.CppParser.dll
CppSharp.dll
CppSharp.Generator.dll
CppSharp.Parser.CLI.dll
CppSharp.Runtime.dll
Note that the CppSharp.CppParser.dll is a bit special in that it's a native C++ dll not a managed .Net dll so you won't be able to add a reference to it
You ether need to add it into the project as a Link, or alter your system path to point to it
The QtSharp project already has a link to it in the project file for copying across (although this isn't visible under references)
Backup the files within the References directory within QtSharp, and then replace them with these built ones