Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue Building on Windows: Build error #145

Open
pazzo83 opened this issue Aug 26, 2015 · 8 comments
Open

Issue Building on Windows: Build error #145

pazzo83 opened this issue Aug 26, 2015 · 8 comments
Labels

Comments

@pazzo83
Copy link

pazzo83 commented Aug 26, 2015

I am trying to build Cxx on Windows but I cam getting some errors upon running Pkg.build("Cxx"). I used cygwin64 to compile Julia (with the overrides, etc). These are the errors:

julia> Pkg.build("Cxx")
INFO: Building Cxx
Tuning for julia installation at: C:\Users\my_user\Julia\latest\julia\usr\bin
    CC /cygdrive/c/Users/my_user/Julia/.julia/v0.4/Cxx/deps/build/bootstrap.o
../src/bootstrap.cpp:1:0: warning: -fPIC ignored for target (all code is positio
n independent)
 #undef B0 //rom termios
 ^
../src/bootstrap.cpp:84:11: error: expected ';' at end of member declaration
 #define C CxxInstance *Cxx
           ^
../src/bootstrap.cpp:84:24: error: function definition does not declare paramete
rs
 #define C CxxInstance *Cxx
                        ^
BuildBootstrap.Makefile:83: recipe for target 'build/bootstrap.o' failed
make: *** [build/bootstrap.o] Error 1
=================================[ ERROR: Cxx ]=================================


LoadError: failed process: Process(`make -f BuildBootstrap.Makefile 'JULIA_HOME=
C:\Users\my_user\Julia\latest\julia\usr\bin'`, ProcessExited(2)) [2]
while loading C:\Users\my_user\Julia\.julia\v0.4\Cxx\deps\build.jl, in expressio
n starting on line 16

================================================================================

I read this might be an issue with the compiler (it is using g++ from cygwin), but I'm not sure. Thanks in advance!

@pazzo83
Copy link
Author

pazzo83 commented Aug 27, 2015

I tried using this C++ compiler as well, but ran into the same error (I updated the make file to use that compiler specifically):

$ g++-5.2.0 --version
g++-5.2.0 (GCC) 5.2.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@Keno
Copy link
Collaborator

Keno commented Aug 30, 2015

That error message strikes me as very weird because it's in a #define that the compiler doesn't seem to see. Maybe C is some sort of keyword in GCC5. Can you try renaming it to something else?

@pazzo83
Copy link
Author

pazzo83 commented Aug 31, 2015

OK, I renamed that to Cabcd (I can share the changes to bootstrap.cpp if you need to see them), but now I am getting some issues in the Make file:

julia> Pkg.build("Cxx")
INFO: Building Cxx
Tuning for julia installation at: C:\Users\my_user\Julia\latest\julia\usr\bin
    CC /cygdrive/c/Users/my_user/Julia/.julia/v0.4/Cxx/deps/build/bootstrap.o
../src/bootstrap.cpp:1:0: warning: -fPIC ignored for target (all code is positio
n independent)
 #undef B0 //rom termios
 ^
make: *** No rule to make target 'C:/Users/my_user/Julia/latest/julia/usr/bin/..
/../usr/lib/libLLVM-3.8.0svn.dll', needed by 'usr/lib/libcxxffi.dll'.  Stop.
=================================[ ERROR: Cxx ]=================================


LoadError: failed process: Process(`make -f BuildBootstrap.Makefile 'JULIA_HOME=
C:\Users\my_user\Julia\latest\julia\usr\bin'`, ProcessExited(2)) [2]
while loading C:\Users\my_user\Julia\.julia\v0.4\Cxx\deps\build.jl, in expressio
n starting on line 16

================================================================================


================================[ BUILD ERRORS ]================================


WARNING: Cxx had build errors.

 - packages with build errors remain installed in C:\Users\my_user\Julia\.julia\
v0.4
 - build the package(s) and all dependencies with `Pkg.build("Cxx")`
 - build a single package by running its `deps/build.jl` script

================================================================================

Seems like it's not looking in the right place for that DLL.

@pazzo83
Copy link
Author

pazzo83 commented Sep 2, 2015

OK, I've made some progress after telling the Make file exactly where the proper DLL was. I also had to change some things in the bootstrap.cpp file to export a few more things to the DLL (adding DLLEXPORT to a few functions, as it would complain when I tried to use Cxx). I also had to change the initialization.jl file to look in the right place for C++:

@windows_only function addStdHeaders(C)
      #base = "C:/mingw-builds/x64-4.8.1-win32-seh-rev5/mingw64/"
      base = "C:/cygwin64/"
      addHeaderDir(C,joinpath(base,"usr/include"), kind = C_System)
      addHeaderDir(C,joinpath(base,"usr/include/w32api"), kind = C_System)
      #addHeaderDir(joinpath(base,"lib/gcc/x86_64-w64-mingw32/4.8.1/include/"), kind = C_System)
      addHeaderDir(C,joinpath(base,"lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++"), kind = C_System)
      addHeaderDir(C,joinpath(base,"lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/x86_64-w64-mingw32"), kind = C_System)

Now, I am able to build, but I get a bunch of errors when I run: using Cxx.

In file included from :1:
In file included from __cxxjl_1.cpp:5:
In file included from C:\Users\my_user\Julia\latest\julia\usr\bin\../include\clang/Parse/Parser.h:17:
In file included from C:\Users\my_user\Julia\latest\julia\usr\bin\../include\clang/Basic/OpenMPKinds.h:18:
In file included from C:\Users\my_user\Julia\latest\julia\usr\bin\../include\llvm/ADT/StringRef.h:13:
In file included from C:/cygwin64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++\algorithm:62:
In file included from C:/cygwin64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++\bits/stl_algo.h:66:
In file included from C:/cygwin64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++\random:38:
C:/cygwin64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++\cmath:1044:11: error: no member named 'acoshl' in the global namespace
  using ::acoshl;
(and a bunch more like this from cmath)

In file included from :1:
In file included from __cxxjl_1.cpp:5:
In file included from C:\Users\my_user\Julia\latest\julia\usr\bin\../include\clang/Parse/Parser.h:17:
In file included from C:\Users\my_user\Julia\latest\julia\usr\bin\../include\clang/Basic/OpenMPKinds.h:18:
In file included from C:\Users\my_user\Julia\latest\julia\usr\bin\../include\llvm/ADT/StringRef.h:13:
In file included from C:/cygwin64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++\algorithm:62:
In file included from C:/cygwin64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++\bits/stl_algo.h:66:
In file included from C:/cygwin64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++\random:50:
In file included from C:/cygwin64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/x86_64-w64-mingw32\bits/opt_random.h:33:
In file included from C:\Users\F585581\Julia\latest\julia\usr\bin\../lib/clang/3.8.0/include\x86intrin.h:29:
In file included from C:\Users\F585581\Julia\latest\julia\usr\bin\../lib/clang/3.8.0/include\immintrin.h:29:
In file included from C:\Users\F585581\Julia\latest\julia\usr\bin\../lib/clang/3.8.0/include\xmmintrin.h:36:
C:\Users\F585581\Julia\latest\julia\usr\bin\../lib/clang/3.8.0/include\mm_malloc.h:57:22: error: use of undeclared identifier '__mingw_aligned_malloc'
  __mallocedMemory = __mingw_aligned_malloc(__size, __align);

Note that I ended up using 4.9.2 instead of 5.2.0, because this was the default one that came with cygwin and it built fine using it.

So despite those errors, I am able to get back to the prompt without any Julia errors. However, when I try to run:

julia> cxx""" #include<iostream> """

I get this error:

LLVM ERROR: Program used external function '__cxa_atexit' which could not be resolved!

and the REPL just shuts down.

However, if I only run something like:

julia> cxx"""
       void printme(int x) {
       std::cout << x << std::endl;
       }
       """

.. I get the expected C++ error but otherwise it seems fine:

In file included from :1:
__cxxjl_3.cpp:2:6: error: no member named 'cout' in namespace 'std'
std::cout << x << std::endl;
~~~~~^
true

Thanks in advance, I really would like to get this working!

Chris

@Keno
Copy link
Collaborator

Keno commented Sep 2, 2015

I suspect the simplest thing is just to add an empty

void __cxa_atexit() {}

in boot.h. Not sure who normally adds that. You can also try disabling CXAAtExit in the codegen opts, but that might just kick the can down the road.

@pazzo83
Copy link
Author

pazzo83 commented Sep 3, 2015

More progress, but using one of the examples in the readme, it ends up complaining about the function __cxxjl_personality_v0 missing (even though I see it in boot.h). Any ideas?

julia> cxx""" #include<iostream> """
true

julia> cxx"""
       void mycppfunction() {
       int z = 0;
       int y = 5;
       int x = 10;
       z = x * y + 2;
       std::cout << "The number is " << z << std::endl;
       }
       """
true

julia> julia_function() = @cxx mycppfunction()
julia_function (generic function with 1 method)

julia> julia_function()
LLVM ERROR: Program used external function '__cxxjl_personality_v0' which could not be resolved!

@pazzo83
Copy link
Author

pazzo83 commented Sep 3, 2015

There appear to be some major issues when trying to deal with shared libraries in Windows. Firstly, using the example in the readme, I ran into the same LLVM ERROR as above:

julia> addHeaderDir(path_to_lib, kind=C_System)

julia> Libdl.dlopen(path_to_lib * "/testArrayMaker.dll", Libdl.RTLD_GLOBAL)
Ptr{Void} @0x00000000343cbd10

julia> cxxinclude("ArrayMaker.h")

julia> maker = @cxxnew ArrayMaker(5, 2.0)
LLVM ERROR: Program used external function '_ZN10ArrayMakerC1Eif' which could not be resolved!

Interestingly, if you run a "strings" on that dll, you get:

_ZN10ArrayMakerC1Eif
_ZN10ArrayMaker7fillArrEv

among obviously a bunch of other stuff.

So it seems to have trouble taking that and understanding it as just "ArrayMaker"

Similarly, when trying to run some of the code in llvmtest.jl, the same type of error occurs:

julia> include("llvmincludes.jl")

julia> RequireCompleteType(C,d::cpcpp"clang::Type") =
           ccall((:RequireCompleteType,Cxx.libcxxffi),Cint,(Ptr{Cxx.ClangCompiler},Ptr{Void}),&C,d.ptr) > 0
RequireCompleteType (generic function with 1 method)

julia> function cxxsizeof(d::pcpp"clang::CXXRecordDecl")
           executionEngine = pcpp"llvm::ExecutionEngine"(ccall((:jl_get_llvm_ee,Cxx.libcxxffi),Ptr{Void},()))
           C = Cxx.instance(__current_compiler__)
           cgt = pcpp"clang::CodeGen::CodeGenTypes"(ccall((:clang_get_cgt,Cxx.libcxxffi),Ptr{Void},
               (Ptr{Cxx.ClangCompiler},),&C))
           dl = @cxx executionEngine->getDataLayout()
           RequireCompleteType(C,@cxx d->getTypeForDecl())
           t = @cxx cgt->ConvertRecordDeclType(d)
           @assert @cxx t->isSized()
           div((@cxx dl->getTypeSizeInBits(t)),8)
       end
cxxsizeof (generic function with 1 method)

julia> size = cxxsizeof(pcpp"clang::CXXRecordDecl"(Cxx.lookup_name(Cxx.instance(__current_compiler__),
           ["llvm","ExecutionEngine"]).ptr))
LLVM ERROR: Program used external function '_ZN5clang7CodeGen12CodeGenTypes21ConvertRecordDeclTypeEPKNS_10RecordDeclE' which could not be resolved!

At this point, I can use Cxx to run code directly passed in (as in my prior post), but using any shared library is unfortunately not working at this time. Any idea as to what the issue may be?

Thanks!!

@musm
Copy link

musm commented Apr 27, 2016

@pazzo83 Did you have to build Julia with the custom flags yourself ? Can you briefly describe how you got Cxx.jl working on windows? THanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants