Trouble creating a module from CxxWrap'ped code

I am totally baffled by this.

I have been wrapping a c++ simulations package using cxxwrap learning plenty of c++, and generally getting everything to work.

I prepared tests in the canonical way, and saw that I could run each test_*.jl file as a script, successfully.

I ran into a serious problem when I was trying to package everything. I generated a Project.toml, added dependencies in the ] repl, and then when I tried to use the package in this fashion, it was broken. Enums I had previously wrapped were coming back as Tuple{Core.Compiler.UseRef,Nothing}. That is to say, when I was using the code NOT as a standalone package, but by using dev ., everything worked. When I tried to make it a real package, write a proper Project.toml, and import the code using activate ., Enums are no longer represented as anything recognizable.

Any help would be greatly appreciated!

Not sure if this is related, but there is a new branch in cxxwrap to address issues with enums. Can you try the type_overhaul branch?

Maybe your dev environment uses a different version of Cxxwrap than the package you’re creating? Just speculating here…

i cloned it and tried to incorporate it with dev . and i get the following error:
/CxxWrap.jl/deps/deps.jl not found, CxxWrap did not build properly

Do you need do dev it?
If you do

add CxxWrap#type_overhaul
build CxxWrap
test CxxWrap

Does it work then?

i did not know this was possible - thank you! however i tried it and was confronted with the following:


Building CxxWrap → `~/.julia/packages/CxxWrap/m6fg0/deps/build.log`
┌ Error: Error building `CxxWrap`:
│ [ Info: Downloading [https://github.com/JuliaInterop/libcxxwrap-julia/releases/download/v0.5.3/libcxxwrap-julia-1.0.v0.5.3.x86_64-linux-gnu-gcc7-cxx11.tar.gz](https://github.com/JuliaInterop/libcxxwrap-julia/releases/download/v0.5.3/libcxxwrap-julia-1.0.v0.5.3.x86_64-linux-gnu-gcc7-cxx11.tar.gz) to /home/alexander/.julia/packages/CxxWrap/m6fg0/deps/usr/downloads/libcxxwrap-julia-1.0.v0.5.3.x86_64-linux-gnu-gcc7-cxx11.tar.gz...
│ ERROR: LoadError: LibraryProduct(nothing, ["libcxxwrap_julia_stl"], :libcxxwrap_julia_stl, "Prefix(/home/alexander/.julia/packages/CxxWrap/m6fg0/deps/usr)") is not satisfied, cannot generate deps.jl!
│ Stacktrace:
│  [1] error(::String) at ./error.jl:33
│  [2] #write_deps_file#152(::Bool, ::Function, ::String, ::Array{Product,1}) at /home/alexander/.julia/packages/BinaryProvider/TcAwt/src/Products.jl:414
│  [3] write_deps_file(::String, ::Array{Product,1}) at /home/alexander/.julia/packages/BinaryProvider/TcAwt/src/Products.jl:395
│  [4] top-level scope at none:0
│  [5] include at ./boot.jl:326 [inlined]
│  [6] include_relative(::Module, ::String) at ./loading.jl:1038
│  [7] include(::Module, ::String) at ./sysimg.jl:29
│  [8] include(::String) at ./client.jl:403
│  [9] top-level scope at none:0
│ in expression starting at /home/alexander/.julia/packages/CxxWrap/m6fg0/deps/build.jl:55
[07:34:49] ######################################################################## 100.0%

Ah. Right. Not sure if that’s what you’re seeing, but CxxWrap needs another library to build, and that’s also on a type_overhaul branch…
Sorry for the incomplete instructions, I know how annoying that is.
Can you build the libcxxwrap library and then follow this post? https://github.com/JuliaInterop/CxxWrap.jl/issues/146#issuecomment-519438616

You’ll need to clone the repo, add a parent folder JuliaInterop and then call the libraries build.jl from the parent folder of that.
Hope that makes sense…

I have a few questions it turns out.

  1. I clone libcxxwrap-julia, checkout type_overhaul locally, mkdir build, cd build, cmake ../, make, seemingly successfully. I see a number of the shared objects i expect i need.

  2. I clone CxxWrap and checkout type_overhaul.

  3. I’m not sure how to package the resulting libcxxwrap-julia into a tarball, or how to change build.jl accordingly.

  4. I tried to circumvent this by running build . in CxxWrap in the standard way, and then replacing the shared objects in deps/usr/lib with those created by makeing libcxxwrap-julia. doing that however yields the following error in testing:

signal (11): Segmentation fault
in expression starting at /home/alexander/CxxWrap.jl/src/StdLib.jl:15
unknown function (ip: 0xffffffffffffffff)
Allocations: 5700824 (Pool: 5699645; Big: 1179); GC: 12
ERROR: LoadError: LoadError: Failed to precompile CxxWrap [1f15a43c-97ca-5a2a-ae31-89f07a497df4] to /home/alexander/.julia/compiled/v1.1/CxxWrap/WGIJU.ji.
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] compilecache(::Base.PkgId, ::String) at ./loading.jl:1197
[3] _require(::Base.PkgId) at ./loading.jl:960
[4] require(::Base.PkgId) at ./loading.jl:858
[5] require(::Module, ::Symbol) at ./loading.jl:853
[6] include at ./boot.jl:326 [inlined]
[7] include_relative(::Module, ::String) at ./loading.jl:1038
[8] include(::Module, ::String) at ./sysimg.jl:29
[9] include(::String) at ./client.jl:403
[10] top-level scope at none:0
[11] include at ./boot.jl:326 [inlined]
[12] include_relative(::Module, ::String) at ./loading.jl:1038
[13] include(::Module, ::String) at ./sysimg.jl:29
[14] include(::String) at ./client.jl:403
[15] top-level scope at none:0

Try the following:

  1. mkdir JuliaInterop
    cd JuliaInterop
    git clone https://github.com/JuliaInterop/libcxxwrap-julia.git
    cd libcxxwrap-julia
    git checkout type_overhaul
    cd ../..
    julia JuliaInterop/libcxxwrap-julia/.ci/build_tarballs.jl
    
    This builds the tarballs in the directory products.
  2. Either checkout the type_overhaul branch of CxxWrap in the julia package manager and set the envvar as explained in the CxxWrap issue, or do what you did and dev the CxxWrap package, checkout the type_overhaul branch, and edit the deps/build.jl file to point to your local file for the libcxxwrap tar ball that you just built, instead of the one on the web. Just use the absolute path. You’ll need to specify the checksum, which you can get with sha256sum <filename>.
  3. After modifying the build file (or specifying the envvar) you should be able to just ] build CxxWrap.

I get stopped by this:


if VERSION >= v"1.1"
    exit()
end

i will comment that out and see how it goes…

Yes, I saw that, too. @barche, is that really intended? What’s the reason for putting that there? Seems to work fine without this.

i don’t mean to keep posting stack traces, but…


[ Info: Building for x86_64-linux-gnu-gcc7-cxx11, x86_64-linux-gnu-gcc8-cxx11, x86_64-w64-mingw32-gcc7-cxx11, x86_64-w64-mingw32-gcc8-cxx11, i686-w64-mingw32-gcc7-cxx11, i686-w64-mingw32-gcc8-cxx11, x86_64-apple-darwin14
At line 288, ABORTED (Operation not permitted)!
At line 1171, ABORTED (Success)!
ERROR: LoadError: Build for libcxxwrap-julia-1.0 on x86_64-linux-gnu-gcc7-cxx11 did not complete successfully

Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] #build#184(::Bool, ::Bool, ::Bool, ::Bool, ::Bool, ::Array{String,1}, ::Bool, ::Function, ::BinaryBuilder.UserNSRunner, ::String, ::Array{LibraryProduct,1}, ::String, ::Linux, ::Prefix) at /home/alexander/.julia/packages/BinaryBuilder/vkHhH/src/AutoBuild.jl:565
 [3] (::getfield(BinaryBuilder, Symbol("#kw##build")))(::NamedTuple{(:verbose, :ignore_manifests, :debug),Tuple{Bool,Array{String,1},Bool}}, ::typeof(build), ::BinaryBuilder.UserNSRunner, ::String, ::Array{LibraryProduct,1}, ::String, ::Linux, ::Prefix) at ./none:0
 [4] (::getfield(BinaryBuilder, Symbol("##173#179")){Bool,Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol},NamedTuple{(:debug,),Tuple{Bool}}},String,String,VersionNumber,String,Array{Platform,1},getfield(Main, Symbol("##3#4")),Array{String,1}})(::String) at /home/alexander/.julia/packages/BinaryBuilder/vkHhH/src/AutoBuild.jl:391
 [5] mktempdir(::getfield(BinaryBuilder, Symbol("##173#179")){Bool,Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol},NamedTuple{(:debug,),Tuple{Bool}}},String,String,VersionNumber,String,Array{Platform,1},getfield(Main, Symbol("##3#4")),Array{String,1}}, ::String) at ./file.jl:581
 [6] mktempdir at ./file.jl:579 [inlined]
 [7] #autobuild#171(::Bool, ::Base.Iterators.Pairs{Symbol,Bool,Tuple{Symbol},NamedTuple{(:debug,),Tuple{Bool}}}, ::Function, ::String, ::String, ::VersionNumber, ::Array{String,1}, ::String, ::Array{Platform,1}, ::getfield(Main, Symbol("##3#4")), ::Array{String,1}) at /home/alexander/.julia/packages/BinaryBuilder/vkHhH/src/AutoBuild.jl:279
 [8] (::getfield(BinaryBuilder, Symbol("#kw##autobuild")))(::NamedTuple{(:verbose, :debug),Tuple{Bool,Bool}}, ::typeof(autobuild), ::String, ::String, ::VersionNumber, ::Array{String,1}, ::String, ::Array{Platform,1}, ::getfield(Main, Symbol("##3#4")), ::Array{String,1}) at ./none:0
 [9] #build_tarballs#160(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Array{String,1}, ::String, ::VersionNumber, ::Array{String,1}, ::String, ::Array{Platform,1}, ::getfield(Main, Symbol("##3#4")), ::Array{String,1}) at /home/alexander/.julia/packages/BinaryBuilder/vkHhH/src/AutoBuild.jl:117
 [10] build_tarballs(::Array{String,1}, ::String, ::VersionNumber, ::Array{String,1}, ::String, ::Array{Platform,1}, ::Function, ::Array{String,1}) at /home/alexander/.julia/packages/BinaryBuilder/vkHhH/src/AutoBuild.jl:21
 [11] top-level scope at none:0
 [12] include at ./boot.jl:326 [inlined]
 [13] include_relative(::Module, ::String) at ./loading.jl:1038
 [14] include(::Module, ::String) at ./sysimg.jl:29
 [15] exec_options(::Base.JLOptions) at ./client.jl:267
 [16] _start() at ./client.jl:436
