Difference between revisions of "DevTools:CSharp Bindings on Windows"
David Haslam (talk | contribs) m (removed "index.jsp" from URL) |
David Haslam (talk | contribs) |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 100: | Line 100: | ||
</ol> | </ol> | ||
+ | [[Category:Bindings]] | ||
[[Category:Tutorials]] | [[Category:Tutorials]] | ||
+ | [[Category:SWORD]] |
Latest revision as of 14:07, 11 January 2018
The standard Sword distribution contains bindings for C#. These will not make and run on Windows using Visual Studio 2013. This is a tutorial on the steps needed to get things working on Windows. The goal is to be able to cross develop on either Windows or Linux using the same source code. After downloading the current version of Sword [1]:
-
Set up Sword for windows according to these instructions:
Tutorial:Compiling & Installing SWORD on Windows
Except, stop before making libsword.sln, you will need to make some changes before the project will build successfully. -
Open \sword\sword\lib\vcppmake\libsword.sln in VS2013. VS will want to convert the project; allow this.
-
Open the project properties window
- Under the C/C++ tab General, edit additional include directories, change icu-sword to icu
-
Under the Linker tab General, edit additional library directories
Change libcurl-vc10-x86-release-static-ipv6-sspi-spnego-winssl/lib to
libcurl-vc-x86-release-static-ipv6-sspi-spnego-winssl/lib
Change icu-sword/lib to icu/lib
-
In the Solution Explorer window, drag the file: sword\bindings\flatapi.cpp into the solution.
-
Open flatapi.h
- Replace all ' * SWDLLEXPORT ' with ' SWDLLEXPORT * ' (without the quotes)
-
Replace all ' ** SWDLLEXPORT ' with ' SWDLLEXPORT ** ' (without the quotes)
-
If they do not exist, declare the following functions:
SWHANDLE SWDLLEXPORT org_crosswire_sword_SWMgr_newWithPath(const char *thePath); void SWDLLEXPORT org_crosswire_sword_InstallMgr_delete(SWHANDLE hInstallMgr);
-
Open flatapi.cpp
- Make the replacements as in step 5
-
Change all ::clearModInfo to clearTheModInfo (remove the colons and rename)
-
Change the declaration of clearModInfo in the unnamed namespace to clearTheModInfo
-
Define the functions in 5.3 above if they do not exist:
SWHANDLE SWDLLEXPORT org_crosswire_sword_SWMgr_newWithPath(const char *thePath) { SWConfig *sysConf = new SWConfig(thePath); return (SWHANDLE) new HandleSWMgr(new WebMgr(sysConf)); } void SWDLLEXPORT org_crosswire_sword_InstallMgr_delete(SWHANDLE hInstallMgr) { HandleInstMgr *hinstmgr = (HandleInstMgr*)hInstallMgr; if (hinstmgr) delete hinstmgr; }
-
At this point, libsword.sln should make without errors
-
In the Sword distribution, there is a bindings directory having a csharp directory. In that directory, edit the file NativeMethods.cs:
- In the NativeMethods class the DLLNAME changes from libsword.so to libsword
-
In the NativeMethods class change:
[DllImport(DLLNAME)] to [DllImport(DLLNAME, CallingConvention=CallingConvention.Cdecl)]
-
Put all of the dlls in the sword project where C# can find them. Quick and dirty is to copy them all to the bin directory for the executable you will build. You may need the following dlls (I don't yet know yet which dlls do what, so I've included them all from the Windows build of the Sword distribution. This list works, a lesser list may be sufficient.):
icule53.dll clucene-core.dll icudt53.dll icuuc53.dll liblzma.dll icuio53.dll icuin53.dll binding.dll icutu53.dll iculx53.dll clucene-shared.dll libsword.dll libbz2.dll
-
Figure out where you want your data files and edit sword.conf to point to that directory. Also put sword.conf somewhere reasonable.
Note that in getting everything located, the differences between Linux and Windows on environment variables and file locations became sufficiently complex that I found it easier to create a C# class to manage all that. That class is located at CSharp Environment Variables Class. -
In sword\bindings\csharp\examples edit LookupExample.cs
using (var manager = new manager()) //changes to using (var manager = new manager(@"path to sword.conf"))