# Supported options for compiling LibraryLink code with VC++

I have to generate an interface to Mathematica for a fairly large library. I would like to use LibraryLink, as the generation seems much simpler. The platform is Windows (VS 2012), and I am wondering what the constraints are with regards to compiler options, etc. First and foremost: can I compile in 32 bit mode, or does it have to be 64 bits? (The CygWin toolkit file tells me that MathKernel.exe is a PE32+ executeable, whatever that is, and that the architecture is x86-64, which is 64 bits.) Would there be any library incompatibilities when compiling with VS2012 (VC11)? And are there any options I must respect?

-

Use the "TargetSystemID" option to CreateLibrary (this exists for CreateExecutable and CreateObjectFile as well) to compile for a 32-bit or 64-bit target.

"TargetSystemID" -> "Windows" generates a 32-bit binary "TargetSystemID" -> "Windows-x86-64" generates a 64-bit binary

If you want to use this library from Mathematica, create a Mathematica package MyPackage, and include the dynamic libraries here:

MyPackage/LibraryResources/Windows/MyLibrary.dll
MyPaclage/LibraryResources/Windows-x86-64/MyLibrary.dll


In MyPackage.m, point to the library mylib (the name passed to CreateLibrary):

$LibraryResourcesPath = FileNameJoin[{ DirectoryName[SystemPrivate$InputFileName],
"LibraryResources",
$SystemID }] If[FreeQ[$LibraryPath, $LibraryResourcesPath], PrependTo[$LibraryPath, $LibraryResourcesPath] ]$MyLibrary = FindLibrary["mylib"]


Now you can call LibraryFunctionLoad on \$MyLibrary.

-
 I don't want to compile my library from Mathematica; it is a large, existing library, already embedded in Excel, Python and Java. It consists of about 20 DLLs, and is developed in Visual Studios. I need to know what the constraints are on the compiler options I use in Visual Studios. – James Kanze Dec 20 '12 at 9:00