Skip to content

Segmentation fault when generating a wrapper for Qt code #1957

@graslany

Description

@graslany

Hello,

I tried running CppSharp on a simple project that includes a Qt header (the ubiquitous QString, probably quite a complex target), and got a segmentation fault during the generation process. Launching gdb on the program and printing the locals seems to feature the dump of an abstract syntax tree, so I guess that a parsing step succeeded, after which the generation phase failed, or something like this.

This is the C++ project I tried to wrap (usage of QString is commented out, uncomment it to try reproducing the problem):

sampleDll.tar.gz

This is the generator project file :

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="CppSharp" Version="1.1.84.17100" />
  </ItemGroup>

</Project>

And the generator implementation :

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

public class Library: ILibrary
{
    public void Setup(Driver driver)
    {
        var options = driver.Options;
        options.GeneratorKind = GeneratorKind.CSharp;

        var module = options.AddModule("Sample");
        module.IncludeDirs.Add(@"/home/___/dev/dllnetwrapper/sampleDll/");

        // From build.ninja:
        // -isystem /home/___/dev/dllnetwrapper-build/SampleDll_autogen/include -isystem /usr/include/qt6/QtCore -isystem /usr/include/qt6 -isystem /usr/lib64/qt6/mkspecs/linux-g++

        foreach (string includePath in new List<string> {
            "/home/___/dev/dllnetwrapper-build/SampleDll_autogen/include",
            "/usr/include/qt6/QtCore",
            "/usr/include/qt6",
            "/usr/lib64/qt6/mkspecs/linux-g++",
            })
        {
            module.IncludeDirs.Add(includePath);
        }

        // Those includes are needed, but they do not appear in the build.ninja file?
        // /usr/include/c++/15/x86_64-suse-linux/

        foreach (string wildIncludePath in new List<string> {
            "/usr/include/c++/15/x86_64-suse-linux/",
            })
        {
            module.IncludeDirs.Add(wildIncludePath);
        }

        module.Headers.Add("domain.h");

        module.LibraryDirs.Add(@"/home/___/dev/dllnetwrapper-build");
        module.Libraries.Add("libSampleDll.so");
    }

	public void SetupPasses(Driver driver)
    {
    }

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

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

As you can see from the above, this was run on a Linux box running OpenSUSE Tumbleweed.

Do not hesitate to ask me for more details if this can help diagnosing or fixing the issue, I wish you a good day.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions