Skip to content

Error when trying to import Windows SQL headers #9120

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

Closed
mjoerussell opened this issue Jun 14, 2021 · 2 comments
Closed

Error when trying to import Windows SQL headers #9120

mjoerussell opened this issue Jun 14, 2021 · 2 comments

Comments

@mjoerussell
Copy link

Zig Version: 0.9.0-dev.140+4173a2bc2

Min Repro: On the above version of Zig, if I try to compile the following code:

const c = @cImport({
    @cInclude("windows.h");
    @cInclude("sqlext.h");
});

pub fn main() !void {
    const odbc_2 = c.SQL_OV_ODBC2;
}

I get this error:

error: unable to translate C expr: unexpected token .HashHash
pub const __MSABI_LONG = @compileError("unable to translate C expr: unexpected token .HashHash"); // C:\Users\mjoer\Code\zig\build-release\lib\zig\libc\include\any-windows-any/_mingw_mac.h:209:13
                         ^
.\zig-cache\o\255badc43fbb061efcb527c641fb4bea\cimport.zig:82622:26: note: referenced here
pub const SQL_OV_ODBC2 = __MSABI_LONG(@as(c_uint, 2));
                         ^
.\src\main.zig:10:21: note: referenced here
    const odbc_2 = c.SQL_OV_ODBC2;
                    ^
scratch...The following command exited with error code 1:
C:\Users\mjoer\Code\zig\build-release\bin\zig.exe build-exe C:\Users\mjoer\Code\tests\zig\scratch\src\main.zig -lc -lodbc32 --cache-dir C:\Users\mjoer\Code\tests\zig\scratch\zig-cache --global-cache-dir C:\Users\mjoer\AppData\Local\zig --name scratch --enable-cache
error: the following build command failed with exit code 1:
C:\Users\mjoer\Code\tests\zig\scratch\zig-cache\o\76851c19e00f699686ad20056f38b112\build.exe C:\Users\mjoer\Code\zig\build-release\bin\zig.exe C:\Users\mjoer\Code\tests\zig\scratch C:\Users\mjoer\Code\tests\zig\scratch\zig-cache C:\Users\mjoer\AppData\Local\zig run
@ehaas
Copy link
Contributor

ehaas commented Jun 15, 2021

__MSABI_LONG appears to be a macro that uses token pasting (## ). Those macros can't be directly translated to Zig.

As a workaround, you can try the following (untested):

const c = @cImport({
    @cDefine("__MSABI_LONG(x)", "(long)(x)");
    @cInclude("windows.h");
    @cInclude("sqlext.h");
});
pub fn main() !void {
    const odbc_2 = c.SQL_OV_ODBC2;
}

@mjoerussell
Copy link
Author

Thanks, that seems to fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants