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

libssh error #5022

Closed
omarpta opened this issue Apr 13, 2020 · 2 comments
Closed

libssh error #5022

omarpta opened this issue Apr 13, 2020 · 2 comments
Labels
translate-c C to Zig source translation feature (@cImport)

Comments

@omarpta
Copy link

omarpta commented Apr 13, 2020

Hi,
I'm trying to use libssh with zig on windows.
I installed the libssh using vcpkg with VS 2017 and here is my code:

const std = @import("std");
const ssh = @cImport(@cInclude("libssh/libssh.h"));

pub fn main() anyerror!void {
    var ssh_session: ?ssh.ssh_session = undefined;
    std.debug.warn("Hello\n", .{});
}

build.zig

const Builder = @import("std").build.Builder;

pub fn build(b: *Builder) void {
    // Standard target options allows the person running `zig build` to choose
    // what target to build for. Here we do not override the defaults, which
    // means any target is allowed, and the default is native. Other options
    // for restricting supported target set are available.
    const target = b.standardTargetOptions(.{});

    // Standard release options allow the person running `zig build` to select
    // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
    const mode = b.standardReleaseOptions();

    const exe = b.addExecutable("claro-oss", "src/main.zig");
    exe.addIncludeDir("C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17763.0\\ucrt");
    exe.addIncludeDir("C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17763.0\\um");
    exe.addIncludeDir("C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17763.0\\shared");
    exe.addIncludeDir("C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include");
    exe.addIncludeDir("C:\\Users\\omar\\github\\vcpkg\\installed\\x64-windows\\include");
    exe.addLibPath("C:\\Users\\omar\\github\\vcpkg\\installed\\x64-windows\\lib");
    exe.linkSystemLibrary("libssh");
    exe.setTarget(target);
    exe.setBuildMode(mode);
    exe.install();

    const run_cmd = exe.run();
    run_cmd.step.dependOn(b.getInstallStep());

    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);
}

And i'm facing the following error:

$ zig build run
C:\omarpta\d\zig\test-libssh\zig-cache\o\1yV0RcuP5JPtGCT660okV45ANMYA5yMQIWX-xAABD7zIB0nu5fsWfmbWjq3v3tzM\cimport.zig:7277:1: error: expected token ';', found 'pub'
pub const NtCurrentTeb = @compileError("unable to translate function"); // C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\winnt.h:22421:1
^
test-libssh...The following command exited with error code 1:
C:\tools\zig\zig.exe build-exe C:\omarpta\d\zig\test-libssh\src\main.zig --library libssh --cache-dir C:\omarpta\d\zig\test-libssh\zig-cache --name test-libssh -I C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt -I C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um -I C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared -I C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include -I C:\Users\omar\github\vcpkg\installed\x64-windows\include -L C:\Users\omar\github\vcpkg\installed\x64-windows\lib --cache on

Build failed. The following command failed:
C:\omarpta\d\zig\test-libssh\zig-cache\o\Y9DY3LGEk0--pEOQN9ep1b_ilumvcgDzYcl68iSZHWAIcHxTDlI1t06RyUI5wfGh\build.exe C:\tools\zig\zig.exe C:\omarpta\d\zig\test-libssh C:\omarpta\d\zig\test-libssh\zig-cache run

When i open the zig-cache file which has the error i can see that zig "forgot" to put semicolon in this line:

...
pub const GetCurrentFiber = @compileError("unable to translate function")  <------
pub const NtCurrentTeb = @compileError("unable to translate function"); // C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um\winnt.h:22421:1
...

Is it a bug from zig or am i doing something wrong?
Thanks in advance!

@haoyu234
Copy link

I searched for other issues related to this:

  1. Generated @compileError missing semicolon
  2. Successfully @cImport("Windows.h")

It seems that translate-c cannot handle windows.h yet

@omarpta
Copy link
Author

omarpta commented Apr 13, 2020

Thanks!

@daurnimator daurnimator added duplicate translate-c C to Zig source translation feature (@cImport) labels Apr 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
translate-c C to Zig source translation feature (@cImport)
Projects
None yet
Development

No branches or pull requests

3 participants