Compile Problem HL/C
Haxe Code: https://github.com/boorik/smartfox-haxe-client/blob/d7a10b57dc389bef19eab7508480cbd9df4739d4/com/smartfoxserver/v2/SmartFox.hx#L939
https://github.com/boorik/smartfox-haxe-client/blob/d7a10b57dc389bef19eab7508480cbd9df4739d4/com/smartfoxserver/v2/core/SFSEvent.hx#L54
C Output:
r13 = (com__smartfoxserver__v2__core__$SFSEvent)g$da560e3;
r7 = r13->HANDSHAKE;
Error:
Export/hl/obj\com/smartfoxserver/v2/SmartFox.c(351): error C2037: left of 'HANDSHAKE' specifies undefined struct/union '_com__smartfoxserver__v2__core__$SFSEvent'
Could you provide a minimal example?
Could you provide a minimal example?
The library link is already above.
@barisyild Does this still reproduce for you? I have tried with haxe 4.3.6, 4.3.7 and 5.0.0-preview.1 and couldn't reproduce this error. For me, the HANDSHAKE string is correctly inlined:
r2 = (String)s$handshake;
@barisyild Does this still reproduce for you? I have tried with haxe 4.3.6, 4.3.7 and 5.0.0-preview.1 and couldn't reproduce this error. For me, the
HANDSHAKEstring is correctly inlined:r2 = (String)s$handshake;
What is your os, i tried with windows.
I'm also testing this on windows 11
Also i can't reproduce, probably fixed.
@barisyild Actually, the reason I wasn't able to reproduce was due to -dce full. If I remove that, I am able to reproduce it:
class Main {
public static inline var HANDSHAKE:String = "HANDSHAKE";
public static inline var SOCKET_ERROR:String = "SOCKET_ERROR";
static function main() {
trace(Main.HANDSHAKE);
trace(Main.SOCKET_ERROR);
}
}
--dce no
-cp src
-D analyzer-optimize
-main Main
--hl bin/main.c
-D hlgen.makefile=vs2019
Code generated in bin/main.c
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" main.sln -t:main -nologo -verbosity:minimal -property:Configuration=Release -property:Platform=x64
main.c
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.h(19,9): error C2059: syntax error: '-' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.h(21,1): error C2059: syntax error: '}' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\hl\init.c(359,7): error C2037: left of 'HANDSHAKE' specifies undefined struct/union '_$Main' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\hl\init.c(362,7): error C2059: syntax error: '(' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\hl\init.c(364,13): error C2275: '$Std': illegal use of this type as an expression [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Std.h(4): message : see declaration of '$Std' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\hl\init.c(364,14): error C2146: syntax error: missing ';' before identifier 'g$_Std' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
The problem is that SOCKET_ERROR is defined in winsock.h to -1, which causes a syntax error when SOCKET_ERROR is generated in hl/c code. winsock.h is included via windows.h in hl.h, see: https://github.com/HaxeFoundation/hashlink/blob/4a8e055a0954b2fd26e48314e4952f1afd31078d/src/hl.h#L235
Maybe it would be possible for hl.h to avoid including windows.h, or perhaps it could define WIN32_LEAN_AND_MEAN before including it.
#804 should solve this particular case, for both jumbo builds and regular builds. It removes the windows.h include in hl.h which fixes the error for non-jumbo builds, and when hlc_main.c includes it (all source files are #included together in a jumbo build), it now uses WIN32_LEAN_AND_MEAN which prevents it from defining SOCKET_ERROR.
However, some other windows macros can still break user code in jumbo builds. Here is an example:
class Main {
static final near = "near";
static function main() {
trace(Main.near);
}
}
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.h(18,13): error C2208: '_String *': no members defined using this type [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(28,15): error C2059: syntax error: ';' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(30,14): error C2275: 'String': illegal use of this type as an expression [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\String.h(5): message : see declaration of 'String' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(30,15): error C2146: syntax error: missing ';' before identifier 's$src_Main_hx' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(31,23): error C2275: 'vdynamic': illegal use of this type as an expression [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
C:\HaxeToolkit\hashlink\include\hl.h(491): message : see declaration of 'vdynamic' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(31,24): error C2059: syntax error: ')' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(33,23): error C2275: 'vdynamic': illegal use of this type as an expression [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
C:\HaxeToolkit\hashlink\include\hl.h(491): message : see declaration of 'vdynamic' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(33,24): error C2059: syntax error: ')' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(34,14): error C2275: 'String': illegal use of this type as an expression [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\String.h(5): message : see declaration of 'String' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(34,15): error C2146: syntax error: missing ';' before identifier 's$Main' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(35,23): error C2275: 'vdynamic': illegal use of this type as an expression [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
C:\HaxeToolkit\hashlink\include\hl.h(491): message : see declaration of 'vdynamic' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(35,24): error C2059: syntax error: ')' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(36,14): error C2275: 'String': illegal use of this type as an expression [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\String.h(5): message : see declaration of 'String' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(36,15): error C2146: syntax error: missing ';' before identifier 's$main' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(37,23): error C2275: 'vdynamic': illegal use of this type as an expression [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
C:\HaxeToolkit\hashlink\include\hl.h(491): message : see declaration of 'vdynamic' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(37,24): error C2059: syntax error: ')' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(38,45): error C2275: 'vdynamic': illegal use of this type as an expression [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
C:\HaxeToolkit\hashlink\include\hl.h(491): message : see declaration of 'vdynamic' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Main.c(38,46): error C2059: syntax error: ')' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\hl\init.c(840,12): error C2059: syntax error: '=' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\hl\init.c(842,13): error C2275: '$Std': illegal use of this type as an expression [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\_std\Std.h(4): message : see declaration of '$Std' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
D:\Dev\Haxe\tests\hlc-test\bin\hl\init.c(842,14): error C2146: syntax error: missing ';' before identifier 'g$_Std' [D:\Dev\Haxe\tests\hlc-test\bin\main.vcxproj]
I think the simplest way to fix this is for haxe to generate #include hlc_main.c underneath all the other source file includes, which means windows.h won't be included above the other source files. See: https://github.com/HaxeFoundation/haxe/pull/12335
Fixed by #804 and test in https://github.com/HaxeFoundation/hashlink/commit/6352d47aba2edc97e107f9621c69b94cb3c1ad49