mono / CppSharp

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

std::string rebind lookup failure due to FindClass not searching for templates #752

Open lightgoleft opened 7 years ago

lightgoleft commented 7 years ago

Hello,

I am trying to wrap my c++ library into c sharp on android. However, it turned out ignoring many of my functions due to std::string, i.e., template std::allocator<>. I saw some of issues in same sort on forum, so I want to make sure whether it is my mis-using cppsharp or it is out of some limitation.

my class is like:

Myclass{
  void Foo(const string* A, string* B);
}

Cppsharp log:

Parsing libraries...
Parsed 'MiBUS_NDKD.a'
Parsing code...
ignoring nonexistent directory "lib\clang\3.9.0\include"
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "..\lib\clang\3.9.0\include"
ignoring nonexistent directory "/include"
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 C:\workspace\RFTOOLS\MiBUS\inc
 C:\workspace\RFTOOLS\MiBUS
 c:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r11c\platforms\android-19\arch-arm\usr\include
 C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r11c\sources\cxx-stl\gnu-libstdc++\4.9\include
 C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r11c\sources\cxx-stl\gnu-libstdc++\4.9\libs\armeabi-v7a\include
 C:\ProgramData\Microsoft\AndroidNDK64\android-ndk-r11c\sources\cxx-stl\gnu-libstdc++\4.9\include\backward
 Z:\workspace\git\CppSharp\build\scripts\llvm-cccdd2-windows-vs2015-x86-RelWithDebInfo\lib\clang\3.9.0\include
End of search list.
...
...
Processing code...
Pass 'CppSharp.Passes.SortDeclarationsPass'
Pass 'CppSharp.Passes.ResolveIncompleteDeclsPass'
    Unresolved declaration: rebind
    Unresolved declaration: rebind
    Unresolved declaration: rebind
    Unresolved declaration: rebind
...
...

After doing some researching and debugging, I found "std::allocator<sbyte>::rebind" does exist under

Cppsharp.AST.ASTContext->mudule(allocator.h) -> namespaces(std) ->templates(allocator) ->specialization(allocator<sbyte>)

but ASTContect.FindClass() only searches classes but no templates and their specializations, which causes the problem.

Thanks.

OS: Windows with Xamarin

Target: Clang/NDK

Other settings

ddobrev commented 7 years ago

Functions which use std::string should not be ignored so there definitely is some bug there. However, it doesn't really matter because std::string is not properly supported yet anyway. I am afraid I am going to be really busy for at least a week so I could only take a look afterwards.