Giter Site home page Giter Site logo

mono / cppsharp Goto Github PK

View Code? Open in Web Editor NEW
3.0K 155.0 498.0 37.59 MB

Tools and libraries to glue C/C++ APIs to high-level languages

License: MIT License

Shell 0.05% Lua 0.31% C# 83.69% C++ 15.80% C 0.05% CMake 0.01% JavaScript 0.08% TypeScript 0.01%
cppsharp parsing glue syntax-tree c-sharp c clang mono visitors cplusplus

cppsharp's Introduction

CppSharp is a tool and set of libraries which facilitates the usage of native C/C++ code with the .NET ecosystem.

It consumes C/C++ header and library files and generates the necessary glue code to surface the native API as a managed API. Such an API can be used to consume an existing native library in your managed code or add managed scripting support to a native codebase.

The supported target languages at present are C# and C++/CLI.

It can also be used as a library to parse native code into a syntax tree with a rich declaration and type information model.

Releases/Build Status

NuGet Packages Continuous Integration
NuGet GitHub-actions
  1. Libraries
  2. Documentation
  3. Community
  4. Support
  5. Users

Libraries

AST

Mirrors the Clang's C/C++ AST and type system classes in C# APIs.

Check out Clang's AST introduction docs for more details about its architecture.

  • C++ declarations
  • C++ statements / expressions
  • C++ types
  • Class object layout
  • Declaration visitors
  • Type visitors

Parser

Provides APIs for parsing of C/C++ source code into a syntax tree.

  • Parsing of C/C++ source code
  • Parsing of libraries archives symbols
  • Parsing of shared libraries symbols
  • Based on the very accurate Clang C++ parser.

Generator

Generates the glue binding code from a syntax tree of the native code.

  • Multiple backends: C++/CLI and C# (P/Invoke)
  • Multiple ABIs: Itanium, MS, ARM, iOS
  • Multiple platforms: Windows, OS X and Linux
  • Multiple runtimes: .NET and Mono
  • C++ virtual methods overriding from managed code
  • C++ multiple inheritance by translating to C# interfaces
  • C++ std::string
  • C++ default parameter values
  • C/C++ semantic comments (Doxygen) to C# comments
  • Extensible bindings semantics via user passes and type mapping

Documentation

Please see the following resources for more information:

Getting Started

User's Manual

Developer's Manual

Community

Feel free to open up issues on GitHub for any problems you find.

Support

If you need commercial support feel free to open a discussion or issue for discussion.

Users

CppSharp is used by the following projects:

Kythera AI

QtSharp

MonoGame

LLDBSharp

Xamarin

FFMPEG.net

FFmpeg bindings

Tizen bindings

libgd bindings

ChakraSharp

FFmpeg.AutoGen

GLFW3.NET

DearImguiSharp

Please feel free to send us a pull request adding your own projects to the list above.

cppsharp's People

Contributors

azeno avatar chkn avatar ddobrev avatar deadlocklogic avatar elonh avatar esdrubal avatar fsinisi90 avatar genuinelucifer avatar golddranks avatar iife avatar josetr avatar jpnoir avatar konistehrad avatar mohtamohit avatar oysteinkrog avatar realvictorprm avatar rokups avatar saalvage avatar shana avatar stephenatwork avatar sundermann avatar tapika avatar tomba avatar tomspilman avatar tritao avatar trungnt2910 avatar vargaz avatar vovkasm avatar xistoso avatar zillemarco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cppsharp's Issues

Underscores In OutputNamespace

If I do the following:

options.OutputNamespace = "Company.Product.Library";

The generated namespace is:

namespace Company_Product_Library
{

.. and not what I expected which is...

namespace Company.Product.Library
{

This seems to be caused by using SafeIdentifier on the namespace string.

Finalizers

It would be nice for CppSharp to generate C# finalizers for all wrapped objects. I currently work around this by adding them to a separate source file as a partial class implementation:

    public unsafe partial class Texture
    {
        ~Texture()
        {
            Dispose(false);
        }
    }

    public unsafe partial class RenderTarget
    {
        ~RenderTarget()
        {
            Dispose(false);
        }
    }

The finalizer is necessary to properly cleanup the unmanaged parts of the wrapper when the user omits a direct call to Dispose(). You already call GC.SuppressFinalize(this) which means the finalizer will not do any extra work unless it is needed.

Some people prefer to not have finalizers and instead force the caller to properly dispose of their objects. In this case adding a finalizer could be optional and when disabled it could add something like this instead:

#if DEBUG
    ~WrapperClass()
    {
        Debug.Fail("You forgot to call Dispose!");
    }
#endif

To alert the user that they forgot to Dispose() this object and that the unmanaged objects were leaked.

By the way we're using CppSharp to generate C# wrappers for a project running on the PS4. It has been fantastic and much easier than if we needed to generate our own bindings.

Static Functions Issues

I'm having issues with exporting static functions from C++ without getting weird looking wrappers.

My first try was just adding static methods to a class with private constructor. My thinking was that since the class had nothing but static methods, CppSharp would not make it constructible.... but that does not seem to be the case. The final class had constructors and dispose methods.

My next try was just putting plain methods in a header:

// MyStaticClass.h
#pragma once
#include "PreDecls.h"

__declspec(dllexport) bool MyStaticMethod();

What I got was this...

namespace MyNamespace
{
    public unsafe partial class MyNamespace_MyStaticClass
    {
        public struct Internal
        {
           // blah blah blah
        }

        public static bool MyStaticMethod()
        {
            var __ret = Internal.MyStaticMethod_0();
            return __ret;
        }
    }
}

Instead of having the class named after the header file... MyStaticClass... I got something with the assembly namespace prepended MyNamespace_MyStaticClass.

So what is the best way to get a C# style "static class" wrapper from C++?

Include a known-good llvm revision

Because CppSharp requires a trunk version of llvm it would be nice to keep the an up to date known-good revision number in the version getting started docs.

Functions not found in the library symbols

They are many, here's just 3 examples: QModelIndex::row(), QModelIndex::column(), QModelIndex::model(). Using Qt MinGW 5.1.0 with:

driver.Options.GeneratorKind = LanguageGeneratorKind.CSharp;
string qtModule = "QtCore";
driver.Options.Abi = CppAbi.Itanium;
driver.Options.LibraryName = string.Format("{0}Sharp", qtModule);
driver.Options.Verbose = true;
driver.Options.IgnoreParseWarnings = true;
driver.Options.Headers.Add("qabstractitemmodel.h");
driver.Options.IncludeDirs.Add(@"C:\Qt\Qt5.1.0\5.1.0\mingw48_32\include");
driver.Options.IncludeDirs.Add(Path.Combine(@"C:\Qt\Qt5.1.0\5.1.0\mingw48_32\include", qtModule));
driver.Options.LibraryDirs.Add(@"C:\Qt\Qt5.1.0\5.1.0\mingw48_32\lib");
driver.Options.Libraries.Add("libQt5Core.a");
driver.Options.Defines.Add("_MSC_FULL_VER=170050215");

OSX Support

I've had trouble with building and using this on OSX. Ultimately I have compiled the projects, but I have problems with unresolved symbols for ASTContext (_ZN8CppSharp9CppParser3AST10ASTContextC2Ev). The constructor is not defined in AST.h, so I'm not sure how this was generated in AST.cs. I can go and add in an empty constructor for ASTContext, but then I get some other errors due to null values somewhere...

Does anyone have some clearer instructions on how to get the OSX build up?

Unhandled Exception:
System.NotSupportedException: Original pointer must not be null
  at CppSharp.DeclConverter.Visit (CppSharp.Parser.AST.Declaration decl) [0x00000] in <filename unknown>:0
  at CppSharp.DeclConverter.VisitDeclaration (CppSharp.Parser.AST.Declaration decl, CppSharp.AST.Declaration _decl) [0x00000] in <filename unknown>:0
  at CppSharp.DeclConverter.VisitTranslationUnit (CppSharp.Parser.AST.TranslationUnit decl) [0x00000] in <filename unknown>:0
  at CppSharp.DeclVisitor`1[CppSharp.AST.Declaration].Visit (CppSharp.Parser.AST.Declaration decl) [0x00000] in <filename unknown>:0
  at CppSharp.DeclConverter.Visit (CppSharp.Parser.AST.Declaration decl) [0x00000] in <filename unknown>:0
  at CppSharp.ASTConverter.Convert () [0x00000] in <filename unknown>:0
  at CppSharp.ClangParser.ConvertASTContext (CppSharp.Parser.AST.ASTContext context) [0x00000] in <filename unknown>:0
  at CppSharp.Driver.ParseCode () [0x00000] in <filename unknown>:0
  at CppSharp.ConsoleDriver.Run (ILibrary library) [0x00000] in <filename unknown>:0
  at Crap.Test+Program.Main (System.String[] args) [0x00000] in <filename unknown>:0

Const and non-const constructor overloads

When signatures clash, they're given an ordinal to disambiguate them. This doesn't work for constructors however.

struct Overloaded
{
    Overloaded(void* p) {}
    Overloaded(const void* p) {}
};

I'm not sure what the best answer for this is. Add extra discriminant parameters or fallback to runtime dispatch?

public void Overloaded(void* p, int isConst) // runtime
{
     var arg0 = p;
     if(isConst) Internal._Overloaded0(__Instance, arg0);
     else Internal._Overloaded1(__Instance, arg0);
}
public void Overloaded(void* p, Const.True)
public void Overloaded(void* p, Const.False)

I'm not familiar with c# generics but perhaps there's a solution there?

Error from STL Library

My C++ code contains Standard Library functions and I am having a trouble running CppSharp due to that.
On my header file, I have something like:
int testFunc(std::string x);

Then my C# code, I did similar as what the example did, include Library and header files with correct directory. After running the problem, I get errors like:

error CS0246: The type or namespace name 'std' could not be f
ound (are you missing a using directive or an assembly reference?)

error CS0208: Cannot take the address of, get the size of, or
declare a pointer to a managed type ('std.basic_string.Internal')
c:\Users

error CS1061: 'Std.String' does not contain a definition for
__Instance' and no extension method __Instance' accepting a first argument of
type 'Std.String' could be found (are you missing a using directive or an assem
bly reference?)

When I look at the .cs file, it generates to:
internal static extern int testFunc1_0(global::System.IntPtr instance, Std.String x);

I just downloaded the latest VS dlls (Nov 13th ver 423). I am also having similar error messages when I use stl , and others. Do I need to do some customization or something? How to make CppSharp recognizes my STL stuff? Thanks

LLVM/Clang Latest Breaks CppSharp

So after hours of trying to get CppSharp to build I've gotten close, but found out finally that the latest changes to LLVM/Clang break CppSharp.

I'm working on a PR to fix this now.

windows.h not found

In the native header I reference a third party library that uses

#include <windows.h>

I use

options.IncludeDirs.Add("PATH_TO_3RDPARTY_DIR"); 

and

ctx.IgnoreHeadersWithName("HEADER_NAME");

this works with the CppSharp_VS2012_423 release but using the latest 933 build from Teamcity I get:

fatal windows.h file not found 

and the bindings are not produced. Is this a clang problem or cppSharp?

EntryPointNotFoundException with a simple example

I am testing the usage of the library (CppSharp_VS2012_423_artifacts.zip) with a simple project in VS2012.
I have the following three projects based on some test projects you have in the repository:
Native.vcxproj with Native.h

#if defined(_MSC_VER)
#define DLL_API __declspec(dllexport)
#else
#define DLL_API
#endif

class DLL_API Foo
{
public:
     Foo();
     int A;
     float B;
const char* GetANSI();
};

and Native.cpp

#include "Native.h"  

const char* Foo::GetANSI()
{
 return "ANSI";
}

WrapperGenerator with Program.cs

using System;
using CppSharp;
using CppSharp.AST;
using CppSharp.Generators;

namespace WrapperGenerator
{
       class Program : ILibrary
      {
           static void Main(string[] args)
           {
                 ConsoleDriver.Run(new Program());
                 Console.ReadLine();
            }

           public void Setup(Driver driver)
           {            
        var options = driver.Options;
        options.Verbose = true;
        options.GeneratorKind = GeneratorKind.CSharp;          
        options.LibraryName = "Native";           
        options.Headers.Add(@"F:\Repositories\TestCppSharp\Source\Native\Native.h");
        options.OutputDir = @"F:\Repositories\TestCppSharp\Source\TestCppSharp\";            
        //options.TargetTriple = "i686-pc-win32";          
    }

    public void SetupPasses(Driver driver) { }
    public void Preprocess(Driver driver, ASTContext ctx)  { }
    public void Postprocess(Driver driver, ASTContext ctx) { }
   }

}

The Native.cs file is generated successfully and I have the following simple program in another project TestCppSharp

using System;
using Native;

 namespace TestCppSharp
 {
      class Program
     {
           static void Main(string[] args)
           {
                   Native.Foo d = new Foo();
                   Console.WriteLine(d.GetANSI());
           }
     }
  }

When I run this I get EntryPointNotFoundException inside Native.cs in

    public Foo()
    {
        __Instance = Marshal.AllocHGlobal(8);
        Internal.ctor_0(__Instance);
    }

Any ideas what might be wrong? Also, is the current Getting-Started documentation up-do-date? I could help with that if you want. In that guide the generated code does not include CppSharp.Runtime.ICppMarshal interface. Is it possible to do that in my example?

Need a way to indicate that one header depends on the macros in another header

I have two headers where one header depends on the macros defined in the other header, but the second header doesn't include the first header. The assumption is that the first header will always be included in a file before the second header. As a result, I'm getting errors in the second header.

Currently I am resolving this issue by creating a third header which includes the other two headers in the appropriate order. It would be nice to have some way of indicating this dependency in code rather than having to create another header.

Wrong parameters of operators generated by Q_DECLARE_OPERATORS_FOR_FLAGS

To reproduce, run the latest Qt# (https://github.com/ddobrev/QtSharp/) and check, for example, QtCoreqstring.operator_. This is the | operator (you can see the internal call), apparently generated by Q_DECLARE_OPERATORS_FOR_FLAGS - there is no other | operator in qstring.h. Its parameters are of type Qt.MouseButton. At the same time, one can see that the call to Q_DECLARE_OPERATORS_FOR_FLAGS is given as its argument QString::SectionFlags.
Note: Qt.MouseButton is used as the incorrect replacement in all cases.

Syntax Errors In Generator.Tests

There are some syntax errors in the current Generator.Tests library that I don't know how to fix myself.

First in TestPasses.cs you have this:

        [SetUp]
        public void Setup()
        {
            ParseLibrary("Passes.h");
            passBuilder = new PassBuilder(library); // < ERROR!  PassBuilder needs a Driver now!
        }

Then in TestCLITypePrinter.cs:

        [TestFixtureSetUp]
        public void Init()
        {
            ParseLibrary("CLITypes.h");
            printer = new CLITypePrinter(database, library); // < ERROR! needs a Driver and a CLITypePrinterContext!
        }

wrapping interface-based libraries

It seems CppSharp is unable to wrap interface-based libraries. It outputs lots of "Symbol not found" warnings with mangled names. These mangled names are not exported of course. Library exports only few functions and provides header files full of pure virtual declarations of methods. User does not create library objects either - calls to library api return created objects. Tested with this: http://downloads.sourceforge.net/irrlicht/irrlicht-1.8.zip and oct 25 binary release.

Support dependent fields in internals

We need to handle cases such as:

template
class Whatever
{
T Foo;
}

class Bar
{
Whatever W;
}

In here, Foo is a dependent field. We need to represent it in Internals as an int. One of the approaches is generating a separate internal struct per template specialisation.

No Destructor Generated?

I have the following class:

class __declspec(dllexport) MyClass
{        
public:
    MyClass();
    ~MyClass();
};

... after generation the dispose methods look like this:

        public void Dispose()
        {
            Dispose(disposing: true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            Marshal.FreeHGlobal(__Instance);
        }

I don't see it trying to execute my destructor method at all.

Correct Location to Run Cmake

The docs say:
4.Run CMake in \deps\llvm and compile solution in RelWithDebInfo mode

which results in the .lib files being put in "deps\llvm\RelWithDebInfo" , but the CppSharp project is looking in "deps\llvm\build\RelWithDebInfo". Am I supposed to run Cmake in the build folder?

MinGW symbols not found

While wrapping QtCore, no symbol is found. The searched for symbols (that is, the parameter "symbol" of Library.FindSymbol) have a format similar to:

??0QForeachContainerBase@@qeaa@XZ

while the keys of Library.Symbols are of the formats:

__imp___Zls6QDebugRK21QPersistentModelIndex
_z_inflatePrime

Changing Driver.Options.Abi to Itanium (the default is Microsoft) makes no difference.

Wrapping 64bit DLLs

So when trying to wrap a 64bit DLL the generator made the wrapper like this:

        [StructLayout(LayoutKind.Explicit, Size = 4)]
        public struct Internal
        {
           ...
        }

        int CppSharp.Runtime.ICppMarshal.NativeDataSize
        {
            get { return 4; }
        }

        public MyClass()
        {
            __Instance = Marshal.AllocHGlobal(4);
            Internal.MyClass_0(__Instance);
        }

Causing memory corruption when calling the 64bit library. Manually replacing all the '4's with '8's fixed it.

How do I define for my ILibrary that my DLL is 64bit?

Multiple identifiers have same name.

For example this is generated when trying to wrap irrlicht:

[SuppressUnmanagedCodeSecurity]
[UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)]
delegate void __IGUIButtonDelegate(global::System.IntPtr instance);
static __IGUIButtonDelegate __IGUIButtonDelegateInstance;

static void __IGUIButtonDelegateHook(global::System.IntPtr instance)
{
    if (!_References.ContainsKey(instance))
        throw new Exception("No managed instance was found");

        var target = (IGUIButton) _References[instance].Target;
        target.Dispose();
}

[SuppressUnmanagedCodeSecurity]
[UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.ThisCall)]
delegate void __IGUIButtonDelegate(global::System.IntPtr instance);
static __IGUIButtonDelegate __IGUIButtonDelegateInstance;

static void __IGUIButtonDelegateHook(global::System.IntPtr instance)
{
    if (!_References.ContainsKey(instance))
        throw new Exception("No managed instance was found");

    var target = (IGUIButton) _References[instance].Target;
    target.Dispose();
}

Other files have only repeated delegate type definitions.
Used config:

options.Abi = CppAbi.Microsoft;
options.GenerateInterfacesForMultipleInheritance = true; 
options.GenerateVirtualTables = true;
options.CheckSymbols = false;

Generating bindings for C library/ABI

What is the story if I want to generate bindings for e.g. ffmpeg?
Having a "C" mode seems like a very useful thing to me, is this something that is a goal/desired? (I'm really tired of creating p/invoke stuff by hand ...)

I have not found a way to generate nice C bindings using the existing options, but I've been able to get calling convention etc. correct by modifying Parser.cpp to pass -std=gnu99.
I guess there might be some work needed other places as well to get things working, any ideas/suggestions?

Receiving alot of errors when parsing

When trying to generate both CLI and C# wrappers I receive many errors for a couple of projects. So I am trying to figure out if I am doing something wrong here. The errors I seem to be receiving are:

Unhandled typdef errors
Duplicate names
Unknown typename

I know duplicate names is just a warning, but when I look at some of the files generated a large portion of it is generic names from the renaming. For the most part it generates the proper files, except it seems like it is not generating any files for the headers that are receiving the Unknown typename errors. Which is a large portion of one of the libraries. Is there any way I can minimize these errors, possible some extra steps that I can take. so I can have functional wrappers?

I am not using any SetupPasses, preprocess, or postprocess configuration ATM.

Error when parsing headers referenced includes.

Just want to say, awesome project. Great concept, and it is unbelievable how easy you have made it for others.

I do have a question though. When CppSharp parses the headers I specify, I get an error about the headers that are referenced within the .h file, saying they can not be found. Mainly when they are in this format: "includes/types.h"

I am adding a folder for the includes as such:

options.IncludeDirs.Add(@"C:\Users\Joe\Documents\Testapp\lib\includes");

Then adding each header as such:

options.Headers.Add("interface.h");

Now I know I could bypass this, but I am wondering if their is a way to set ignore parameters on headers. So I could ignore certain strings? Unless there is another way of fixing this.

String Memory Leak

I noticed this in one of our wrapped functions:

        protected Effect(string name)
        {
            var arg0 = Marshal.StringToHGlobalAnsi(name);
            __Instance = Marshal.AllocHGlobal(88);
            Internal.ctor_0(__Instance, arg0);
        }

Here you use Marshal.StringToHGlobalAnsi to marshal the string to C++, but you don't free the string. From the docs it says that you should be calling Marshal.FreeHGlobal(arg0); to free that memory.

I suspect this is a memory leak in CppSharp.

Handle non-TagDecl bases

BaseClassSpecifier.Class has the following code:
if (!Type.IsTagDecl(out @Class))
throw new NotSupportedException();

Which means generation fails for classes which inherit templates. This branch adds a test case to the Basic test.

It also has hacks to early out for non-TagDecl bases which at least allows generation to succeed. Should I make a pull request or is there a better way to handle this?

https://github.com/sk-havok/CppSharp/tree/req/non_class_base

SDL Example Crash

Building against LLVM/Clang r185136 the SDL example crashes under VS2012.

The crash is in ASTVisitor.VisitParameterDecl:

        public virtual bool VisitParameterDecl(Parameter parameter)
        {
            if (!VisitDeclaration(parameter))
                return false; 

            return parameter.Type.Visit(this, parameter.QualifiedType.Qualifiers); //< CRASH!
        }

It is caused by parameter.Type being null. Inspecting the parameter.Name it is "argv" and that it is trying to process the "SDL_main" function.

Not sure if this error should be more gracefully handled?

Maybe the sample should skip processing SDL_main.h?

Can't wrap operator*

Operator* will need to be renamed in the bindings. It currently generates

public static void* operator *(SmartPtr __op)

from

struct SmartPtr
{
    void* operator*() { return nullptr; }
};

How to pass string by reference?

I have the following simple method

void Test(char* output)
{
   output = strdup("This is a test");
}

How can I make the generator produce something like:

internal static extern void Test_0(global::System.IntPtr instance, out string output);

Currently it produces something like:

internal static extern void Test_0(global::System.IntPtr instance, sbyte* output);

and if you add the following line to Preprocess

ctx.SetMethodParameterUsage("Foo", "Test", 1, ParameterUsage.Out);

it will produce

internal static extern void Test_0(global::System.IntPtr instance, out sbyte output);

Null reference exception when parsing header

I'm happy to help debug the below error, I'm just not sure where to start.

I'm trying to generate wrappers for the octave libraries (). I'm getting the null reference exception below. The null is generated on line 505 of parser.cpp (VTLayout is null):

auto& VTLayout = VTContext.getVFTableLayout(RD, VFPtrInfo.VFPtrOffset);

Here is the exception:

System.NullReferenceException occurred
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=CppSharp.Parser
StackTrace:
at llvm.OwningArrayPtrclang::VTableComponent.get(OwningArrayPtrclang::VTableComponent* ) in c:\cppsharp\cppsharp\deps\llvm\include\llvm\adt\owningptr.h:line 135
InnerException:

Here is my setup code:

    public void Setup(Driver driver)
    {
        var options = driver.Options;
        options.LibraryName = "OctaveSharp";
        options.Headers.Add("oct.h");
        options.IncludeDirs.Add(@"C:\Octave-class\3.2.4_gcc-4.4.0\include\octave-3.2.4\octave");
        options.LibraryDirs.Add(@"C:\Software\Octave-3.6.4\lib\octave\3.6.4");
        options.Libraries.Add(@"octave.lib");
        options.OutputDir = @"C:\CppSharp\CppSharp\OctaveSharp";
    }

Octave was installed using:
http://sourceforge.net/projects/octave/files/Octave%20Windows%20binaries/Octave%203.6.4%20for%20Windows%20Microsoft%20Visual%20Studio/

Unsafe Externs

I was getting errors from the usage of unsafe in the SDL example like so:

            [SuppressUnmanagedCodeSecurity]
            [DllImport("SymbolNotFound", CallingConvention = CallingConvention.Cdecl,
                EntryPoint="SDL_NumJoysticks")]
            public unsafe static extern int NumJoysticks0();

But really... unsafe is not needed here... that code compiles fine without the unsafe keyword.

Should GenerateInternalFunction be fixed to not put unsafe on all externs?

How to get started with CppSharp in a Win32 Dynamic Library like this ?

一个.h文件DllDemo.h

ifdef DllDemo_EXPORTS

define DllAPI __declspec(dllexport)

else

define DllAPI __declspec(dllimport)

extern "C" //原样编译
{
DllAPI int __stdcall Max(int a,int b); //__stdcall使非C/C++语言内能够调用API
}

endif

在DllDemo.cpp文件中导入DllDemo.h文件,并实现Max(int,int)函数

include "DllDemo.h"

DllAPI int __stdcall Max(int a,int b)
{
if(a==b)
return NULL;
else if(a>b)
return a;
else
return b;
}

Null ref at Enumeration.Item.IsHexadecimal with qmetatype.h

The problem is that most enum members of QMetaType::Type are defined using a macro, that is:

enum Type {
    // these are merged with QVariant
    QT_FOR_EACH_STATIC_TYPE(QT_DEFINE_METATYPE_ID)

    FirstCoreType = Bool,
    LastCoreType = QJsonDocument,
    FirstGuiType = QFont,
    LastGuiType = QPolygonF,
    FirstWidgetsType = QSizePolicy,
    LastWidgetsType = QSizePolicy,
    HighestInternalId = LastWidgetsType,

    QReal = sizeof(qreal) == sizeof(double) ? Double : Float,

    UnknownType = 0,
    User = 1024
};

I'd think the macro would have to be expanded before working with the items of the enum.

Parser::ParseSharedLib depends on unimplemented function

I'm trying to use a library, "vc100-liboctave-1.dll" (part of a standard windows Octave install), but I'm getting the following error:

For this function:

ParserResultKind Parser::ParseSharedLib(llvm::StringRef File,
                                            llvm::MemoryBuffer *Buffer)

this line:

for(auto it = Object->begin_dynamic_symbols(); it != Object->end_dynamic_symbols();

depends on unimplemented function:

symbol_iterator COFFObjectFile::begin_dynamic_symbols() const {
  // TODO: implement
  report_fatal_error("Dynamic symbols unimplemented in COFFObjectFile");
}

SDL Example Fails For Unions

The SDL example now runs into some unions when processing.

In particular in SDL_RWops...

typedef struct SDL_RWops
{
    union
    {
#if defined(ANDROID)
        struct
        {
            void *fileNameRef;

In SDL_Event....

/**
 *  \brief General event structure
 */
typedef union SDL_Event
{

In SDL_HapticEffect....

typedef union SDL_HapticEffect
{
    /* Common for all force feedback effects */
    Uint16 type;                    /**< Effect type. */
    SDL_HapticConstant constant;    /**< Constant effect. */

In SDL_GameControllerButtonBind:

typedef struct SDL_GameControllerButtonBind
{
    SDL_GameControllerBindType bindType;
    union
    {
        int button;
        int axis;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.