in expression starting at /home/alexander/JuliaInterop/libcxxwrap-julia/.ci/build_tarballs.jl:65

Hmm. That’s not something I’ve seen before.
Looks like BinaryBuilder doesn’t work on your system, but I’m speculating.

cc’ing @barche for insight.
Which architecture do you need? Maybe start by commenting out all of the ones you don’t need…

Another idea would be to fork the repo and use travis to build your tarballs…

It is because Julia itself is a binary dependency for libcxxwrap-julia. To get Julia in a BinaryBuilder-compatible way, it is downloaded from https://github.com/JuliaPackaging/JuliaBuilder/releases, but this only has the 1.0 version. So to run the build_tarballs.jl script locally you must indeed remove this version check.

edit: I just realized this made the tests for julia > 1.0 fail, so it is removed from the source. But regardless of the Julia used to execute the build_tarballs.jl, it will always build against Julia 1.0.

Yes, the last trace looks like a permission problem starting the container, normally it should ask for a sudo password. CC’ing @staticfloat for this.

Regarding a custom build of CxxWrap: it is easier to just build it directly using standard CMake commands, and then set ENV["JLCXX_DIR"] to the CMake build directory before doing Pkg.build("CxxWrap"). I recommend using the type_overhaul branch for new work, this should be close to release now (just a few more failing tests on Travis and a fix for Julia 1.3 to go).

Yep, looks like BinaryBuilder is freaking out. Your error points to line 288 within the User Namespace sandbox, so my best guess is that you’re on a system that doesn’t have the User Namespace patches to the kernel (Arch Linux is one example that does not have this). This is strange however, as BB should be auto-detecting that this fails and attempting to use sudo to get around it, as Barche mentioned. The only case in which this wouldn’t happen would be if you were to run it with the environment variable BINARYBUILDER_RUNNER=unprivileged, but I’m assuming you don’t have that defined.

Could you print out the value of BinaryBuilder.versioninfo()?

Ok, so another day another traceback

what i did:

  1. cd ~/JuliaInterop/libcxxwrap-julia/

  2. git checkout type_overhaul

  3. mkdir build

  4. cd build

  5. cmake ../

  6. make

  7. cd ~/CxxWrap.jl/

  8. git checkout type_overhaul

  9. julia

  10. ENV["JLCXX_DIR"]="/home/alexander/JuliaInterop/libcxxwrap-julia/build"

  11. ]

  12. activate .

  13. build

then from the package i want to use this in:

  1. ]

  2. activate .

  3. dev ~/CxxWrap.jl/

  4. test

