mono / CppSharp

Tools and libraries to glue C/C++ APIs to high-level languages
MIT License
3.13k stars 516 forks source link

Only dependent classes have specializations Exception #782

Open pmelick opened 7 years ago

pmelick commented 7 years ago

I get an exception Only dependent classes have specializations while trying to generate C# bindings for a C++ library. I'm not sure how to tell which class(es) are triggering the error.

I did have to comment out add_argument(-fno-rtti) in src\CppParser\Parser.cpp as in https://github.com/mono/CppSharp/issues/768

I also had to add the clang include dirs from /opt/clang+llvm-3.8.0/

I don't know if the override warnings during the parser are related.

Thanks very much for your help

OS: Ubuntu 14.04

Target: Clang

Used settings:

public void Setup(Driver driver)
{
    var options = driver.Options;
    driver.ParserOptions.AddArguments ("-fcxx-exceptions");
    options.GeneratorKind = GeneratorKind.CSharp;
    options.Verbose = true;
    var module = options.AddModule("map_api");
        module.IncludeDirs.Add (<the correct include dirs>);
    module.Headers.Add("map_api.hh");
    module.LibraryDirs.Add (<the correct library dirs>);
    module.Libraries.Add ("libmap_api.so");
    module.IncludeDirs.Add ("/opt/clang+llvm-3.8.0/include/c++/v1");
    module.IncludeDirs.Add ("/opt/clang+llvm-3.8.0/lib/clang/3.8.0/include");
}

Stack trace:

Parsing libraries...
Parsed 'libmap_api.so'
Parsing code...
Parsed '/home/pmelick/av/source/mlp/libs/submap_graph/map_api.hh'
/home/pmelick/av/source/mlp/libs/geography/types.hh(248,5): warning: 'create' overrides a member function but is not marked 'override'
/home/pmelick/av/source/mlp/libs/geography/types.hh(248,5): warning: 'clone' overrides a member function but is not marked 'override'
/home/pmelick/av/source/mlp/libs/geography/types.hh(248,5): warning: 'assign' overrides a member function but is not marked 'override'
/home/pmelick/av/source/mlp/libs/geography/types.hh(248,5): warning: 'assign' overrides a member function but is not marked 'override'
/home/pmelick/av/source/mlp/libs/geography/types.hh(248,5): warning: 'assign_defaults' overrides a member function but is not marked 'override'
/home/pmelick/av/source/mlp/libs/geography/types.hh(425,5): warning: 'create' overrides a member function but is not marked 'override'
/home/pmelick/av/source/mlp/libs/geography/types.hh(425,5): warning: 'clone' overrides a member function but is not marked 'override'
/home/pmelick/av/source/mlp/libs/geography/types.hh(425,5): warning: 'assign' overrides a member function but is not marked 'override'
/home/pmelick/av/source/mlp/libs/geography/types.hh(425,5): warning: 'assign' overrides a member function but is not marked 'override'
/home/pmelick/av/source/mlp/libs/geography/types.hh(425,5): warning: 'assign_defaults' overrides a member function but is not marked 'override'
Processing code...

Unhandled Exception:
System.InvalidOperationException: Only dependent classes have specializations.
  at CppSharp.AST.Class.get_Specializations () [0x0000c] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.Passes.ResolveIncompleteDeclsPass+<VisitClassTemplateDecl>c__AnonStorey0.<>m__0 (CppSharp.AST.ClassTemplateSpecialization s) [0x00016] in <09575c55b94a485a8408093596e2d190>:0 
  at System.Linq.Enumerable+WhereListIterator`1[TSource].MoveNext () [0x00048] in <2392cff65f724abaaed9de072f62bc4a>:0 
  at CppSharp.Passes.ResolveIncompleteDeclsPass.VisitClassTemplateDecl (CppSharp.AST.ClassTemplate template) [0x000a9] in <09575c55b94a485a8408093596e2d190>:0 
  at CppSharp.AST.ClassTemplate.Visit[T] (CppSharp.AST.IDeclVisitor`1[T] visitor) [0x00001] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.AST.AstVisitor.VisitDeclarationContext (CppSharp.AST.DeclarationContext context) [0x00127] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.AST.AstVisitor.VisitNamespace (CppSharp.AST.Namespace namespace) [0x00001] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.AST.Namespace.Visit[T] (CppSharp.AST.IDeclVisitor`1[T] visitor) [0x00001] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.AST.AstVisitor.VisitDeclarationContext (CppSharp.AST.DeclarationContext context) [0x0027b] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.AST.AstVisitor.VisitNamespace (CppSharp.AST.Namespace namespace) [0x00001] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.AST.Namespace.Visit[T] (CppSharp.AST.IDeclVisitor`1[T] visitor) [0x00001] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.AST.AstVisitor.VisitDeclarationContext (CppSharp.AST.DeclarationContext context) [0x0027b] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.Passes.TranslationUnitPass.VisitTranslationUnit (CppSharp.AST.TranslationUnit unit) [0x00034] in <09575c55b94a485a8408093596e2d190>:0 
  at CppSharp.Passes.TranslationUnitPass.VisitASTContext (CppSharp.AST.ASTContext context) [0x0001b] in <09575c55b94a485a8408093596e2d190>:0 
  at CppSharp.Generators.BindingContext.<RunPasses>m__0 (CppSharp.Passes.TranslationUnitPass pass) [0x00029] in <09575c55b94a485a8408093596e2d190>:0 
  at CppSharp.PassBuilder`1[T].RunPasses (System.Action`1[T] action) [0x0001b] in <09575c55b94a485a8408093596e2d190>:0 
  at CppSharp.Generators.BindingContext.RunPasses () [0x00007] in <09575c55b94a485a8408093596e2d190>:0 
  at CppSharp.Driver.ProcessCode () [0x00007] in <09575c55b94a485a8408093596e2d190>:0 
  at CppSharp.ConsoleDriver.Run (CppSharp.ILibrary library) [0x0012e] in <09575c55b94a485a8408093596e2d190>:0 
  at CppSharp.SDL+Program.Main (System.String[] args) [0x00006] in /home/pmelick/cppsharp_test_3/cppsharp_test_3/Program.cs:73 
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: Only dependent classes have specializations.
  at CppSharp.AST.Class.get_Specializations () [0x0000c] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.Passes.ResolveIncompleteDeclsPass+<VisitClassTemplateDecl>c__AnonStorey0.<>m__0 (CppSharp.AST.ClassTemplateSpecialization s) [0x00016] in <09575c55b94a485a8408093596e2d190>:0 
  at System.Linq.Enumerable+WhereListIterator`1[TSource].MoveNext () [0x00048] in <2392cff65f724abaaed9de072f62bc4a>:0 
  at CppSharp.Passes.ResolveIncompleteDeclsPass.VisitClassTemplateDecl (CppSharp.AST.ClassTemplate template) [0x000a9] in <09575c55b94a485a8408093596e2d190>:0 
  at CppSharp.AST.ClassTemplate.Visit[T] (CppSharp.AST.IDeclVisitor`1[T] visitor) [0x00001] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.AST.AstVisitor.VisitDeclarationContext (CppSharp.AST.DeclarationContext context) [0x00127] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.AST.AstVisitor.VisitNamespace (CppSharp.AST.Namespace namespace) [0x00001] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.AST.Namespace.Visit[T] (CppSharp.AST.IDeclVisitor`1[T] visitor) [0x00001] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.AST.AstVisitor.VisitDeclarationContext (CppSharp.AST.DeclarationContext context) [0x0027b] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.AST.AstVisitor.VisitNamespace (CppSharp.AST.Namespace namespace) [0x00001] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.AST.Namespace.Visit[T] (CppSharp.AST.IDeclVisitor`1[T] visitor) [0x00001] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.AST.AstVisitor.VisitDeclarationContext (CppSharp.AST.DeclarationContext context) [0x0027b] in <21227c3295334c30a0f9e4c68e63aee7>:0 
  at CppSharp.Passes.TranslationUnitPass.VisitTranslationUnit (CppSharp.AST.TranslationUnit unit) [0x00034] in <09575c55b94a485a8408093596e2d190>:0 
  at CppSharp.Passes.TranslationUnitPass.VisitASTContext (CppSharp.AST.ASTContext context) [0x0001b] in <09575c55b94a485a8408093596e2d190>:0 
  at CppSharp.Generators.BindingContext.<RunPasses>m__0 (CppSharp.Passes.TranslationUnitPass pass) [0x00029] in <09575c55b94a485a8408093596e2d190>:0 
  at CppSharp.PassBuilder`1[T].RunPasses (System.Action`1[T] action) [0x0001b] in <09575c55b94a485a8408093596e2d190>:0 
  at CppSharp.Generators.BindingContext.RunPasses () [0x00007] in <09575c55b94a485a8408093596e2d190>:0 
  at CppSharp.Driver.ProcessCode () [0x00007] in <09575c55b94a485a8408093596e2d190>:0 
  at CppSharp.ConsoleDriver.Run (CppSharp.ILibrary library) [0x0012e] in <09575c55b94a485a8408093596e2d190>:0 
  at CppSharp.SDL+Program.Main (System.String[] args) [0x00006] in /home/pmelick/cppsharp_test_3/cppsharp_test_3/Program.cs:73
tritao commented 7 years ago

@ddobrev Any idea about this one? Might be related to the recent template changes.

@pmelick What Git revision are you working with?

pmelick commented 7 years ago

Latest commit is 8b230bdf07a1ce352e441f2cc634ac7b84c82618, pulled on Monday.

ddobrev commented 7 years ago

@pmelick may I ask you to debug this one? I admit I have no idea how it happened because Class.Specializations only throws an exception when the class it's called on is not dependent. The method in the stack trace on the other hand only works with dependent classes.

pmelick commented 7 years ago

Thanks for the response @ddobrev. Happy to help debug. Can you tell me how I would go about finding which native class is causing the problem?

ddobrev commented 7 years ago

You could just run it in the debugger. When it crashes, you'll be able to see the names and headers of all involved declarations.