Giter Club home page Giter Club logo

cxx.jl's People

Contributors

ararslan avatar certik avatar drewrobson avatar elehcim avatar gnimuc avatar ihnorton avatar jakebolewski avatar jstrube avatar keno avatar konstantin-azarov avatar kristofferc avatar maleadt avatar maxruby avatar mkitti avatar mlubin avatar mschauer avatar nkottary avatar oschulz avatar pallharaldsson avatar r9y9 avatar robertu94 avatar samuelpowell avatar sjkelly avatar stevengj avatar terofrondelius avatar testurser avatar timholy avatar tkonolige avatar vchuravy avatar viralbshah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cxx.jl's Issues

missing dcastCXXRecordDecl

I feel like it's getting close... with:

  • julia explicitly linked against llvm (-lLLVM-3.5svn)
  • other changes in current patch set
    • notably: linking against LLDB disabled for now (I think the segfault I mentioned was due to racing/conflicting initializers)
    • a bunch of minor changes to the qttest

then I get:

isaiah@titan:~/.julia/CXX/deps$ jldev ../test/qttest.jl 
ERROR: ccall: could not find function dcastCXXRecordDecl
 in _cppcall at /home/isaiah/.julia/CXX/src/CXX.jl:740
 in cppcall at /home/isaiah/.julia/CXX/src/CXX.jl:904
 in include at ./boot.jl:245
 in include_from_node1 at ./loading.jl:128
 in process_options at ./client.jl:285
 in _start at ./client.jl:354
while loading /home/isaiah/.julia/CXX/test/qttest.jl, in expression starting on line 25

which is odd, because that function is available when I do using CXX (which completes without errors). I'm guessing it has something to do with the scope of the staged function?

Duplicate definition of std::vector crashes

Hi,

I'm fairly new to julia and Cxx - unbelievable work.

I've seen some issues where julia will dump core if a c++ variable is redefined. Works fine with simple types like int, but not with more complex containers.

Didn't seem like a known issue.

Any pointers appreciated. Thanks in advance!
Michael

For example, with an int:

julia> cxx"""int x;"""

julia> cxx"""int x;"""
In file included from :1:
:1:5: error: redefinition of 'x'
int x;
    ^
:1:5: note: previous definition is here
int x;
    ^

However, this blows up when I try doing the same thing with std::vector.

julia> cxxinclude("vector")

julia> cxx"""std::vector<int> z;"""

julia> cxx"""std::vector<int> z;"""
:1:18: error: redefinition of 'z'
std::vector<int> z;
                 ^
:1:18: note: previous definition is here
std::vector<int> z;
                 ^

signal (11): Segmentation fault
_ZNK5clang4Expr10getExprLocEv at /home/mturok/.julia/v0.4/Cxx/src/../deps/usr/lib/libcxxffi.so (unknown line)
_ZN5clang7CodeGen15CodeGenFunction32GenerateCXXGlobalVarDeclInitFuncEPN4llvm8FunctionEPKNS_7VarDeclEPNS2_14GlobalVariableEb at /home/mturok/.julia/v0.4/Cxx/src/../deps/usr/lib/libcxxffi.so (unknown line)
_ZN5clang7CodeGen13CodeGenModule28EmitCXXGlobalVarDeclInitFuncEPKNS_7VarDeclEPN4llvm14GlobalVariableEb at /home/mturok/.julia/v0.4/Cxx/src/../deps/usr/lib/libcxxffi.so (unknown line)
_ZN5clang7CodeGen13CodeGenModule23EmitGlobalVarDefinitionEPKNS_7VarDeclE at /home/mturok/.julia/v0.4/Cxx/src/../deps/usr/lib/libcxxffi.so (unknown line)
_ZN5clang7CodeGen13CodeGenModule20EmitGlobalDefinitionENS_10GlobalDeclEPN4llvm11GlobalValueE at /home/mturok/.julia/v0.4/Cxx/src/../deps/usr/lib/libcxxffi.so (unknown line)
_ZN5clang7CodeGen13CodeGenModule10EmitGlobalENS_10GlobalDeclE at /home/mturok/.julia/v0.4/Cxx/src/../deps/usr/lib/libcxxffi.so (unknown line)
unknown function (ip: 1933321651)
HandleTopLevelDecl at /home/mturok/.julia/v0.4/Cxx/deps/../src/bootstrap.cpp:193
_cxxparse at /home/mturok/.julia/v0.4/Cxx/deps/../src/bootstrap.cpp:330
cxxparse at /home/mturok/.julia/v0.4/Cxx/deps/../src/bootstrap.cpp:446
cxxparse at /home/mturok/.julia/v0.4/Cxx/src/Cxx.jl:47
anonymous at /home/mturok/.julia/v0.4/Cxx/src/Cxx.jl:1753
jl_apply at /home/mturok/src/julia/src/julia.h:983
jl_eh_restore_state at /home/mturok/src/julia/src/julia.h:1181
eval_user_input at ./REPL.jl:54
unknown function (ip: -2119051785)
jl_apply_generic at /home/mturok/src/julia/src/gf.c:1646
anonymous at ./task.jl:89
start_task at /home/mturok/src/julia/src/task.c:427
julia_trampoline at /home/mturok/src/julia/src/init.c:1015
unknown function (ip: 4199613)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 4199667)
unknown function (ip: 0)

Process julia segmentation fault (core dumped) at Wed Nov 26 11:16:29 2014

issues with include search path

Thanks for this very intresting project. It builds fine on arch linux, but when trying to run the examples it cannot include iostream. Arch linux seems to use the versioning scheme 4.9.2 which doen't fit with cxx_std_lib_version which currently assumes 4.9 exactly and the layout is also slightly different. $(gcc -print-prog-name=cc1plus) -v gives

#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/x86_64-unknown-linux-gnu
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/backward
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/include
 /usr/local/include
 /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/include-fixed
 /usr/include

After copying and pasting these paths into Cxx.jl manually it works like a charm, but perhaps some library function in libclang could be used to determine the correct search path automatically, or something.

@cxxnew fails with new build of Julia v0.4.0/Cxx

On OSX 10.9.5, after rebuilding julia-v0.4.0-dev from master and Pkg.build("Cxx") with the latest fixes, I see the following fatal ERROR that totally disrupts also my OpenCV.jl package:

julia> using Cxx
Warning: requiring "Cxx" did not define a corresponding module.
julia> using Base.Test
julia> cxx"""
       uint64_t foo2() {
           return $(1);
       }
       """
julia> x = @cxx foo2()
0x0000000000000001
julia> @test x == uint64(1)
julia> julia_global = 1
julia> cxx"""
       uint64_t bar() {
           return (uint64_t)$:(julia_global::Int64);
       }
       """
julia> bar() = @cxx bar()
bar (generic function with 1 method)
julia> @test bar() == uint64(1)
julia> julia_global = 2
julia> @test bar() == uint64(2)
julia> julia_global = 1.0
julia> @test_throws TypeError bar()
julia> julia_global = 1
julia> cxx"""
       class PrintTest {
       public:
           PrintTest() {
               abc = $:(julia_global::Int64);
           }
           int64_t abc;
       };
       """
julia> test = @cxxnew PrintTest()
Assertion failed: ((Flags & RF_IgnoreMissingEntries) && "Referenced value not in value map!"), function RemapInstruction, file /Users/maximilianosuster/julia-v0.4.0/deps/llvm-svn/lib/Transforms/Utils/ValueMapper.cpp, line 275.

signal (6): Abort trap: 6
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Abort trap: 6
logout

Clang.jl

@Keno, @ihnorton how do you see Clang.jl fitting in with this? Or has it kind of usurped Clang.jl in terms of functionality.

Function ref using `@cxx` broken

julia> @cxx bar50
ERROR: `convert` has no method matching convert(::Type{CppPtr{CppValue{CppBaseType{symbol("clang::Type")},(false,false,false)},(false,false,false)}}, ::QualType)

Windows support

Hi,
I don't read anywhere, if windows is supported or not.
I tried to build julia and ran into this:

which: no python in (/usr/local/bin:/usr/bin:/opt/bin:/mingw/bin:/python:/home/Sim/julia/usr/lib:/home/Sim/julia/usr/lib/julia:/c/Program Files/7-zip:/home/Sim/julia/usr/lib:/home/Sim/julia/usr/lib/julia:/c/Program Files/7-zip)
/bin/sh: line 3: ../configure: No such file or directory
Makefile:504: recipe for target 'llvm-svn/build_Release+Asserts/config.status' failed
make[2]: *** [llvm-svn/build_Release+Asserts/config.status] Error 127
Makefile:101: recipe for target 'julia-release' failed
make[1]: *** [julia-release] Error 2
Makefile:49: recipe for target 'release' failed
make: *** [release] Error 2

The llvm-svn folder is mostly empty...

Best,
Simon

