Home » excel » c++ – Developing an Excel XLL using Mac OS X / Linux

c++ – Developing an Excel XLL using Mac OS X / Linux

Posted by: admin April 23, 2020 Leave a comment


I’ve been developing C++ models using Visual Studio for the past 5 years, and wrapped them into Xll to be used with Excel (using xlw). The Excel add-in is the final product I want to deliver.

However, I believe C++ coding is way better using Linux or Mac OS X. But I also believe using my models with Excel through the Xll is also very practical, but sadly only works on Windows.

So I would like to know if there is a way to do the implementation on Mac OS X (or Linux), generate the Excel add-in and use it on Windows.

The only method to do so that I’m currently thinking of is doing the coding on Mac OS X, compile the project without including the part concerning the Xll, then load the project into Visual Studio and compile it entirely to generate the Excel add-in. But to be honest, this sounds a bit laborious, and I’m hoping for an easier way.

How to&Answers:

It is possible. You just need to use mingw (http://mingw-w64.sourceforge.net/) to compile from Linux. I should note that you can then use g++ 4.7, which is a very decent C++ compiler with support for C++ 11x. The cross-compilers work both in Mac and Linux, and because it is gcc, you can use them with your favorite tool ecosystem.

There are few unexpected quirks, but just in case:

  • Remember to use -Wl,–add-stdcall-alias to get functions exported with no underscore in the final dll.
  • Instead of declspec(__declexport) use __attribute((dllexport)). But you can also use the more antique .def trickery, if you wish. In any case, use the Windows sdk tools “Depends.exe” or similar to ensure that your dll exports correctly the names.
  • If your are using a virtual machine for testing, or any fresh Excel installation, remember to install all the bells and whistles that come with Office and Excel. Otherwise, in Excel 2007 and Excel 2010, the addins won’t work, and you will mistakenly blame your build setup.

Also, if you are up for using http://kalx.net/xll/, which indeed can make your life simpler, you will have to update that library for strict C++ conformance.

Best regards.


I’ve developed a working example of a C++ Excel addin using Mac OSX, Eclipse CDT and XCode and a spreadsheet that uses the addin. An explanation is here http://www.smr.co.uk/excel-addin-on-mac-os-x-using-cdt/ including versions used etc and the code is here https://github.com/PollardsEtFilles/MacCPPExcelAddinExample.

There are two gotchas

  • Excel 2011 is 32 bit
  • Make sure the addin in the same directory as the excel spreadsheet

clang (included with Xcode) is a good replacement for g++

All you need to do is install Eclipse CDT and import the code you’ll be away.