Feel like a geek and get yourself Ema Personal Wiki for Android and Windows

24 July 2009

Compile a thrift api in C#

Evernote has an API in thrift. To use this api in C#, you need a thrift compiler for windows to compile the thrift files into C# generated code.

The thrift compiler has to be compiled itself, there is no binary download. Worse, you need Cygwin to compile the compiler.

- Download the Cygwin installer
- Click through to the list of components. Sort the list alphabetically and select all libraries that resemble the libraries needed summed up on the ThriftInstallationWin32 page of the thrift wiki.
- download the thrift source from the "Download the snapshot" link on the Apache Thrift download site.
- copy the thrift directory to a new dir c:\cygwin\data
- start cygwin, cd to /data/thrift

Do what's mentioned on the wiki page:
- enter the command "./bootstrap.sh"
- enter the command "./configure"
- cd to compiler/cpp
- enter the command "make"
- after the command finishes, there should be a thrift.exe in this directory.

For your and my future convenience, download the thrift.exe file here.

- download the thrift files to compile. In my case, the evernote zip file containing the thrift definition files at http://www.evernote.com/about/developer/api/
- find out you had better done that as your first step, because the zip file already contains the generated code files. Well, it was a nice exercise anyway.
- just to make myself believe that it was not entirely useless, compile the thrift files:
./thrift.exe --gen csharp evernote/NoteStore.thrift
(etc)

the output can be found in the subdirectory gen-csharp.

5 comments:

Anonymous said...

Thank you! After many hours of googling your post helped me connect the pieces and now i finally can insert data into cassandra from my client written i C# :D

Anonymous said...

Thanks for this fabulous post! It saves me a lot of time!

Unknown said...

Performing the steps above to compiler the thrift compiler results in a thrift.exe (which you link to) but also two hidden directories called .deps and .libs, and these directories contain additional files for the compiler, among those the actual 11MB executable. The thrift.exe is just a simple wrapper for all of this, so if you download the linked file you will not get the complete compiler.

Szymon Kulec said...

I found it useful, to run Cygwin as administrator under Windows 7. Running it without admin privileges was... not enough;) (compilation errors and so on).

Andy Pook said...

You can get a binary for Win32 from http://thrift.apache.org/download/index.html