How to compile c files generated by HashLink

Hello everyone, i followed this tutorial to generate C files with HashLink:
I’m trying to compile the C files by using gcc main.c -I. but i’m getting multiple ‘use of undeclared identifiers’ errors, what include am i missing?`
Thanks in advance

1 Like

I found this by digging though the discord:

Heaps does not compile to HXCPP :slight_smile: You need either hldx (For DirectX backend) or hlsdl (for SDL2). And -hl bytecode.hl or -hl csource/main.c For development purposes you safely can use bytecode, as it’s faster than compiling C sources, and if you need to share executable with someone, you’ll have to compile sources manually, there’s currently no automatic compilation. (For windows I have a tool that makes it somewhat easier - ) @Violetas



A Hashlink tool to compile hlc output. Contribute to Yanrishatum/HLCC development by creating an account on GitHub.

You also can try to use lime as a backend, but it is not officially supported and may or may not work, but hey, it compiles to HXCPP. :wink:

If you’ll look at how HLCC compiles c sources, you can see that it’s pretty straightforward to do. Can’t say what exact flags you need to provide to gcc, but here’s the list:

  • Point it to generated source files (For cl.exe: -I)
  • Also point it to hashlink/include folder (For cl.exe: -I)
  • Specify output executable, obviously ;​)
  • Add all referenced libraries that are used by sources. You can look them up in generated hlc.json file. Those libraries should be already present in your hashlink installation.

So, for cl.exe, command would look like that:
cl.exe /Ox /Fo app /Fe app.exe -I hashlink/include -I csrc app.c hashlink/ssl.lib hashlink/ui.lib hashlink/directx.lib hashlink/openal.lib hashlink/fmt.lib hashlink/libhl.lib
With app being your main file. Note that std library in reality should be libhl

I tried that but now i’m getting a 'hlc.h': No such file or directory, this header file doesn’t even exist in the generated folder. How can i include it?

This header file present in the hashlink install directory inside include subfolder. (It contains hl.h, hlc.h and hlc_main.c)
As example, for me it’s E:/HaxeToolkit/hl/include. See second point of the list above. In example command, hashlink folder supposed to point to hashlink path on your system.

Ok, thanks for the help.
I’m not the first one to have this problem, if anyone else is having problems to compile check this step by step here:

Tried all and every options found by google to compile on windows 10 to no avail. Can someone point me to the right direction? I was trying gcc from powershell. however I link, include etc, the error is the same

Reading the log, I’d say that hl lib is not provided to the linker.

1 Like

Thank you for your response. I’ve managed to build the ‘hello world’ project on windows 10 using the Developer Command Prompt for VS2017 and this command:

cl out/out.c /Fetest.exe -I out -I heaps/include /link /LIBPATH:C:/git/heaps-sandbox/heaps hl.lib libhl.lib directx.lib openal.lib fmt.lib ui.lib

However when I run the exe i get a command prompt looking window with the exe filename as title and the application opens in a separate window. Is this intended?

Well i have left for quite a long time windows, but i remember that you can change the subsystem used.

But i you chose windows instead of console, you may have to adapt some things in the main declaration of C source (may be it can be asked to hl when generating ? I don’t know).
The adaptation shouldn’t be a big deal , though. May be a MS-Windows connaisseur lurking around could say more :slight_smile:

Alternatively you can call hl.UI.closeConsole() at startup

1 Like

That’s what I do for the Visual Studio 2019 hlc build:

Set subsystem to windows and remove the _CONSOLE define.
Also use this in hlc_main.c:

#    ifndef _CONSOLE
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    return wmain(__argc, __wargv);
#    endif
int wmain(int argc, uchar *argv[]) {
#    ifndef _CONSOLE
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    return main(__argc, __argv);
#    endif
int main(int argc, char *argv[]) {

Have fun :wink: