-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Error when cross compiling using zig cc #289
Comments
Actually, I have navigated in Nelua's internals some external libraries and have found this syntax. I have never seen this kind of syntax before. |
I think it's your bindings fault, it uses |
Also,
|
Now that you have mentioned it, I've just noticed this Can we presume it generated a 32-bit C version behind the scenes this way? To verify it we can run it with
|
With Nelua command: The result/* ------------------------------ DIRECTIVES -------------------------------- */
/* Disable some warnings that the generated code can trigger. */
#if defined(__clang__) && __clang_major__ >= 3
#pragma clang diagnostic ignored "-Wtype-limits"
#pragma clang diagnostic ignored "-Wwrite-strings"
#pragma clang diagnostic ignored "-Wunused"
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
#pragma clang diagnostic ignored "-Wparentheses-equality"
#pragma clang diagnostic ignored "-Wtautological-compare"
#pragma clang diagnostic ignored "-Wmissing-braces"
#ifndef __cplusplus
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#pragma clang diagnostic error "-Wimplicit-function-declaration"
#pragma clang diagnostic error "-Wimplicit-int"
#else
#pragma clang diagnostic ignored "-Wnarrowing"
#pragma clang diagnostic ignored "-Wc99-designator"
#endif
#elif defined(__GNUC__) && __GNUC__ >= 5
#pragma GCC diagnostic ignored "-Wtype-limits"
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-value"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#ifndef __cplusplus
#pragma GCC diagnostic ignored "-Wmissing-braces"
#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"
#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
#pragma GCC diagnostic error "-Wimplicit-function-declaration"
#pragma GCC diagnostic error "-Wimplicit-int"
#else
#pragma GCC diagnostic ignored "-Wnarrowing"
#endif
#endif
#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
#endif
/* Macro used to perform compile-time checks. */
#if __STDC_VERSION__ >= 201112L
#define NELUA_STATIC_ASSERT _Static_assert
#elif __cplusplus >= 201103L
#define NELUA_STATIC_ASSERT static_assert
#else
#define NELUA_STATIC_ASSERT(x, y)
#endif
/* Macro used to get alignment of a type. */
#if __STDC_VERSION__ >= 201112L
#define NELUA_ALIGNOF _Alignof
#elif __cplusplus >= 201103L
#define NELUA_ALIGNOF alignof
#elif defined(__GNUC__)
#define NELUA_ALIGNOF __alignof__
#elif defined(_MSC_VER)
#define NELUA_ALIGNOF __alignof
#else
#define NELUA_ALIGNOF(x)
#endif
/* Checks if Nelua and C agrees on pointer size. */
NELUA_STATIC_ASSERT(sizeof(void*) == 4 && NELUA_ALIGNOF(void*) == 4, "Nelua and C disagree on pointer size or alignment");
/* Enable 64 bit offsets for stdio APIs. */
#if !defined(_FILE_OFFSET_BITS) && __SIZEOF_LONG__ >= 8
#define _FILE_OFFSET_BITS 64
#endif
/* Enable POSIX APIs in included headers. */
#if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) && !defined(_GNU_SOURCE) && !defined(_DEFAULT_SOURCE)
#if defined(__gnu_linux__)
#define _GNU_SOURCE
#else
#define _XOPEN_SOURCE 600
#endif
#endif
#include <stdint.h>
#include <stdio.h>
/* ------------------------------ DECLARATIONS ------------------------------ */
static int64_t eval_EePzfW6tFYR_a = 9223372036854775807LL;
static void nelua_print_1(int64_t a1);
static int nelua_main(int argc, char** argv);
/* ------------------------------ DEFINITIONS ------------------------------- */
void nelua_print_1(int64_t a1) {
fprintf(stdout, "%lli", (long long)a1);
fputs("\n", stdout);
fflush(stdout);
}
int nelua_main(int argc, char** argv) {
nelua_print_1(eval_EePzfW6tFYR_a);
return 0;
}
int main(int argc, char** argv) {
return nelua_main(argc, argv);
} Note: Zig CC is basically just an LLVM Clang frontend embedded into Zig toolchain. |
Another interesting thing is that the target is listed in Zig documentation as |
|
the weirdest thing is how its still working on linux with no error using the same bindings |
For example:
|
Interesting...can you try
|
the same error
|
Seems like it throws an error as expected: On a 32-bit computer,
You are trying to assign it with a number larger than the variable type's size. To verify what I am saying, can you try:
|
Wow,that compile fine |
what output did it return? |
using wine it return
|
Very nice; it's exactly as I have suspected. You were hard coding a number larger than your 32-bit version could handle. |
yeah, but still does not compile for windows 64-bit while working fine for 64-bit linux |
What is the error message it throws? |
so i'm confused about the default behavior of the compiler, does it allow overflow at compile time or not |
You mean |
the same as i mentioned earlier |
the nelua compiler, C compilers allow that |
I think you are tired, because what you are doing is rather funny. You are HARDCODING a huge number of signed 64-bit, this part here Obviously, as we both know Do you understand now where's the issue? |
Yes i understand the issue correctly. you can try to assign this big number to an integer in C and it would compile with some overflow warnings, even for 32-bit version. |
About hardcoding, I was referring at this code:
Here it's hardcoded, obviously. About the |
seriously. |
I thought it was Zig's responsibility to emit a 64-bit windows version target output, which fails for some reason as you say, so...excuse my confusion! |
I'll need to look more in depth later, but I believe nelua is being misinformed by the compiler (in this situation of cross-compiling, since When compiling, Nelua will invoke the C compiler (like gcc, zig cc, etc) and get all the information about the C environment (like the size of types), see nelua-lang/lualib/nelua/ccompiler.lua Line 202 in a69a12d
I believe the compiler is not giving the right information to Nelua. About working on Linux but not on Windows in this case: Reading here on Cpp Reference (which also covers standard C), it's shown that
Note On the same page, on "Data models", it says that on 64-bit systems, Win64 API uses LLP64 while Unix uses LP64, where Source: https://en.cppreference.com/w/c/language/arithmetic_types TL;DR: I believe the cross-compilation to Windows on Zig CC is messing up the |
i tried to cross compile nelua code from my linux machine to windows using
zig cc
andmingw
using both these commands
for this code:
give the same error for the generated glad bindings:
a workaround for this is manually compiling the generated c code from nelua using the appropriate c compiler
nelua version:
my environment
The text was updated successfully, but these errors were encountered: