Cling on windows with VS2013

Hello,

I have been able to compile cling using VS2013 with only a small number of modifications.
It seems to work quite well. But I have not tested more then simple C functions.

apparently somewhere windows defines a macro called IN. That is why one needs to to apply this little change to /lib/Interpreter/IncrementalParser.cpp :
532,533c532,533
< for (NamespaceDecl::decl_iterator _IN = ND->decls_begin(),
< EN = ND->decls_end(); _IN != EN; ++_IN) {

        for (NamespaceDecl::decl_iterator IN = ND->decls_begin(),
               EN = ND->decls_end(); IN != EN; ++IN) {

536,537c536,537
< if (!shouldIgnore(_IN))
< getCodeGenerator()->HandleTopLevelDecl(DeclGroupRef(
_IN));

          if (!shouldIgnore(*IN))

in include/Interpreter/RuntimeUniverse.h you need to remove the #ifdef _WIN32 block
and most things will start to work.

You had asked me privately about the mingw compilation we got working. I replied but I think it was private. Lets make it public now so others can see it, I will repost it all here.

I have also attached a patch file and build instructions.

mingw working binary of cling on windows:

s3.amazonaws.com/sysprogs2infus … -cling.exe
It is equivalent to the following nightly build: ecsft.cern.ch/dist/cling/curren … 21.tar.bz2

run cling.exe directly from the directory where it is located. It includes several proof-of-concept workarounds that are sensitive to the working directory.

You need to run this batch file first as well: QueryCppIncludes.bat

I remember that we may have had to replace this .bat’s contents with the below on certain systems if it didn’t work (am just reading from my old emails):

@echo off
set CLING_BIN=%~dp0
echo %CLING_BIN%…/lib/gcc/mingw32/4.7.2/include/c++
echo %CLING_BIN%…/lib/gcc/mingw32/4.7.2/include/c++/mingw32
echo %CLING_BIN%…/lib/gcc/mingw32/4.7.2/include/c++/backward
echo %CLING_BIN%…/lib/gcc/mingw32/4.7.2/include
echo %CLING_BIN%…/lib/gcc/mingw32/4.7.2/…/…/…/…/include
echo %CLING_BIN%…/lib/gcc/mingw32/4.7.2/include-fixed
gbrill
Archive.zip (384 KB)

Thanks!

I will think about this functionPointer problem.
Your current solution is a bit … hacky ?
But it is great that you have made such success!

It sounds as though you have accomplished the same using VS 2013. This would be a lot easier than mingw.

Can you post you VS 2013 solution on github or somewhere? I would like to try it.

The patch to enable the build is in.

So just use cmake and generate build files for Visual Studio 12
and edit include/Interpreter/RuntimeUniverse.h

a binary is uploaded here www63.zippyshare.com/v/28094296/file.html

Hi,

Just for reference, the current master builds just fine with MSVC2013, no additional patches needed. We are working on fixing C++ support for cling on MSVC, too.

Cheers, Axel.

I’d be really interested in talking with gbrill on the mingw support he was talking about.

I send two patches to vgvassilev that he merged on github back in december to fix some issues with it.

github.com/vgvassilev/cling/com … 140ded73f6
github.com/vgvassilev/cling/com … 9e9943f012

I would like to get these merged into the main project if possible and
I have another patch I would like to merge also that helps with searching gcc for paths.

Hi,

Thanks, apart for a minor modification (LLVM_ON_WIN32 instead of _WIN32 in cling) they are good to go; I have committed them. Thank you for your patches!

Can you post the third patch?

Cheers, Axel.

Hi Axel,

Here are the 3 patches with the modifications you asked for.
I also fixed my name in the Author to the full name

gist.github.com/martell/4054db3154b2a5004692

I think with the commit you made on this first one you only added
DynamicLibraryManager.cpp and missed the rest of the files.

gist.github.com/martell/a0fb3037ad47c3e42489

This fixes windows x64 bit building.
void* is not the same length as an unsigned long on this platform.
size_t seems like the best solution to this :slight_smile:

gist.github.com/martell/1a2e3539f503257a0fcc
By invoking bash it helps cygwin and msys2 on windows find the include dirs.
Other platforms shouldn’t be affected by this change but a test would be nice

Many Thanks
Martell Malone

There are 2 things I think we need to work around

On MSVC and mingw-w64

  1. Current head seems more broken than it was in the past.

cling

****************** CLING ******************

  • Type C++ code and press enter to run it *
  •         Type .q to exit             *
    

#include <stdio.h>
printf(“hello”);

Caught an interpreter exception!
Incompatible object format!

I believe this is because MCJIT is only available via elf mode on windows atm.
This patch may help.
freedesktop.org/patch/25959/
Could this be worked into cling ?

  1. We need to find an actual solution to the missing functions rather than using this
    gist.github.com/martell/ac2024b967b547705ec5

Hi,

Ack on the COFF / ELF issue on Windows; we’ll fix that.

What is the issue with the missing functions?

Axel.

That’s great. I’m super excited about the support of inline asm :slight_smile:

I think we talked about this before.

Basically on mingw-w64 when you try to even do something as simple as printf it fails to find the location of the function and all other functions it needs to hook up to within cling.exe itself
gbrill came up with the idea of creating a table using nm and patching the lookup function to hack it.
I am not sure if this is a cling issue or a clang issue to be honest.

Hi,

I forget things :slight_smile: Can you describe the matching of the symbols that needs to happen? Or can I see the mapping text file?

Cheers, Axel.

Hello,
I have tried building Cling with VS2013, but I am met with an error at

[code]IncrementalExecutor.h(99): std::atomic_flag m_AtExitFuncsSpinLock = ATOMIC_FLAG_INIT;

Compiler Error C2797: List initialization inside member initializer list or non-static data member initializer is not implemented.[/code]

I worked around it by removing “= ATOMIC_FLAG_INIT” and adding m_AtExitFuncsSpinLock.clear() in the constructor.
The build was successful, however, when I try to use Cling i am greeted by yet another error:

[cling]$ int x = 0;
>>> Caught an interpreter exception!
>>> Incompatible object format!

So, how are you guys able to run cling windows?
Are there any patches that one must apply?

Thanks

Hi,

This will be fixed soon - hopefully still this week.

Axel.

What is the last known version of Cling to function properly on Windows?
It still throws the “Incompatible object format” error.

Hi Axel and Biex,

I have also experienced exactly this problem, including all details (building cling with VS2013, having to work around “m_AtExitFuncsSpinLock = ATOMIC_FLAG_INIT”, getting “Caught an interpreter exception! Incompatible object format!”).

I am happy to hear that you are working on it. If you know any work-around in the mean time, I would be very appreciative.


Cheers,
Ben Morphett

Hi,

Fixed now!

Axel.

[quote=“Axel”]Hi,

Fixed now!

Axel.[/quote]

Great to hear that! however, I am still getting the “Caught an interpreter exception! Incompatible object format!” error on Windows (MSVC2013). The same error also applies when building Cling in Cygwin.

Any idea as to why that is?

Hi,

I can reproduce it. We’ll have to debug it…

Cheers, Bertrand.