Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Invalid subtyping #327

Closed
torrance opened this issue Sep 2, 2022 · 5 comments
Closed

Invalid subtyping #327

torrance opened this issue Sep 2, 2022 · 5 comments

Comments

@torrance
Copy link

torrance commented Sep 2, 2022

I've seen this error elsewhere (e.g. #326) but in my case I am on Julia 1.8.

I have the following toy C++:

#include <jlcxx/jlcxx.hpp>
#include <jlcxx/stl.hpp>

class Rectangle {
    int width, height;
  public:
    Rectangle(int, int);
    int area() {
        return width * height;
    }
};

Rectangle::Rectangle(int a, int b) {
  width = a;
  height = b;
}

JLCXX_MODULE define_julia_module(jlcxx::Module &mod) {
    mod.add_type<Rectangle>("Rectangle")
        .constructor<int, int>();
}

I am building this using binary builder and installing a local dev module (casacorejl_jll). When I include this in my module as such:

module Casacore

using casacorejl_jll
using CxxWrap

@wrapmodule("libcasacorejl.so")

function __init__()
    @initcxx
end

end

I get the following error:

ERROR: LoadError: invalid subtyping in definition of Rectangle with supertype Any

I'm at a loss what I am doing wrong here. Any help?

@torrance
Copy link
Author

torrance commented Sep 5, 2022

I've created a full MWE here (https://github.com/torrance/cxxtest), which includes the BinaryBuilder build_tarballs.jl script and CMake files, in case it is of any use in debugging and/or reproducing this.

My workflow looks like this:

cd cxxtest
julia build_tarballs.jl --deploy=local
julia --project=.

Then inside Julia:

] add CxxWrap
] dev libcxxtest_jl
include("CxxTest.jl")

The error message:

julia> include("CxxTest.jl")
C++ exception while wrapping module CxxTest: invalid subtyping in definition of Rectangle with supertype Any
ERROR: LoadError: invalid subtyping in definition of Rectangle with supertype Any
Stacktrace:
 [1] register_julia_module
   @ ~/.julia/packages/CxxWrap/IdOJa/src/CxxWrap.jl:405 [inlined]
 [2] readmodule(so_path::String, funcname::Symbol, m::Module, flags::Nothing)
   @ CxxWrap.CxxWrapCore ~/.julia/packages/CxxWrap/IdOJa/src/CxxWrap.jl:734
 [3] wrapmodule(so_path::String, funcname::Symbol, m::Module, flags::Nothing)
   @ CxxWrap.CxxWrapCore ~/.julia/packages/CxxWrap/IdOJa/src/CxxWrap.jl:738
 [4] include(fname::String)
   @ Base.MainInclude ./client.jl:476
in expression starting at /home/torrance/cxxtest/CxxTest.jl:1

@benlorenz
Copy link
Contributor

This error often happens when running and building with different julia / libjulia versions.
Even if the log says libjulia_jll v1.8.0 it might be using binaries for 1.6, 1.7 or even 1.9, they are all under the same release but with different platforms: https://github.com/JuliaBinaryWrappers/libjulia_jll.jl/releases/tag/libjulia-v1.8.0%2B2
You might see the version that is really used in the cmake output when running the build with --verbose.

You need to build separate binaries for each minor julia version using L/libjulia/common.jl, the version will then be included in a platform-tag. You can look at some examples on Yggdrasil: https://github.com/JuliaPackaging/Yggdrasil/search?q=libjulia

@torrance
Copy link
Author

torrance commented Sep 5, 2022

That's it! For anyone else encountering this problem when doing local development with build_tarballs.jl, I used an additional julia_version key in my Platforms list, e.g.:

platforms = [Platform("x86_64", "linux"; libc="glibc", julia_version="1.8")]

For supporting a range of versions, see the search listing @benlorenz provided: https://github.com/JuliaPackaging/Yggdrasil/search?q=libjulia

@torrance torrance closed this as completed Sep 5, 2022
@j-hayes
Copy link

j-hayes commented Sep 4, 2024

Just adding my comment for others who might come across this. Make sure that the version of julia you are using is the one that comes out of your $PATH variable. I.e. I ran /opt/julia-1.x.0/bin/julia but my default julia in my $PATH is /opt/julia-1.y.0/bin

@divital-coder
Copy link

@benlorenz Thank you so much, I admire your comment so much, u have no idea how much time i spent headbutting this issue, until i finally realised it was simply a julia version compat issue, hope u have an awesome day on your side of the screen :)

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

No branches or pull requests

4 participants