Taking member function pointer

To make the Qt example nicer, I tried this:
setup(hibtn, @cxx(&QPushButton::clicked))
which fails with:

cpp_ref: cxxref(CppAddr((CppNNS{(:QPushButton,:clicked)})()))
cxxref: CppAddr{CppNNS{(:QPushButton,:clicked)}}
:1:1: error: must explicitly qualify name of member function when taking its address
^
QAbstractButton::
ERROR: `juliatype` has no method matching juliatype(::CppPtr{CppValue{CppBaseType{symbol("clang::Type")},(false,false,false)},(false,false,false)})
while loading /home/isaiah/.julia/Cxx/test/qt1.jl, in expression starting on line 80

and this
setup(hibtn, pcpp"QPushButton::clicked"), which fails with:

jldev: /cmn/jldev/deps/llvm-svn/tools/clang/lib/Frontend/../../include/clang/AST/Type.h:562: const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' failed.

signal (6): Aborted

Is there a way to do this that I am missing?

Conflict between system and julia's LLVM

I am not sure what I am doing wrong, but I am getting errors that suggest that there is a conflict between the LLVM installed on my linux box (archlinux) and the one julia builds. Is there a way to make Cxx exclusively use julia's LLVM?

julia> Pkg.build("Cxx")
INFO: Building Cxx
Tuning for julia installation at: /data/phd/github/julia.4/usr/bin
    CC /home//.julia/v0.4/Cxx/deps/build/bootstrap.o
In file included from /usr/include/llvm/IR/ValueMap.h:30:0,
                 from ../src/bootstrap.cpp:14:
/usr/include/llvm/IR/ValueHandle.h:27:7: error: redefinition of ‘class llvm::PointerLikeTypeTraits<llvm::ValueHandleBase**>’
 class PointerLikeTypeTraits<ValueHandleBase**> {
       ^
In file included from /data/phd/github/julia.4/usr/bin/../../usr/include/llvm/ADT/ValueMap.h:31:0,
                 from /data/phd/github/julia.4/usr/bin/../../usr/include/llvm/ExecutionEngine/ExecutionEngine.h:22,
                 from ../src/bootstrap.cpp:13:
/data/phd/github/julia.4/usr/bin/../../usr/include/llvm/Support/ValueHandle.h:27:7: error: previous definition of ‘class llvm::PointerLikeTypeTraits<llvm::ValueHandleBase**>’
 class PointerLikeTypeTraits<ValueHandleBase**> {

Support for other LLVM languages

Can you add support for other LLVM language like Rust and LLVM-based D compiler so these libraries also can be consumed from Julia?

missing vtable

The following is a reduced testcase. It ends with:

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

which means that the vtable for class A is missing.

using Cxx

cxx"""
class A
{
public:
    virtual void f();
};

class B : public A
{
public:
    void f() {}
};

void F()
{
    B b;
    b.f();
}
"""

@cxx F()

Using CXX

Sorry to open issues in order to ask questions, but I'm not sure where I should be directing questions.

In the examples I can find for using CXX people seem to be doing

using CXX

However, when I do this it doesn't seem to find a module called CXX.

I notice when the build was done it did not build a debug build because there was not a corresponding Julia debug build. Is this what I'm missing?

Cxx test failures (missing header defines)

At the current moment, Julia and LLVM both seem to be compiling without issue, and Cxx builds fine, but I am getting the following error messages when running the Cxx tests:

julia> Pkg.test("Cxx")
INFO: Testing Cxx
Warning: requiring "Cxx" did not define a corresponding module.
In file included from :1:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/llvm/IR/Module.h:20:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/llvm/IR/DataLayout.h:23:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/llvm/ADT/DenseMap.h:20:
/home/wbhart/julia/usr/bin/../../usr/include/llvm/Support/MathExtras.h:272:24: error: use of undeclared identifier 'INT64_C'
  return N >= 64 || (-(INT64_C(1)<<(N-1)) <= x && x < (INT64_C(1)<<(N-1)));
                       ^
/home/wbhart/julia/usr/bin/../../usr/include/llvm/Support/MathExtras.h:272:56: error: use of undeclared identifier 'INT64_C'
  return N >= 64 || (-(INT64_C(1)<<(N-1)) <= x && x < (INT64_C(1)<<(N-1)));
                                                       ^
/home/wbhart/julia/usr/bin/../../usr/include/llvm/Support/MathExtras.h:298:26: error: use of undeclared identifier 'UINT64_C'
  return N >= 64 || x < (UINT64_C(1)<<(N));
                         ^
/home/wbhart/julia/usr/bin/../../usr/include/llvm/Support/MathExtras.h:330:24: error: use of undeclared identifier 'INT64_C'
  return N >= 64 || (-(INT64_C(1)<<(N-1)) <= x && x < (INT64_C(1)<<(N-1)));
                       ^
/home/wbhart/julia/usr/bin/../../usr/include/llvm/Support/MathExtras.h:330:56: error: use of undeclared identifier 'INT64_C'
  return N >= 64 || (-(INT64_C(1)<<(N-1)) <= x && x < (INT64_C(1)<<(N-1)));
                                                       ^
In file included from :1:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/llvm/IR/Module.h:20:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/llvm/IR/DataLayout.h:25:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/llvm/IR/DerivedTypes.h:21:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/llvm/IR/Type.h:19:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/llvm/ADT/APFloat.h:20:
/home/wbhart/julia/usr/bin/../../usr/include/llvm/ADT/APInt.h:1533:14: error: use of undeclared identifier 'UINT32_MAX'
      return UINT32_MAX;
             ^
i64*
In file included from :1:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Interpreter/CommandInterpreter.h:19:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Core/Debugger.h:24:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Core/SourceManager.h:21:
/home/wbhart/julia/usr/bin/../../usr/include/lldb/Host/FileSpec.h:531:62: error: use of undeclared identifier 'SIZE_MAX'
    MemoryMapFileContents (off_t offset = 0, size_t length = SIZE_MAX) const;
                                                             ^
/home/wbhart/julia/usr/bin/../../usr/include/lldb/Host/FileSpec.h:561:57: error: use of undeclared identifier 'SIZE_MAX'
    ReadFileContents (off_t offset = 0, size_t length = SIZE_MAX, Error *error_ptr = NULL) const;
                                                        ^
In file included from :1:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Interpreter/CommandInterpreter.h:19:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Core/Debugger.h:27:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/DataFormatters/FormatManager.h:23:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/DataFormatters/FormattersContainer.h:40:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Target/TargetList.h:19:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Target/Target.h:25:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Core/Disassembler.h:23:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Core/EmulateInstruction.h:19:
/home/wbhart/julia/usr/bin/../../usr/include/lldb/Core/Opcode.h:86:46: error: use of undeclared identifier 'UINT8_MAX'
        GetOpcode8 (uint8_t invalid_opcode = UINT8_MAX) const
                                             ^
/home/wbhart/julia/usr/bin/../../usr/include/lldb/Core/Opcode.h:102:48: error: use of undeclared identifier 'UINT16_MAX'
        GetOpcode16 (uint16_t invalid_opcode = UINT16_MAX) const
                                               ^
In file included from :1:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Interpreter/CommandInterpreter.h:19:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Core/Debugger.h:27:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/DataFormatters/FormatManager.h:23:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/DataFormatters/FormattersContainer.h:40:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Target/TargetList.h:19:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Target/Target.h:25:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Core/Disassembler.h:23:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Core/EmulateInstruction.h:20:
/home/wbhart/julia/usr/bin/../../usr/include/lldb/Core/RegisterValue.h:164:42: error: use of undeclared identifier 'UINT8_MAX'
        GetAsUInt8 (uint8_t fail_value = UINT8_MAX, bool *success_ptr = NULL) const
                                         ^
/home/wbhart/julia/usr/bin/../../usr/include/lldb/Core/RegisterValue.h:178:44: error: use of undeclared identifier 'UINT16_MAX'
        GetAsUInt16 (uint16_t fail_value = UINT16_MAX, bool *success_ptr = NULL) const;
                                           ^
In file included from :1:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Interpreter/CommandInterpreter.h:19:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Core/Debugger.h:27:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/DataFormatters/FormatManager.h:24:
/home/wbhart/julia/usr/bin/../../usr/include/lldb/DataFormatters/TypeCategory.h:83:48: error: use of undeclared identifier 'UINT16_MAX'
        static const uint16_t ALL_ITEM_TYPES = UINT16_MAX;
                                               ^
In file included from :1:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Interpreter/CommandInterpreter.h:22:
/home/wbhart/julia/usr/bin/../../usr/include/lldb/Interpreter/CommandHistory.h:62:29: error: use of undeclared identifier 'SIZE_MAX'
          size_t stop_idx = SIZE_MAX) const;
                            ^
In file included from :1:
In file included from /home/wbhart/julia/usr/bin/../../usr/include/lldb/Interpreter/CommandReturnObject.h:21:
/home/wbhart/julia/usr/bin/../../usr/include/lldb/Core/StreamTee.h:103:36: error: use of undeclared identifier 'SIZE_MAX'
        size_t min_bytes_written = SIZE_MAX;
                                   ^
/home/wbhart/julia/usr/bin/../../usr/include/lldb/Core/StreamTee.h:119:34: error: use of undeclared identifier 'SIZE_MAX'
        if (min_bytes_written == SIZE_MAX)
                                 ^
Warning: requiring "Cxx" did not define a corresponding module.
Warning: requiring "Cxx" did not define a corresponding module.
foo
foo
foo
foo
foo
foo
foo
foo
foo
foo
1
2
3
4
5
6
7
8
9
10
Warning: requiring "Cxx" did not define a corresponding module.
ERROR: Graphs not found
 in require at ./loading.jl:49
 in require4105 at /home/wbhart/julia/usr/bin/../lib/julia/sys.so
 in include at ./boot.jl:242
 in include_from_node1 at ./loading.jl:128
 in include at ./boot.jl:242
 in process_options at ./client.jl:300
 in _start at ./client.jl:382
 in _start4030 at /home/wbhart/julia/usr/bin/../lib/julia/sys.so
while loading /home/wbhart/.julia/v0.4/Cxx/test/llvmgraph.jl, in expression starting on line 2
while loading /home/wbhart/.julia/v0.4/Cxx/test/runtests.jl, in expression starting on line 4

=================================[ ERROR: Cxx ]=================================

failed process: Process(`/home/wbhart/julia/usr/bin/julia /home/wbhart/.julia/v0.4/Cxx/test/runtests.jl`, ProcessExited(1)) [1]

================================================================================
INFO: No packages to install, update or remove
ERROR: Cxx had test errors
 in cd at ./file.jl:20

Here is my versioninfo()

julia> versioninfo()
Julia Version 0.4.0-dev+1970
Commit 7dd805f* (2014-12-06 11:22 UTC)
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: AMD Opteron(tm) Processor 6174
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Barcelona)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-svn

I also have:

shell> g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.1-2ubuntu1~12.04' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.1 (Ubuntu 4.8.1-2ubuntu1~12.04)

@cxx segfaults passing string to C++ function declared extern "C"

We have a function called PrintS which accepts a string in C++ declared extern "C".

We have a string object, called s:

julia> s
Ptr{UInt8} @0x0000000009deb988

If we do the following, the string is printed without issue:

julia> icxx"PrintS($s);"

But the following segfaults (also happens in a slightly earlier version of Cxx that passes its test suite):

julia> @cxx PrintS(s)
julia: /home/wbhart/julia/deps/llvm-svn/tools/clang/lib/AST/DeclBase.cpp:1299: clang::DeclContext::lookup_result clang::DeclContext::lookup(clang::DeclarationName): Assertion `DeclKind != Decl::LinkageSpec && "Should not perform lookups into linkage specs!"' failed.

signal (6): Aborted
gsignal at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 1740803486)
unknown function (ip: 1740803650)
_ZN5clang11DeclContext6lookupENS_15DeclarationNameE at /home/wbhart/.julia/v0.4/Cxx/src/../deps/usr/lib/libcxxffi.so (unknown line)
unknown function (ip: 949332921)
unknown function (ip: 949335829)
BuildDeclarationNameExpr at /home/wbhart/.julia/v0.4/Cxx/deps/../src/bootstrap.cpp:1153
unknown function (ip: 859353246)
unknown function (ip: 859353325)
jl_apply_generic at /home/wbhart/julia/src/gf.c:1646
unknown function (ip: 859465199)
unknown function (ip: 859466871)
jl_apply_generic at /home/wbhart/julia/src/gf.c:1646
unknown function (ip: 859521207)
jl_instantiate_staged at /home/wbhart/julia/src/gf.c:978
jl_mt_assoc_by_type at /home/wbhart/julia/src/gf.c:1030
jl_apply_generic at /home/wbhart/julia/src/gf.c:1634
do_call at /home/wbhart/julia/src/interpreter.c:71
eval at /home/wbhart/julia/src/interpreter.c:210
jl_toplevel_eval_flex at /home/wbhart/julia/src/toplevel.c:515
jl_eh_restore_state at /home/wbhart/julia/src/julia.h:1181
unknown function (ip: 1752061126)
unknown function (ip: 1752061431)
jl_apply_generic at /home/wbhart/julia/src/gf.c:1646
unknown function (ip: 1752191183)
start_task at /home/wbhart/julia/src/task.c:410
julia_trampoline at /home/wbhart/julia/src/init.c:1016
unknown function (ip: 4199549)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 4199605)
Aborted (core dumped)

It works fine if we call it directly using ccall because the function is declared extern "C". (We are slurping the header in where this function's prototypes exist, but apparently @cxx doesn't realise it is using the C calling conventions.)

trouble with qttest.jl on Linux with package libraries

I was trying to get test/qttest.jl running on Linux (Ubuntu 14.04), using package-installed libraries, and haven't had any success yet.

Steps I took:

  1. copied your Make.user from julia-dev (https://groups.google.com/d/msg/julia-dev/4kUu2ieWZ9Q/Qesdblf-ixkJ), ran make cleanall; make, and installed and built Cxx.jl
  2. applied #10, and modified qttest.jl as below
using Cxx

const qtlibdir = "/usr/lib/x86_64-linux-gnu"
const qtincludedir = "/usr/include/qt5"
const QtCore = joinpath(qtlibdir,"libQt5Core.so")
const QtWidgets = joinpath(qtlibdir,"libQt5Widgets.so") 

addHeaderDir(qtincludedir; isFramework = true, kind = C_System)
#addHeaderDir(qtincludedir; kind = C_System)

dlopen(QtCore)
addHeaderDir(joinpath(qtincludedir, "QtCore"))

dlopen(QtWidgets)
addHeaderDir(joinpath(qtincludedir, "QtWidgets"))

#cxxinclude("QtWidgets/QApplication")    # ERROR HERE
#cxxinclude("QtWidgets/QMessageBox")
cxxinclude("QApplication")    # ERROR HERE
cxxinclude("QMessageBox")


x = Ptr{Uint8}[pointer("julia"),C_NULL]
app = @cxx QApplication(int32(0),pointer(x))

@cxx QMessageBox::about(cast(C_NULL,pcpp"QWidget"), pointer("Hello World"), pointer("This is a QMessageBox!"))

@cxx app->exec()

With this, I either get

In file included from :1:
In file included from /usr/include/qt5/QtWidgets/QApplication:1:
/usr/include/qt5/QtWidgets/qapplication.h:45:10: fatal error: 'QtCore/qcoreapplication.h' file not found
#include <QtCore/qcoreapplication.h>
         ^

or, if I say that the Qt5 includes is not a "framework" and change the invocation to QtWidgets/Qapplication, I get

 cxxinclude("QtWidgets/QApplication")
In file included from :1:
In file included from /usr/include/qt5/QtWidgets/QApplication:1:
In file included from /usr/include/qt5/QtWidgets/qapplication.h:45:
In file included from /usr/include/qt5/QtCore/qcoreapplication.h:45:
/usr/include/qt5/QtCore/qglobal.h:1008:4: error: "You must build your code with position independent code if Qt was built with -reduce-relocations. "         "Compile your code with -fPIC or -fPIE."
#  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
   ^

@ihnorton, did you do anything else to get that example to run, beyond what you submitted in #7? Is it possible to set the equivalent of -fPIC or even use package libraries, or is the Qt source needed?

Passing intialized C++ structures to Julia and then back to C++

I have managed to wrap a large fraction of the OpenCV library by now - and even the GUI interface works well with the @cxx macros. However, I encountered something a little odd when trying to call C++ structures that appear to be intialized properly using @cxx.

For example, calling the OpenCV "cv::Mat" constructors in the following way works fine:

# empty image array using @cxx cv::Mat() 
julia > Mat()      

#  # Mat, 600 x600 uint8 gray using @cxx cv::Mat(rows, cols, matType)
julia> img1 = Mat(600, 600, CV_8UC1)  

Constructing a size_t vector cv::Size(rows, columns) is also fine:

# cvSize(width, height) = @cxx cv::Size(width,height)
julia> imgSize = cvSize(500, 250)
CppValue{symbol("cv::Size_"),(Int32,)}(Uint8[0xf4,0x01,0x00,0x00,0xfa,0x00,0x00,0x00])

However, for some reason that I don´t understand, something that worked fine a couple of days ago now does not work:

# Mat(size, matType::CV_MatType) = @cxx cv::Mat(imgSize, matType)
julia> img2 = Mat(imgSize, CV_8UC1)
ERROR: Got bad type information while compiling CppNNS{(:cv,:Mat,:zeros)} (got Type{Uint64} for argument 1)

Do you have any hints as to what I should do to pass these arguments properly? The Mat constructor for these arguments expects the following:

Mat::Mat(Size size, int type)

I assume that Size should be a size_t (Uint64) equivalent, but what is the correct way to pass the it to a @cxx call of the Mat constructor or generally to other functions (assuming it does not need to be modified)?

Building on RHEL

I'm submitting this issue to document my experience trying to build Cxx on RHEL 6.5. Hopefully this helps somebody...

First of all, now that JuliaLang/julia#8297 has been merged, kf/staged needs to be rebased.

I used the following Make.user

$ cat Make.user 
LLVM_VER=svn
LLVM_ASSERTIONS=1
#LLVM_DEBUG=1
BUILD_LLVM_CLANG=1
BUILD_LLDB=1
LLDB_VER = master
USE_LLVM_SHLIB=1
LLDB_DISABLE_PYTHON=1

In order to build LLVM-SVN, I needed to upgrade gcc from v4.4 to v4.9 and apply this patch to LLVM.

LLDB wouldn't link without adding LLVM_LDFLAGS += -lpthread to deps/Makefile

After this, Julia builds and I get

julia> Pkg.clone("https://github.com/Keno/Cxx.jl") 
INFO: Cloning Cxx from https://github.com/Keno/Cxx.jl
INFO: Computing changes...

julia> Pkg.build("Cxx")
INFO: Building Cxx
Tuning for julia installation at: /scr2/mweastwood/julia/usr/bin
    CC /home/mweastwood/.julia/Cxx/deps/build/bootstrap.o
    LINK /home/mweastwood/.julia/Cxx/deps/usr/lib/libcxxffi.so
/scr2/mweastwood/julia/usr/bin/../../usr/lib/liblldbExpression.a(ClangExpressionParser.o): In function `lldb_private::ClangExpressionParser::Parse(lldb_private::Stream&)':
ClangExpressionParser.cpp:(.text._ZN12lldb_private21ClangExpressionParser5ParseERNS_6StreamE+0x394): warning: the use of `mktemp' is dangerous, better use `mkstemp'
Not building debug library because corresponding julia DEBUG library does not exist.
To build, simply run the build again once the library at
/scr2/mweastwood/julia/usr/bin/../../usr/lib/libjulia-debug.so
has been built.

julia> using Cxx
ERROR: error compiling init: could not load module libcxxffi: libcxxffi: cannot open shared object file: No such file or directory
 in include at ./boot.jl:246
 in include_from_node1 at ./loading.jl:128
 in reload_path at ./loading.jl:152
 in _require at ./loading.jl:67
 in require at ./loading.jl:52
while loading /home/mweastwood/.julia/Cxx/src/Cxx.jl, in expression starting on line 37

After changing "libcxxffi" to "libcxxffi.so" here I get

julia> using Cxx
Warning: redefining constant libcxxffi
ERROR: error compiling init: could not load module libcxxffi.so: /scr2/mweastwood/julia/usr/bin/../lib/libcxxffi.so: undefined symbol: _ZN12lldb_private15HostThreadPosix4JoinEPPv
 in include at ./boot.jl:246
 in include_from_node1 at ./loading.jl:128
 in reload_path at ./loading.jl:152
 in _require at ./loading.jl:67
 in require at ./loading.jl:52
while loading /home/mweastwood/.julia/Cxx/src/Cxx.jl, in expression starting on line 37

And now I'm stuck. :(

julia> versioninfo()
Julia Version 0.4.0-dev+715
Commit ea49d91* (2014-09-21 05:48 UTC)
Platform Info:
  System: Linux (x86_64-unknown-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-1620 v2 @ 3.70GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-svn

Build issues on linux

I compiled julia using this Make.user:
LLVM_ASSERTIONS=1
LLVM_VER=svn
BUILD_LLVM_CLANG=1
BUILD_LLDB=1
LLDB_VER=master
USE_LLVM_SHLIB=1
LLDB_DISABLE_PYTHON=1
(this could be added to README.md btw)

and then:

julia> Pkg.clone("https://github.com/Keno/Cxx.jl.git")
INFO: Cloning Cxx from https://github.com/Keno/Cxx.jl.git
INFO: Computing changes...
julia> Pkg.build("Cxx")
INFO: Building Cxx
Tuning for julia installation at: /home/luther/software/julia_cxx/usr/bin
CC /home/luther/.julia/v0.4/Cxx/deps/build/bootstrap.o
LINK /home/luther/.julia/v0.4/Cxx/deps/usr/lib/libcxxffi.so
/usr/bin/ld: cannot find -llldbCore
/usr/bin/ld: cannot find -llldbDataFormatters
/usr/bin/ld: cannot find -llldbExpression
(and lots of other lldb libs)

These libs are indeed missing:
$ ls usr/lib/liblldb*
usr/lib/liblldbAPI.a usr/lib/liblldbBreakpoint.a usr/lib/liblldbCommands.a usr/lib/liblldbInitAndLog.a

Building with OSX/Julia Nightly

julia> Pkg.build("Cxx")
INFO: Building Cxx
Tuning for julia installation at: /Applications/Julia-0.4.0-dev-0fe184e0c0.app/Contents/Resources/julia/bin
BuildBootstrap.Makefile:2: /Applications/Julia-0.4.0-dev-0fe184e0c0.app/Contents/Resources/julia/bin/../../deps/Versions.make: No such file or directory
BuildBootstrap.Makefile:3: /Applications/Julia-0.4.0-dev-0fe184e0c0.app/Contents/Resources/julia/bin/../../Make.inc: No such file or directory
make: *** No rule to make target `/Applications/Julia-0.4.0-dev-0fe184e0c0.app/Contents/Resources/julia/bin/../../Make.inc'. Stop.
=================================[ ERROR: Cxx ]=================================

failed process: Process(make -f BuildBootstrap.Makefile JULIA_HOME=/Applications/Julia-0.4.0-dev-0fe184e0c0.app/Contents/Resources/julia/bin, ProcessExited(2)) [2]
while loading /Users/rhl/.julia/v0.4/Cxx/deps/build.jl, in expression starting on line 16

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

WARNING: Cxx had build errors.

  • packages with build errors remain installed in /Users/rhl/.julia/v0.4
  • build a package and all its dependencies with Pkg.build(pkg)
  • build a single package by running its deps/build.jl script

Latest nightly build failure

We tried to build CXX with the latest Julia-0.4 nightly on Ubuntu 12.04 with gcc-4.8.

julia> Pkg.build()
INFO: Building CXX
Tuning for julia installation at: /home/wbhart/julia/usr/bin
    CC /home/wbhart/.julia/v0.4/CXX/deps/build/bootstrap.o
../src/bootstrap.cpp:14:30: fatal error: llvm/IR/ValueMap.h: No such file or directory
 #include "llvm/IR/ValueMap.h"
                              ^
compilation terminated.
make: *** [build/bootstrap.o] Error 1
=================================[ ERROR: CXX ]=================================

failed process: Process(`make -f BuildBootstrap.Makefile JULIA_HOME=/home/wbhart/julia/usr/bin`, ProcessExited(2)) [2]
while loading /home/wbhart/.julia/v0.4/CXX/deps/build.jl, in expression starting on line 16

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

It looks like the LLVM file it is looking for no longer exists in the LLVM that Julia-0.4 uses.

[We tried building CXX with Julia-0.3 but it was looking for a source tree for Julia (starting from JULIA_HOME) but we had a binary installation of Julia 0.3 only. Should CXX work with Julia-0.3 with a source build? Or are you targeting Julia 0.4.]

Reference returns are broken

C++ > int &bar(int *foo) {
      return *foo;
      }

C++ > int x = 6;

C++ > bar(&x)
Function return type does not match operand type of return inst!
  ret i32* %call
 i32
define i32 @0() {
top:
  %call = call dereferenceable(4) i32* @_ZN6__icxx5icxx9Ev()
  ret i32* %call
}

ERROR: error compiling anonymous: Malformed LLVM Function

Build Failure from Ctors

I'm not quite sure what I am seeing. This is with a fresh pull of Cxx and Julia:

steve:~/.julia/v0.4/Cxx(master)$ git rev-parse HEAD
12298db48f8619b4931025ddb2844c64f12383dd
julia> versioninfo()
Julia Version 0.4.0-dev+2721
Commit 0dae54c (2015-01-15 18:18 UTC)
Platform Info:
  System: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-svn

julia> Pkg.build("Cxx")
INFO: Building Cxx
Tuning for julia installation at: /home/steve/Software/julia/usr/bin
    CC /home/steve/.julia/v0.4/Cxx/deps/build/bootstrap.o
../src/bootstrap.cpp:375:36: error: 'CtorList' is a private member of 'clang::CodeGen::CodeGenModule'
    clang::CodeGen::CodeGenModule::CtorList &ctors = clang_cgm->getGlobalCtors();
                                   ^
/home/steve/Software/julia/usr/bin/../../deps/llvm-svn/tools/clang/lib/CodeGen/CodeGenModule.h:275:33: note: implicitly declared private here
  typedef std::vector<Structor> CtorList;
                                ^
../src/bootstrap.cpp:375:65: error: no member named 'getGlobalCtors' in 'clang::CodeGen::CodeGenModule'; did you mean 'GlobalCtors'?
    clang::CodeGen::CodeGenModule::CtorList &ctors = clang_cgm->getGlobalCtors();
                                                                ^~~~~~~~~~~~~~
                                                                GlobalCtors
/home/steve/Software/julia/usr/bin/../../deps/llvm-svn/tools/clang/lib/CodeGen/CodeGenModule.h:351:12: note: 'GlobalCtors' declared here
  CtorList GlobalCtors;
           ^
../src/bootstrap.cpp:375:54: error: type 'CtorList' (aka 'vector<clang::CodeGen::CodeGenModule::Structor>') does not provide a call operator
    clang::CodeGen::CodeGenModule::CtorList &ctors = clang_cgm->getGlobalCtors();
                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~
3 errors generated.
BuildBootstrap.Makefile:66: recipe for target 'build/bootstrap.o' failed
make: *** [build/bootstrap.o] Error 1

Embedded C code?

I've been thinking about how you might implement something like critcl for Julia.

critcl is a Tcl feature that allows writing C code in-line in a Tcl program and creating Tcl procedures with the body implemented in C.

When interfacing with a complex external C library, a common pattern in Tcl is to write a procedure using in-line C to deal with c-structs, type conversion etc.

I don't fully understand how Cxx.jl works, but what I've read tells me that there is an embedded C compiler involved. So, my question is: how hard would it be to extend Cxx.jl to implement a Julia macro that takes some C-code as one of its arguments and generate a Julia-callable C function on the fly?

critcl examples:

http://wiki.tcl.tk/11227

https://github.com/tcltk/tcllib/blob/master/modules/uuid/uuid.tcl#L105

https://github.com/tcltk/tcllib/blob/master/modules/md5crypt/md5cryptc.tcl#L169

http://andreas-kupries.github.io/critcl/

assert on invalid code

$ ./julia -e 'using Cxx; cxx"""auto x = 3;"""; cxx"""auto x = 3;"""'
Warning: requiring "Cxx" did not define a corresponding module.
In file included from :1:
:1:6: error: redefinition of 'x'
auto x = 3;
     ^
:1:6: note: previous definition is here
auto x = 3;
     ^
Unexpected undeduced auto type!
UNREACHABLE executed at /home/luther/software/julia_cxx/deps/llvm-svn/tools/clang/lib/CodeGen/CodeGenTypes.cpp:406!

Changing the code from auto to int avoids the crash.

Edit:
I think this is an issue with the error handling (or lack thereof). Here is another example. Executing h2 prints an error (because C and ~C are private) but the functions are still executed (ctor and dtor is still printed).

function h2()
       icxx"""
          class C { C() {std::cout << "ctor\n";}  ~C() {std::cout << "dtor\n";} }; 
          auto c = std::make_shared<C>();
       """
end

std::cout not working: missing in namespace 'std'

After adding fix #50, std::cout is working in replpane but not when wrapped with cxx""" ... """
Would be good to fix this soon as std::cout is rather commonly used.

julia> cxx""" #include<iostream> """
julia> cxx"""
       std::cout << "Hello" << std::endl;
       """
In file included from :1:
:2:6: error: no type named 'cout' in namespace 'std'
std::cout << "Hello" << std::endl;
~~~~~^
:2:11: error: expected unqualified-id
std::cout << "Hello" << std::endl;
          ^
julia> include(joinpath(Pkg.dir("Cxx"), "src/CxxREPL/replpane.jl"))
C++ > std::cout << "Hello" << std::endl;
Hello

Pkg.build("Cxx") build ERROR on OSX -- _BuildDeclarationNameExpr

I just rebuilt Julia v0.4.0-dev from source after git pull on julia and llvm-svn and get a new ERROR when using Pkg.build("Cxx"). Frustrating considering that this was working ok just before updating. . . Any thoughts on how to deal with this ERROR?

julia> Pkg.build("Cxx")
INFO: Building Cxx
Tuning for julia installation at: /Users/maximilianosuster/julia-v0.4.0/usr/bin
    LINK /Users/maximilianosuster/.julia/Cxx/deps/usr/lib/libcxxffi.dylib
Undefined symbols for architecture x86_64:
  "clang::Sema::BuildDeclarationNameExpr(clang::CXXScopeSpec const&, clang::LookupResult&, bool)", referenced from:
      _BuildDeclarationNameExpr in bootstrap.o
     (maybe you meant: __ZN5clang4Sema24BuildDeclarationNameExprERKNS_12CXXScopeSpecERNS_12LookupResultEbb)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [usr/lib/libcxxffi.dylib] Error 1
=========================================[ ERROR: Cxx ]=========================================

failed process: Process(`make -f BuildBootstrap.Makefile JULIA_HOME=/Users/maximilianosuster/julia-v0.4.0/usr/bin`, ProcessExited(2)) [2]
while loading /Users/maximilianosuster/.julia/Cxx/deps/build.jl, in expression starting on line 16

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

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

WARNING: Cxx had build errors.

 - packages with build errors remain installed in /Users/maximilianosuster/.julia
 - build a package and all its dependencies with `Pkg.build(pkg)`
 - build a single package by running its `deps/build.jl` script

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

missing CodeGenModule.h

Hi,
I sucessufly build Julia with the following changes to Make.user but getting following error when building the package:

julia> Pkg.build("Cxx")
INFO: Building Cxx
Tuning for julia installation at: /home/kuba/PRJ/JULIA/0.4/julia/usr/bin
CC /home/kuba/.julia/v0.4/Cxx/deps/build/bootstrap.o
../src/bootstrap.cpp:49:35: fatal error: CodeGen/CodeGenModule.h: No such file or directory
#include "CodeGen/CodeGenModule.h"
^
compilation terminated.
make: *** [build/bootstrap.o] Error 1

Julia:
Version 0.4.0-dev+949 (2014-10-05 02:28 UTC)
Commit 7dd704b (1 day old master)
x86_64-redhat-linux

Thanks for looking into this,
kuba

Conversion errors with std::map when calling c++ functions using julia for intermediate variables

From julia/cxx, when I call a c++ function that uses a std::map, I'm seeing errors with implicit conversions/promotions.

I define the following c++ code within the julia session, via the cxx macro. When I call mainMap() from julia, all works fine.

When I call the underlying functions within julia, holding a std::map in a julia variable as an intermediate, I get compiler errors about no known conversions (related to const-ness, or std::basic_string vs std::string).

I'll show the working and failing snippets from my repl below. Happy to debug - any pointers appreciated.

#include <map>
#include <string>
#include <iostream>

typedef std::map<std::string, std::string> Map;

Map getMap()
{ 
    return Map({ {"hello", "world"}, {"everything", "awesome"} });
}
void dumpMap(Map m)
{
    for (auto it = m.cbegin(); it != m.cend(); ++it)
        std::cout << "[" << (*it).first << ":" << (*it).second << "]" << std::endl;
}
void mainMap()
{
    Map m = getMap();
    dumpMap(m);
};

Calling the mainMap function works fine:

julia> @cxx mainMap()
[everything:awesome]
[hello:world]

Now, I can create the map within julia and show that I can access a pair looked up via find():

julia> m = @cxx getMap()
CppValue{symbol("std::map"),(CppValue{symbol("std::basic_string"),(UInt8,CppValue{symbol("std::char_traits"),(UInt8,)},CppValue{symbol("std::allocator"),(UInt8,)})},CppValue{symbol("std::basic_string"),(UInt8,CppValue{symbol("std::char_traits"),(UInt8,)},CppValue{symbol("std::allocator"),(UInt8,)})},CppValue{symbol("std::less"),(CppValue{symbol("std::basic_string"),(UInt8,CppValue{symbol("std::char_traits"),(UInt8,)},CppValue{symbol("std::allocator"),(UInt8,)})},)},CppValue{symbol("std::allocator"),(CppValue{symbol("std::pair"),(CppValue{symbol("std::basic_string"),(UInt8,CppValue{symbol("std::char_traits"),(UInt8,)},CppValue{symbol("std::allocator"),(UInt8,)})},CppValue{symbol("std::basic_string"),(UInt8,CppValue{symbol("std::char_traits"),(UInt8,)},CppValue{symbol("std::allocator"),(UInt8,)})})},)})}(UInt8[0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00    0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00])

julia> pair = @cxx m->find(pointer("everything"))
CppValue{symbol("std::_Rb_tree_iterator"),(CppValue{symbol("std::pair"),(CppValue{symbol("std::basic_string"),(UInt8,CppValue{symbol("std::char_traits"),(UInt8,)},CppValue{symbol("std::allocator"),(UInt8,)})},CppValue{symbol("std::basic_string"),(UInt8,CppValue{symbol("std::char_traits"),(UInt8,)},CppValue{symbol("std::allocator"),(UInt8,)})})},)}(UInt8[0xa0,0xcc,0x77,0x08,0x00,0x00,0x00,0x00])

julia> icxx"""std::cout << $pair->first << ": " << $pair->second << std::endl;""";
everything: awesome

The failures happens when I want to pass the std::map into an underlying function. I tried passing it by value and by reference. Conversion errors happen whether I use the @cxx macro call, or use the icxx""" interface.

julia> m = @cxx getMap()
CppValue{symbol("std::map"),(CppValue{symbol("std::basic_string"),(UInt8,CppValue{symbol("std::char_traits"),(UInt8,)},CppValue{symbol("std::allocator"),(UInt8,)})},CppValue{symbol("std::basic_string"),(UInt8,CppValue{symbol("std::char_traits"),(UInt8,)},CppValue{symbol("std::allocator"),(UInt8,)})},CppValue{symbol("std::less"),(CppValue{symbol("std::basic_string"),(UInt8,CppValue{symbol("std::char_traits"),(UInt8,)},CppValue{symbol("std::allocator"),(UInt8,)})},)},CppValue{symbol("std::allocator"),(CppValue{symbol("std::pair"),(CppValue{symbol("std::basic_string"),(UInt8,CppValue{symbol("std::char_traits"),(UInt8,)},CppValue{symbol("std::allocator"),(UInt8,)})},CppValue{symbol("std::basic_string"),(UInt8,CppValue{symbol("std::char_traits"),(UInt8,)},CppValue{symbol("std::allocator"),(UInt8,)})})},)})}(UInt8[0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00    0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00])

julia> @cxx dumpMap(m)
:1:1: error: no viable conversion from 'map<std::basic_string<char>, std::basic_string<char>, std::less<std::basic_string<char> >, allocator<pair<basic_string<char, std::char_traits<char>, std::allocator<char>>, std::basic_string<char>>>>' to 'map<std::string, std::string, std::less<std::basic_string<char> >, allocator<pair<const basic_string<char, std::char_traits<char>, std::allocator<char>>, std::basic_string<char>>>>'
^
/usr/include/c++/4.8/bits/stl_map.h:180:7: note: candidate constructor not viable: no known conversion 
from 'std::map<std::basic_string<char>, std::basic_string<char>, std::less<std::basic_string<char> >, std::allocator<std::pair<std::basic_string<char>, std::basic_string<char> > > >'
  to 'const std::map<std::basic_string<char>, std::basic_string<char>, std::less<std::basic_string<char> >, std::allocator<std::pair<const std::basic_string<char>, std::basic_string<char> > > > &' for 1st argument
      map(const map& __x)
      ^
/usr/include/c++/4.8/bits/stl_map.h:191:7: note: candidate constructor not viable: no known conversion from 'std::map<std::basic_string<char>, std::basic_string<char>, std::less<std::basic_string<char> >, std::allocator<std::pair<std::basic_string<char>, std::basic_string<char> > > >' to 'std::map<std::basic_string<char>, std::basic_string<char>, std::less<std::basic_string<char> >, std::allocator<std::pair<const std::basic_string<char>, std::basic_string<char> > > > &&' for 1st argument
      map(map&& __x)
      ^
/usr/include/c++/4.8/bits/stl_map.h:206:7: note: candidate constructor not viable: no known conversion from 'std::map<std::basic_string<char>, std::basic_string<char>, std::less<std::basic_string<char> >, std::allocator<std::pair<std::basic_string<char>, std::basic_string<char> > > >' to 'initializer_list<value_type>' for 1st argument
      map(initializer_list<value_type> __l,
      ^
:13:18: note: passing argument to parameter 'm' here
void dumpMap(Map m)
                 ^
ERROR: Failed to create CallExpr
 in CallDNE at /home/mturok/.julia/v0.4/Cxx/src/Cxx.jl:1242



julia> icxx"""dumpMap($m)"""
:2:1: error: no matching function for call to 'dumpMap'
dumpMap(__juliavar1)
^~~~~~~
:13:6: note: candidate function not viable: no known conversion from 'map<std::basic_string<char>, std::basic_string<char>, std::less<std::basic_string<char> >, allocator<pair<basic_string<char, std::char_traits<char>, std::allocator<char>>, std::basic_string<char>>>>' to 'map<std::string, std::string, std::less<std::basic_string<char> >, allocator<pair<const basic_string<char, std::char_traits<char>, std::allocator<char>>, std::basic_string<char>>>>' for 1st argument
void dumpMap(Map m)
     ^

Thanks in advance,
Michael Turok

Set functions on CppValue or CppPtr structures

I am implementing setfunctions, specifically for C++ STL containers (vector, map) that have been initialized as CppValues in Julia - and somehow the values are not changed (and I get no error).
I wonder whether there is something trivial I am missing regarding how the setfunction should be implemented in the context of Cxx (as the same functions work fine in straight C++).

The setfunctions (e.g., setHeight) for simple variables work perfectly fine, e.g.,

cxx"""
  class Box
       {
       . . .  
       }
      . . .  
       void Box::setHeight( double hei )
       {
           height = hei;
       }
"""
box = @cxxnew Box()
function boxVolume(box, length, height, breadth)
    @cxx box->setLength(length)
    @cxx box->setHeight(height)
    @cxx box->setBreadth(breadth)
    volume = @cxx box->getVolume()
end
julia> boxVolume(box, 10, 20, 30)
6000.0

However, this does not work with std::vector or std::map. I could get all methods working with std::vector (e.g., size, create, at) the only one that did not appear to work is setting the value of an element by indexing (I used set functions with template type or a declared long type).

I first initialized the std::vector and checked that everything looks ok:

julia> vec = stdvector(10,10)
CppValue{symbol("std::__1::vector"),(Int64,CppValue{symbol("std::__1::allocator"),(Int64,)})}(UInt8[0x40,0x07,0x8d,0xb3,0xf9,0x7f,0x00,0x00,0x90,0x07    0x00,0x00,0x90,0x07,0x8d,0xb3,0xf9,0x7f,0x00,0x00])
julia> stdsize(vec)
10
julia> stdpush_back(vec, 33)
julia> at(vec, 10)
33
julia> stdpop_back(vec)
julia> stdsize(vec)
9

Here I tried setting the first element to 44, but nothing happened (no change)

julia> @cxx set(vec,1,44)
julia> at(vec, 1)
10

Is there something I am missing regarding how to set values in the declarations below?

cxx"""
template <typename T_>
void set(std::vector<T_> cppvec, int index, T_ val) 
              {
                 cppvec[index] = val;
              }

void set2(std::vector<long> cppvec, int index, long val) 
              {
                 cppvec[index] = val;
              }
"""

Syntactic sugar for common Cxx Types

I was wondering how much this package should support making it easy to use C++ types in Julia. For example I am currently wrapping Clipper and there is a case where it is handy to take the bitwise 'and' and 'or' of enums. A simple step in this direction is adding the following to Cxx:

Base.|{T}(v1::CppEnum{T}, v2::CppEnum{T}) = CppEnum{T}(v1.val|v2.val)
Base.&{T}(v1::CppEnum{T}, v2::CppEnum{T}) = CppEnum{T}(v1.val&v2.val)

I am afraid this could be an endless rabbit hole of encapsulation. For example, std::vector would more difficult to do. What is the philosophy on this approach?

error with namespace + inner enum

cxx"""
namespace foo{
 class bar{
  public:
  enum baz{
   A,B,C
  };
 };
}
"""
println(@cxx foo::bar::A)

gives:

nns = (:foo,:bar,:A)
n = :foo
cur = CppPtr{symbol("clang::Decl"),()}(Ptr{Void} @0x0000000005308f40)
isaNamespaceDecl(cur) = false
n = :bar
cur = CppPtr{symbol("clang::Decl"),()}(Ptr{Void} @0x0000000005492180)
isaNamespaceDecl(cur) = true
julia: /mnt/hdd/mlubin/julia-0.4/deps/llvm-svn/tools/clang/lib/AST/NestedNameSpecifier.cpp:66: static clang::NestedNameSpecifier* clang::NestedNameSpecifier::Create(const clang::ASTContext&, clang::NestedNameSpecifier*, const clang::NamespaceDecl*): Assertion `(!Prefix || (Prefix->getAsType() == nullptr && Prefix->getAsIdentifier() == nullptr)) && "Broken nested name specifier"' failed.

error calling methods

cxx"""
 class bar {
   public:
   double xxx() {
      return 5.0;
   }
 };
"""

b = @cxxnew bar()
println(b)
println(@cxx b->xxx())

gives

nns = (:bar,)
n = :bar
CppPtr{:bar,()}(Ptr{Void} @0x0000000004061db0)
Function return type does not match operand type of return inst!
  ret double %call
 i8*
define i8* @0(%CppPtr.20) {
top:
  %dummy.addr = alloca %class.bar*, align 8
  %1 = extractvalue %CppPtr.20 %0, 0
  %dummy = bitcast i8* %1 to %class.bar*
  store %class.bar* %dummy, %class.bar** %dummy.addr, align 8
  %2 = load %class.bar** %dummy.addr, align 8
  %call = call double @_ZN3bar3xxxEv(%class.bar* %2)
  ret double %call
}

ERROR: error compiling anonymous: Malformed LLVM Function

Can't build on OSX

I tried to build following your mailing list instructions. However I get the following error during compilation of Julia itself:

In file included from /Users/john/Documents/code/downloaded/julia/deps/llvm-svn/tools/lldb/source/../include/lldb/Core/FormatNavigator.h:29:
/Users/john/Documents/code/downloaded/julia/deps/llvm-svn/tools/lldb/source/../include/lldb/Symbol/ClangASTContext.h:21:10: fatal error: 
      'llvm/ADT/OwningPtr.h' file not found
#include "llvm/ADT/OwningPtr.h"
         ^
1 error generated.

My Make.user:

USE_SYSTEM_LIBM=1
BUILD_LLVM_CLANG=1
BUILD_LLDB=1

My deps/Versions.make

USE_SYSTEM_LIBM=1
BUILD_LLVM_CLANG=1
BUILD_LLDB=1
...

I also merged the branches and applied the patch as stated on the mailing list.

In issue #3 a similar problem arose on Ubuntu, but I'm on OSX. Any ideas how I can solve this? How do I try "the master branch of lldb instead of release_33"

Apologies for the stupid questions.
I'm unreasonably excited about CXX.jl!
Thanks!

CxxREPL not working?

Hi folks,

Not sure if the replpane is ready for prime-time yet, but I'm seeing the following errors when trying it. Once again, thanks in advance.

First up, I'm running julia within emacs, and then with an xterm. (Note that since I did a fresh build of julia, I now see the warning message "WARNING: Terminal not fully functional" - and I'm not yet sure about the ::gets error message).

I include versioninfo(true) at the end, as well as the git log -1 for Cxx itself.

First from emacs:

               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "help()" for help.
  | | | | | | |/ _' |  |
  | | |_| | | | (_| |  |  Version 0.4.0-dev+2514 (2015-01-05 22:41 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 51976a3 (1 day old master)
|__/                   |  x86_64-linux-gnu

WARNING: Terminal not fully functional
julia> 
julia> using Cxx
Warning: requiring "Cxx" did not define a corresponding module.

julia> include(joinpath(Pkg.dir("Cxx"), "src/CxxREPL/replpane.jl"))
In file included from :1:
In file included from __cxxjl_0.cpp:6:
In file included from /home/mturok/src/julia/usr/bin/../../usr/include/clang/Parse/Parser.h:17:
In file included from /home/mturok/src/julia/usr/bin/../../usr/include/clang/Basic/OpenMPKinds.h:18:
In file included from /home/mturok/src/julia/usr/bin/../../usr/include/llvm/ADT/StringRef.h:13:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/algorithm:62:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/stl_algo.h:65:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/random:39:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/cstdio:120:11: error: no member named 'gets' in the global namespace
  using ::gets;
        ~~^
ERROR: type BasicREPL has no field interface
 in include at ./boot.jl:248
 in include_from_node1 at ./loading.jl:128
 in print at ./string.jl
while loading /home/mturok/.julia/v0.4/Cxx/src/CxxREPL/replpane.jl, in expression starting on line 144

And from an xterm:

mturok@mturok-xubuntu:~$ src/julia/usr/bin/julia
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "help()" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.4.0-dev+2514 (2015-01-05 22:41 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 51976a3 (1 day old master)
|__/                   |  x86_64-linux-gnu

julia> using Cxx
Warning: requiring "Cxx" did not define a corresponding module.

julia> include(joinpath(Pkg.dir("Cxx"), "src/CxxREPL/replpane.jl"))
In file included from :1:
In file included from __cxxjl_0.cpp:6:
In file included from /home/mturok/src/julia/usr/bin/../../usr/include/clang/Parse/Parser.h:17:
In file included from /home/mturok/src/julia/usr/bin/../../usr/include/clang/Basic/OpenMPKinds.h:18:
In file included from /home/mturok/src/julia/usr/bin/../../usr/include/llvm/ADT/StringRef.h:13:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/algorithm:62:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/stl_algo.h:65:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/random:39:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/cstdio:120:11: error: no member named 'gets' in the global namespace
  using ::gets;
        ~~^

WARNING: deprecated syntax "{a=>b, ...}" at /home/mturok/.julia/v0.4/Cxx/src/CxxREPL/replpane.jl:163.
Use "Dict{Any,Any}(a=>b, ...)" instead.
Dict{Char,Any} with 36 entries:
  '\x1e' => nothing
  '\x12' => (anonymous function)
  '\x02' => (anonymous function)
  '\x10' => (anonymous function)
  '\v'   => (anonymous function)
  '\x15' => (anonymous function)
  '\x1a' => (anonymous function)
  '\a'   => nothing
  '\x19' => (anonymous function)
  '\t'   => (anonymous function)
  '\n'   => Base.LineEdit.KeyAlias("\r")
  '\x1d' => nothing
  '\0'   => (anonymous function)
  '<'    => (anonymous function)
  '\x13' => (anonymous function)
  '\x11' => nothing
  ';'    => (anonymous function)
  '\b'   => (anonymous function)
  '\x16' => nothing
  ⋮      => ⋮

julia>

And the version information:

julia> versioninfo(true)
Julia Version 0.4.0-dev+2514
Commit 51976a3 (2015-01-05 22:41 UTC)
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
  WORD_SIZE: 64
           Ubuntu 14.04.1 LTS
  uname: Linux 3.13.0-43-generic #72-Ubuntu SMP Mon Dec 8 19:35:06 UTC 2014 x86_64 x86_64
Memory: 7.798191070556641 GB (386.73828125 MB free)
Uptime: 87251.0 sec
Load Avg:  0.13427734375  0.0859375  0.056640625
Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz: 
       speed         user         nice          sys         idle          irq
#1  3258 MHz     546846 s        648 s     194286 s    7818837 s         14 s
#2  3258 MHz     474251 s        828 s     183338 s    7897539 s          0 s

  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Nehalem)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-svn
Environment:
  TERM = dumb
  GLADE_CATALOG_PATH = :
  XDG_SESSION_PATH = /org/freedesktop/DisplayManager/Session0
  GLADE_PIXMAP_PATH = :
  PATH = /home/mturok/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
  DEFAULTS_PATH = /usr/share/gconf/xubuntu.default.path
  MANDATORY_PATH = /usr/share/gconf/xubuntu.mandatory.path
  GLADE_MODULE_PATH = :
  XDG_SEAT_PATH = /org/freedesktop/DisplayManager/Seat0
  HOME = /home/mturok

Package Directory: /home/mturok/.julia/v0.4
15 required packages:
 - BinDeps                       0.3.7
 - Bokeh                         0.0.1
 - DataFrames                    0.6.0
 - Debug                         0.0.4
 - Distributions                 0.6.3
 - GLM                           0.4.2
 - GraphViz                      0.0.3
 - IJulia                        0.1.16
 - JSON                          0.4.0
 - LibBSON                       0.1.2
 - Memoize                       0.0.0
 - Mongo                         0.1.0
 - ODBC                          0.3.10
 - Pandas                        0.2.0
 - PyPlot                        1.5.0
22 additional packages:
 - ArrayViews                    0.4.8
 - Color                         0.3.15
 - Compat                        0.2.8
 - Cxx                           0.0.0-             master (unregistered)
 - DataArrays                    0.2.7              e5391941 (dirty)
 - Dates                         0.4.4
 - FixedPointNumbers             0.0.6
 - GZip                          0.2.13
 - LaTeXStrings                  0.1.2
 - Mustache                      0.0.6
 - Nettle                        0.1.7
 - NumericExtensions             0.6.2
 - NumericFuns                   0.2.3
 - PDMats                        0.3.1
 - PyCall                        0.7.3
 - REPLCompletions               0.0.3
 - Reexport                      0.0.2
 - SHA                           0.0.3
 - SortingAlgorithms             0.0.2
 - StatsBase                     0.6.10
 - URIParser                     0.0.3
 - ZMQ                           0.1.15

julia> 

And here is the specific revision of Cxx I'm using....

mturok@mturok-xubuntu:~/.julia/v0.4/Cxx$ git log -1
commit 6838b0c918d30b5345e092b8ac66f694055a7e5e
Author: Keno Fischer <[email protected]>
Date:   Sun Jan 4 15:51:01 2015 +0100

    Cxx.jl is dead - long live Cxx.jl

    Remove the code from the first iteration of this package.
    It is long outdated, doesn't work anymore and never had as
    many features as the current version.

Build failure on Ubuntu

I have tried to follow the instructions you gave at the dev-list on julia.mit.edu and I use g++ in version 4.8. My versioninfo is

julia> versioninfo()
Julia Version 0.3.0-rc1+120
Commit 6b2a7d7* (2014-07-21 18:04 UTC)
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E7- 8850  @ 2.00GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Nehalem)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

When running Pkg.build("CXX"), the last part before the error is

../src/bootstrap.cpp: In function ‘void* DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::Type**, uint32_t, clang::Expr**, uint32_t)’:
../src/bootstrap.cpp:902:43: error: variable ‘clang::sema::TemplateDeductionInfo tdi’ has initializer but incomplete type
     clang::sema::TemplateDeductionInfo tdi((clang::SourceLocation()));
                                           ^
../src/bootstrap.cpp: In function ‘void* getCalleeReturnType(clang::CallExpr*)’:
../src/bootstrap.cpp:1024:21: error: ‘class clang::FunctionDecl’ has no member named ‘getReturnType’
   return (void*)fd->getReturnType().getTypePtr();
                     ^
make: *** [build/bootstrap.o] Error 1
=====================================================[ ERROR: CXX ]=====================================================

failed process: Process(`make -f BuildBootstrap.Makefile JULIA_HOME=/home/andreasnoackjensen/juliallvmdev/usr/bin`, ProcessExited(2)) [2]
while loading /home/andreasnoackjensen/.julia/v0.3/CXX/deps/build.jl, in expression starting on line 16

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

If you need more output I can make a gist.

replpane terminates while trying to access elements in std::vector

replpane is a fantastic addition to this package. While testing whether replpane would be useful to quickly debug C++ scripts before wrapping them in Julia, I encountered the following:

julia> include(joinpath(Pkg.dir("Cxx"), "src/CxxREPL/replpane.jl"))
# press "<" 
C++ > std::vector<int>vec2(20);
C++ > vec2.push_back(10);
C++ > vec2.push_back(100);
C++ > std::cout << vec2.at(0) << std::endl;

libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: vector
signal (6): Abort trap: 6
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Abort trap: 6
logout

This seems to happen no matter how I use at to access or change values to the std::vector container.

Catching C++ exceptions

I appreciate that this library is a work in progress (and is amazing already)! But is there currently any way to catch C++ exceptions and transfer them to julia? Currently julia simply segfaults.

I can imagine writing a macro that takes a C++ exception type and writes the required code to catch this exception and transfer it to julia; I might write such a thing; but I am wondering if this has already been thought about?

Passing Julia datatypes to C++

We have done the following using Cxx

using Cxx

cxx"""class Bill {
         public:
            int64_t a;
            int64_t b;
       };"""

 type Bill
          a::Int
          b::Int
       end

s = Bill(1, 2)

cxx"""#include <stdio.h>"""

cxx"""void myfn(Bill * m) { printf("%ld, %ld", m->a, m->b);}"""

Now we are looking for a way to pass s into the function myfn. Can you give an example of how to do this using Cxx?

latest build issue..

julia> Pkg.build("Cxx")
INFO: Building Cxx
Tuning for julia installation at: /Users/rhl/code/julia/usr/bin
LINK /Users/rhl/.julia/v0.4/Cxx/deps/usr/lib/libcxxffi.dylib
Undefined symbols for architecture x86_64:
"clang::tooling::Replacement::Replacement(clang::SourceManager const&, clang::CharSourceRange const&, llvm::StringRef)", referenced from:
clang::tooling::ReplaceStmtWithText::run(clang::ast_matchers::MatchFinder::MatchResult const&) in libclangTooling.a(RefactoringCallbacks.o)
clang::tooling::ReplaceStmtWithStmt::run(clang::ast_matchers::MatchFinder::MatchResult const&) in libclangTooling.a(RefactoringCallbacks.o)
clang::tooling::ReplaceIfStmtWithItsBody::run(clang::ast_matchers::MatchFinder::MatchResult const&) in libclangTooling.a(RefactoringCallbacks.o)
"clang::tooling::applyAllReplacements(std::__1::set<clang::tooling::Replacement, std::__1::lessclang::tooling::Replacement, std::_1::allocatorclang::tooling::Replacement > const&, clang::Rewriter&)", referenced from:
clang::tooling::RefactoringTool::runAndSave(clang::tooling::FrontendActionFactory
) in libclangTooling.a(Refactoring.o)
clang::tooling::RefactoringTool::applyAllReplacements(clang::Rewriter&) in libclangTooling.a(Refactoring.o)
"clang::tooling::operator<(clang::tooling::Replacement const&, clang::tooling::Replacement const&)", referenced from:
std::__1::__tree<clang::tooling::Replacement, std::__1::lessclang::tooling::Replacement, std::__1::allocatorclang::tooling::Replacement >::__node_insert_unique(std::__1::_tree_node<clang::tooling::Replacement, void>) in libclangTooling.a(RefactoringCallbacks.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *
* [usr/lib/libcxxffi.dylib] Error 1
=================================[ ERROR: Cxx ]=================================

failed process: Process(make -f BuildBootstrap.Makefile JULIA_HOME=/Users/rhl/code/julia/usr/bin, ProcessExited(2)) [2]
while loading /Users/rhl/.julia/v0.4/Cxx/deps/build.jl, in expression starting on line 16

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

WARNING: Cxx had build errors.

  • packages with build errors remain installed in /Users/rhl/.julia/v0.4
  • build a package and all its dependencies with Pkg.build(pkg)
  • build a single package by running its deps/build.jl script

Warning: requiring "Cxx" did not define a corresponding module

Hi,
Successfully built Cxx gives me the following warning on load:
julia> dlopen("/home/kuba/.julia/v0.4/Cxx/deps/usr/lib/libcxxffi.so")
Ptr{Void} @0x000000000277f560

julia> using Cxx
Warning: requiring "Cxx" did not define a corresponding module.

julia> cxx"""
#include
"""
In file included from :1:
In file included from :2:
In file included from /usr/include/c++/4.8/iostream:39:
In file included from /usr/include/c++/4.8/ostream:38:
In file included from /usr/include/c++/4.8/ios:42:
In file included from /usr/include/c++/4.8/bits/ios_base.h:41:
In file included from /usr/include/c++/4.8/bits/locale_classes.h:40:
In file included from /usr/include/c++/4.8/string:52:
In file included from /usr/include/c++/4.8/bits/basic_string.h:2815:
In file included from /usr/include/c++/4.8/ext/string_conversions.h:43:
/usr/include/c++/4.8/cstdio:120:11: error: no member named 'gets' in the global namespace
using ::gets;
~~^

Cannot make modules using Cxx

I am not sure if there is an implementation reason for this or not since I notice Cxx does not define a module. Taking an example in the README:

julia> module CxxModule
       using Cxx 
       cxx""" #include<iostream> """
       cxx"""  
                       void mycppfunction() {   
                          int z = 0;
                          int y = 5;
                          int x = 10;
                          z = x*y + 2;
                          std::cout << "The number is " << z << std::endl;
                       }
                    """
       julia_function() = @cxx mycppfunction()
       end
Warning: requiring "Cxx" did not define a corresponding module.
ERROR: UndefVarError: @cxx_mstr not defined
 in show at ./show.jl

version of LLVM - Clang

Hello,
I have maybe an obvious question. What version of LLVM and Clang should I build prior building Julia?
In one of the previous post I have seen LLVM_VER=svn. Is it the latest release_35 in git?
Has anyone tried building Julia with Cxx support on Linux?

Cheers,
kuba

Cxx README example 4 fails with fatal ERROR

Again, on OSX 10.9.5., new build of Julia from master, libcxxffi.dylib built fine, everything appears to work with Cxx except for @cxxnew declarations (previous issue filed) and now passing julia variables/functions, e.g., example 4 of README:

julia> cxx"""
                 void testJuliaPrint() {
                     $:(println("\nTo end this test, press any key")::Nothing);
                 }
              """

julia> @cxx testJuliaPrint()
Assertion failed: (!isa<MDNodeFwdDecl>(Op) && "Expected all forward declarations to be resolved"), function resolveCycles, file /Users/maximilianosuster/julia-v0.4.0/deps/llvm-svn/lib/IR/Metadata.cpp, line 459.

signal (6): Abort trap: 6
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Abort trap: 6
logout

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.