Search code examples
c++windowsjuliaembedding

Embedding Julia in C++ using Visual Studio


I try to embed Julia v1.4.2 in a simple C++ console application built using Visual Studio 2017 v15.0. I follow the official docs at https://docs.julialang.org/en/v1/manual/embedding/#High-Level-Embedding-on-Windows-with-Visual-Studio-1. However, when typing #include <julia.h> VS explodes in a series of 25+ errors, such as:

identifier "PCONTEXT" is undefined in errhandlingapi.h

identifier "PCONTEXT" is undefined in WinBase.h

identifier "PSLIST_HEADER" is undefined in WinBase.h

...


Solution

  • Answering my own question here as I found a solution. Turns out <uv.h> - which is a part of Julia - must be included before <windows.h>.

    This is so because uv.h includes uv/win.h which includes winsock2.h. And winsock2.h guards against including winsock.h which is included by windows.h. But if windows.h and thereby winsock.h is included first, then winsock2.h will try to redefine everything in winsock.h leading to a string of errors.