julia: /home/alexander/JuliaInterop/libcxxwrap-julia/src/jlcxx.cpp:46: jlcxx::cxxint_t jlcxx::Module::store_pointer(void*): Assertion `ptr != nullptr' failed.

signal (6): Aborted
in expression starting at /home/alexander/pairinteraction_fork/pairinteraction/PairInteraction.jl/src/PairInteraction.jl:10
__libc_signal_restore_set at /build/glibc-OTsEL5/glibc-2.27/signal/../sysdeps/unix/sysv/linux/nptl-signals.h:80 [inlined]
raise at /build/glibc-OTsEL5/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:48
abort at /build/glibc-OTsEL5/glibc-2.27/stdlib/abort.c:79
__assert_fail_base at /build/glibc-OTsEL5/glibc-2.27/assert/assert.c:92
__assert_fail at /build/glibc-OTsEL5/glibc-2.27/assert/assert.c:101
_ZN5jlcxx6Module13store_pointerEPv at /home/alexander/CxxWrap.jl/deps/../../JuliaInterop/libcxxwrap-julia/build/lib/libcxxwrap_julia.so (unknown line)
_ZN5jlcxx19FunctionWrapperBase19set_pointer_indicesEv at /home/alexander/CxxWrap.jl/deps/../../JuliaInterop/libcxxwrap-julia/build/lib/libcxxwrap_julia.so (unknown line)
_ZN5jlcxx6Module17add_type_internalI18MatrixElementCacheNS_13ParameterListIJEEE14_jl_datatype_tEENS_11TypeWrapperIT_EERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPT1_ at /home/alexander/pairinteraction_fork/pairinteraction/build/pairinteraction/libpireal.so (unknown line)
define_julia_module at /home/alexander/pairinteraction_fork/pairinteraction/build/pairinteraction/libpireal.so (unknown line)
register_julia_module at /home/alexander/CxxWrap.jl/deps/../../JuliaInterop/libcxxwrap-julia/build/lib/libcxxwrap_julia.so (unknown line)
register_julia_module at /home/alexander/CxxWrap.jl/src/CxxWrap.jl:278 [inlined]
readmodule at /home/alexander/CxxWrap.jl/src/CxxWrap.jl:564
wrapmodule at /home/alexander/CxxWrap.jl/src/CxxWrap.jl:570
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1864
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:323
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:411
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:362 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:773
jl_interpret_toplevel_thunk_callback at /buildworker/worker/package_linux64/build/src/interpreter.c:885
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7fa423fc271f)
unknown function (ip: (nil))
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:894
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:764
jl_eval_module_expr at /buildworker/worker/package_linux64/build/src/toplevel.c:179
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:614
jl_parse_eval_all at /buildworker/worker/package_linux64/build/src/ast.c:883
jl_load at /buildworker/worker/package_linux64/build/src/toplevel.c:826
include at ./boot.jl:326 [inlined]
include_relative at ./loading.jl:1038
include at ./sysimg.jl:29
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:323
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:411
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:362 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:773
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:689
jl_interpret_toplevel_thunk_callback at /buildworker/worker/package_linux64/build/src/interpreter.c:885
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7fa441c460df)
unknown function (ip: 0x2)
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:894
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:764
jl_toplevel_eval_in at /buildworker/worker/package_linux64/build/src/toplevel.c:793
eval at ./boot.jl:328 [inlined]
eval at ./client.jl:404
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
top-level scope at ./none:3
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1864
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:758
jl_toplevel_eval_in at /buildworker/worker/package_linux64/build/src/toplevel.c:793
eval at ./boot.jl:328
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
exec_options at ./client.jl:243
_start at ./client.jl:436
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
jl_apply at /buildworker/worker/package_linux64/build/ui/../src/julia.h:1571 [inlined]
true_main at /buildworker/worker/package_linux64/build/ui/repl.c:96
main at /buildworker/worker/package_linux64/build/ui/repl.c:217
__libc_start_main at /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
_start at /opt/julia-1.1.0/bin/julia (unknown line)
Allocations: 2829107 (Pool: 2828595; Big: 512); GC: 4

Hi,

All of these steps look correct to me, is the C++ code for your libpireal.so available somewhere?

though i suspect the problem is in cxxwrap on its own, i would appreciate any help!

https://github.com/pairinteraction/pairinteraction/pull/100

I started looking at this, but it would pay off I think to lookl at current CxxWrap master with libxxwrap-julia 0.6.2, since this contains support for std::vector, so you should now be able to simplify many methods to e.g.:

.method("precalculateElectricMomentum", &MatrixElementCache::precalculateElectricMomentum)
1 Like

thank you for informing me! that is very helpful indeed!