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

Cannot use libssh/callbacks.h: unable to translate C expr: unexpected token 'do' #19868

Open
michidk opened this issue May 5, 2024 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@michidk
Copy link

michidk commented May 5, 2024

Zig Version

0.12.0

Steps to Reproduce and Observed Behavior

const libssh = @cImport({
    @cInclude("libssh/libssh.h");
    @cInclude("libssh/server.h");
    @cInclude("libssh/callbacks.h");
});

pub fn main() !void {
	  var callbacks = libssh.ssh_callbacks_init{};
}

Gives the following error:

/workspaces/zig-test/zig-cache/o/dc3e989fc7e6dea02d804f0d1ced5863/cimport.zig:1994:32: error: unable to translate C expr: unexpected token 'do'
pub const ssh_callbacks_init = @compileError("unable to translate C expr: unexpected token 'do'"); // /usr/include/libssh/callbacks.h:420:9

Expected Behavior

Code compiles.

@michidk michidk added the bug Observed behavior contradicts documented or intended behavior label May 5, 2024
@dermetfan
Copy link

Quick workaround:

const c = struct {
    pub usingnamespace @cImport({
        @cInclude("libssh/libssh.h");
        @cInclude("libssh/server.h");
        @cInclude("libssh/callbacks.h");
    });

    // manually translated snippets
    pub const ssh = struct {
        pub fn callbacks_init(p: anytype) void {
            p.size = @sizeOf(@TypeOf(p.*));
        }
    };
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants