hashlink icon indicating copy to clipboard operation
hashlink copied to clipboard

Unable to build C output on Windows gcc

Open pkhead opened this issue 1 year ago • 2 comments

I have compiled some code from Haxe to C, but I am unable to build it on Windows using gcc. I am using gcc installed from MSYS2's mingw-w64-x86_64-gcc package.

This is my test code:

class Main {
    static function main() {
        trace("Hello, world!");
    }
}

This is my build.hxml:

--class-path src
--main Main
--hl out/hlc/main.c

And this is the error I get:

gcc -std=c11 -c out/hlc/main.c -o out/bin/test.o -I out/hlc -I/c/Users/nabca/Documents/src/hashlink/x64/Debug/../../src
In file included from out/hlc/main.c:6:
C:/Users/nabca/Documents/src/hashlink/src/hlc_main.c: In function 'WinMain':
C:/Users/nabca/Documents/src/hashlink/src/hlc_main.c:133:16: error: implicit declaration of function 'wmain' [-Wimplicit-function-declaration]
  133 |         return wmain(__argc, __argv);
      |                ^~~~~

I did notice that if I modify hlc_main.c so that the WinMain and wWinMain functions are defined after wmain and main, as well as change the parameters of wmain to int argc, char *argv[] instead of int argc, uchar *argv[], the code will be able to compile successfully.

pkhead avatar May 26 '24 02:05 pkhead

Yes, this is common. But this post solved all my build problems with hl/c :

https://joshblog.net/2024/openfl-devlog-hashlink-c-compilation/

Huge thanks to @joshtynjala Josh Tynjala for this great deep dive and problem solution. It should be in the wiki!

datee avatar May 26 '24 14:05 datee

That's the post I followed while I was trying to figure out how to get it to build.

I'd like to point out that the only reason I couldn't build it was because there was an easily fixable implicit function declaration in hlc_main.c that gcc interpreted as an error.

pkhead avatar May 30 '24 15:05 pkhead

MSVC also warns about this:

...\src\hlc_main.c(133,14): warning C4013: 'wmain' undefined; assuming extern returning int

tobil4sk avatar Sep 01 '24 11:09 tobil4sk

Once that is resolved, this error comes up next:

In file included from run.c:6:
.../HASHLINK/include/hlc_main.c: In function 'WinMain':
.../HASHLINK/include/hlc_main.c:167:30: error: passing argument 2 of 'wmain' from incompatible pointer type [-Wincompatible-pointer-types]
  167 |         return wmain(__argc, __argv);
      |                              ^~~~~~
      |                              |
      |                              char **
.../HASHLINK/include/hlc_main.c:132:28: note: expected 'uchar **' {aka 'short unsigned int **'} but argument is of type 'char **'
  132 | int wmain(int argc, uchar *argv[]) {
      |                     ~~~~~~~^~~~~~

Which is reported similarly by MSVC:

...\src\hlc_main.c(167,29): warning C4133: 'function': incompatible types - from 'char **' to 'uchar **'

The error can be resolved by changing to __wargv

tobil4sk avatar Sep 01 '24 11:09 tobil4sk