Compiling mxnet for C++ from source on Windows

My goal is to compile mxnet from source to get the mxnet.dll and mxnet.lib and then use mxnet with C++ under Windows. I have to note that this is the first time I am trying to compile a library from source and so far it hasn’t been much fun.

The compilation takes about 5-6 hours. When it’s complete i get the following error:

LINK : fatal error LNK1248: image size (97588000) exceeds maximum allowable size (80000000)

After researching about this error i found out that this is a limit the Windows compiler sets and i don’t think I can do anything about it.

There is another issue here with a similar question, but i don’t know what to do with the answer “try buildingin in the Release configuration”

Does this reduce the size of the image and where can i find the “Release configuration”.

I have done some research on the internet, but couldn’t find much information/resources about compiling for C++ on Window so this is forum is my last resort.

Here are the steps i have gone through with my attempts an compiling from source:

  • Downloaded CMake
  • Downloaded OpenCV
  • Downloaded OpenBlas
  • Set the environment variables: set OpenCV_DIR=C:\Program Files\opencv\build and
    set OpenBLAS_HOME=C:\Program Files\OpenBLAS
  • Downloaded CUDA and cuDNN
  • Cloned the git-repository: git clone https://github.com/apache/incubator-mxnet.git --recursive
  • Set the environment variables for cuDNN: set DCUDNN_INCLUDE=C:\Program Files\cuda\include and set DCUDNN_LIBRARY=C:\Program Files\cuda\lib\x64\cudnn.lib and set LD_LIBRARY_PATH=D:\.....\mxnet\lib
  • Created a “build” directory in the folder
  • Use Cmake: cmake -G "Visual Studio 15 2017 Win64" -T cuda=10.1,host=x64 -DUSE_CPP_PACKAGE=1 -DUSE_CUDA=1 -DUSE_CUDNN=1 -DUSE_NVRTC=1 -DUSE_OPENCV=1 -DUSE_OPENMP=1 -DUSE_BLAS=open -DUSE_LAPACK=1 -DUSE_DIST_KVSTORE=0 -DCUDA_ARCH_LIST=Common -DCUDA_TOOLSET=10.1 -DCUDNN_INCLUDE="C:\Program Files\cuda\include" -DCUDNN_LIBRARY="C:\Program Files\cuda\lib\x64\cudnn.lib" "D:\.....\mxnet"
  • Building the library with msbuild mxnet.sln /p:Configuration=Release;Platform=x64 /maxcpucount

So my questions are:

  • What is the “Release configuration” and where can i get it?
  • Is it possible to get the libmxnet.dll without compiling the source myself?
  • The fact that i can’t change some windows settings to successfully compile the library with my given steps seems strange to me. Have i interpreted this error wrong? and can i do something about it?

Any help would be much appreciated!

Hey PhilippeS. !
I also had a headache when trying to compile MXnet from source with C++ under Windows. I succeeded once one month ago without understanding why and how…

Comparing the steps you have done and thoose listed there, I do not know if you have M. Visual Studio 2015 or 2017.

Then, I used Cmake GUI (more user friendly to set your params and to follow if all is ok or not). It creates in the build dir a mxnet.sln, Visual Studio project.
By opening the project in Visual you can choose your configuration (Release or Debug). Normally the compilation, if ok, gives you the libmxnet.dll or .lib

I hope it can help you a bit.

1 Like

Understandable, it took me some time as well to compile MXNet in Windows, but it was much easier in Linux. I suggested a while back that MXNet should provide official nightly and release builds of the MXNet C++ library, like other DL frameworks: Why no C++ love

Your error seems like you’re running out of disk space.
If you run out of RAM during compilation, then you can try to reduce the number of build threads.

If you are fine with using docker, then you can try out the official NVIDIA MXNet docker image.
The shared library within the docker container supports the C++ API as well as tensorRT.

The libmxnet.dll with C++ support (MXNet 1.4.1, CUDA 10.1, cuDNN v7.5.1.10, openBlas, no OpenCV) is also included in the latest CrazyAra release 0.6.0.

In the following you can find additional build instructions for Windows:

Best regards,
~QueensGambit

1 Like

Thanks for the answers @MarieL and @QueensGambit. Sadly i had to temporarily stop the project, because it is part of my diploma thesis and I had already invested too much time trying to set it up and had to focus on other parts. I will eventually have come back to it in a few weeks and try it again with the tips you gave me.

If I eventually succeed to get it to run on windows i am going to reply to this post and explain the steps I have done to maybe help people who run into the same issues in the future.

Till then wish me luck :slight_smile:

Thanks againg to @MarieL and @QueensGambit for taking the time to reply to my post!