JuliaInterop / CxxWrap.jl

Package to make C++ libraries available in Julia
Other
418 stars 67 forks source link

`StdFill` not defined in `CxxWrap.StdLib` #455

Open peremato opened 1 week ago

peremato commented 1 week ago

I am trying to re-generate the wrappers for XRootD.jl with version v0.16.0 of CxxWrap and version v0.13.2 of libcxxwrap_julia_jll. I can build successfully the wrapper library, but when initialising I get the error:

julia> using XRootD
Precompiling XRootD...
Info Given XRootD was explicitly requested, output will be shown live 
ERROR: LoadError: UndefVarError: `StdFill` not defined in `CxxWrap.StdLib`
Stacktrace:
  [1] getproperty(x::Module, f::Symbol)
    @ Base ./Base.jl:42
  [2] top-level scope
    @ none:1
  [3] eval
    @ ./boot.jl:430 [inlined]
  [4] wrap_functions(functions::Vector{CxxWrap.CxxWrapCore.CppFunctionInfo}, julia_mod::Module)
    @ CxxWrap.CxxWrapCore ~/.julia/packages/CxxWrap/eWADG/src/CxxWrap.jl:773
  [5] wrapfunctions(jlmod::Module)
    @ CxxWrap.CxxWrapCore ~/.julia/packages/CxxWrap/eWADG/src/CxxWrap.jl:790
...

Any idea of what could be the problem? Thanks.

julia> versioninfo()
Julia Version 1.11.0-rc4
Commit b4b9add84db (2024-09-25 11:03 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M2
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m2)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)
Environment:
  JULIA_PROJECT = @.
barche commented 1 week ago

This looks like a possible version mismatch, can you check with CxxWrap.libcxxwrapversion() that this is using the correct libcxxwrap? Maybe also verify with Libdl.dllist() that no wrong library gets pulled in.

peremato commented 1 week ago

Thanks for the reply. I do not see it. Everything looks fine for me (I reverted to julia 1.10 just to check):

julia> using CxxWrap
julia> CxxWrap.libcxxwrapversion()
v"0.13.2"

julia> using Libdl
julia> for l in Libdl.dllist();occursin("cxxwrap",lowercase(l)) && println(l);end
/Users/mato/.julia/compiled/v1.10/libcxxwrap_julia_jll/9VnAb_b2u6u.dylib
/Users/mato/.julia/artifacts/a733004dc3a6d098fcb468930d1084d8fea63e5e/lib/libcxxwrap_julia.0.13.2.dylib
/Users/mato/.julia/artifacts/a733004dc3a6d098fcb468930d1084d8fea63e5e/lib/libcxxwrap_julia_stl.dylib
/Users/mato/.julia/compiled/v1.10/CxxWrap/WGIJU_b2u6u.dylib

The only possibility I see is that JLCXX_HAS_RANGES is not defined for MacOS when building the libcxxwrap_julia_jll . See https://github.com/JuliaInterop/libcxxwrap-julia/blob/587f9feb6b64baa512856af2d508fec1f63583bc/include/jlcxx/stl.hpp#L175

peremato commented 1 week ago

The problem is that for MacOS the compiler used is clang++ and does not support <ranges> therefore the define JLCXX_HAS_RANGES is false.

# /opt/bin/aarch64-apple-darwin20-libgfortran5-cxx11-julia_version+1.10.0/aarch64-apple-darwin20-clang++ -std=c++20 a.cpp
a.cpp:2:10: fatal error: 'ranges' file not found
    2 | #include <ranges>
      |          ^~~~~~~~
1 error generated.

Perhaps @giordano has an idea on how this can be overcome.

giordano commented 1 week ago

ranges may require a much newer SDK (13?): https://github.com/JuliaPackaging/Yggdrasil/pull/8613#discussion_r1590110545

barche commented 1 week ago

Ah yes, good catch, it is because of the #ifdef JLCXX_HAS_RANGES. Easiest solution I can think of is to expose a jlcxx_has_ranges function from libcxxwrap-julia and use that as a condition to use StdFill on the Julia side in CxxWrap. Upgrading the SDK on Yggdrasil is not enough I seem to remember, we need to upgrade the compiler itself.