Closed MadIcecream closed 5 years ago
Would you mind checking C:/Users/madic/scoop/apps/gcc/current/x86_64-w64-mingw32/include/psdk_inc/intrin-impl.h and posting the statement that includes line 835?
These parser failures happen occasionally and sometimes there's a workaround. The best fix is probably for me to migrate off of language-c and onto libclang for parsing C headers.
Sure intrin-impl.h.txt
I'll try this out later, but I'm wondering if this is because __int64
isn't defined in mingw, which might require you to explicitly include "_mingw.h";
before including SDL.
https://github.com/haskell/c2hs/issues/199#issue-296630197
using the version of mingw specified in the issue linked above seems to fix it. However, now I seem to get this error, which I don't know how to solve:
F:\kit-test>kitc hello.kit -I . -o hello
[2019-04-08 12:59:03.9567] ===> parsing and building module graph
[2019-04-08 12:59:03.9768] ===> processing C includes
[2019-04-08 12:59:04.8488] ===> expanding macros
[2019-04-08 12:59:04.8508] ===> resolving module types
----------------------------------------
Error: :0: Duplicate declaration for `main` in hello;
First declaration:
Second declaration:
@.\hello.kit:4:1-13
4 function main() {
^^^^^^^^^^^^^
Function, variable, type and trait names must be unique within the same namespac
e.
[2019-04-08 12:59:04.8598] ERR: compilation failed (1 errors)
This can happen if you name your main module "main.kit". It's a known issue. Try renaming it to something else.
It was already named hello.kit when I got the error.
Wonder if this due to a naming conflict with SDL2's main
function?
Wonder if this due to a naming conflict with SDL2's
main
function?
Possible. Does the kit SDL example work in linux? If so, maybe it is an issue with SDL providing an WinMain.
You should be using main() instead of WinMain() even though you are creating a Windows application, because SDL provides a version of WinMain() which performs some SDL initialization before calling your main code. If for some reason you need to use WinMain(), take a look at the SDL source code in src/main/win32/SDL_main.c to see what kind of initialization you need to do in your WinMain() function so that SDL works properly.
You can stop SDL2 from handling the main if you define SDL_MAIN_HANDLED .
#define SDL_MAIN_HANDLED
#include "SDL.h"
int main(int argc, char *argv[])
{
SDL_SetMainReady();
SDL_Init(SDL_INIT_VIDEO);
...
SDL_Quit();
return 0;
}
Is it possible to do that in kit?
That makes sense. You can define flags in Kit via the command line: -DSDL_MAIN_HANDLED
yup, now it works with setting SDL_MAIN_HANDLED and calling SDL_SetMainReady before SDL_Init. just needed to link the sdl libs using -c-L[SDL2 libs dir] and put the .dll in the directory.
include "SDL2/SDL.h" => "SDL2";
include "stdio.h";
function main() {
SDL_SetMainReady();
var window: Ptr[SDL_Window] = null;
var screenSurface: Ptr[SDL_Surface] = null;
if SDL_Init(SDL_INIT_VIDEO) < 0 {
panic("could not initialize sdl2: %s\n", SDL_GetError());
}
window = SDL_CreateWindow(
"Hello from Kit and SDL2",
${SDL_WINDOWPOS_UNDEFINED: Int}, ${SDL_WINDOWPOS_UNDEFINED: Int},
640, 480,
SDL_WINDOW_SHOWN as Uint
);
if window == null {
panic("could not create window: %s\n", SDL_GetError());
}
screenSurface = SDL_GetWindowSurface(window);
SDL_FillRect(screenSurface, null, SDL_MapRGB(screenSurface.format, 0x80, 0xff, 0xe6));
SDL_UpdateWindowSurface(window);
SDL_Delay(2000);
SDL_DestroyWindow(window);
SDL_Quit();
}
F:\kit-test>kitc hello.kit -I. -DSDL_MAIN_HANDLED -c-L"F:\SDL2-2.0.9\x86_64-w64-mingw32\lib"
[2019-04-17 14:06:25.8484] ===> parsing and building module graph
[2019-04-17 14:06:25.8684] ===> processing C includes
[2019-04-17 14:06:26.7465] ===> expanding macros
[2019-04-17 14:06:26.7485] ===> resolving module types
[2019-04-17 14:06:26.7555] ===> flattening trait implementations
[2019-04-17 14:06:26.7575] ===> typing module content
[2019-04-17 14:06:26.7975] ===> generating intermediate representation
[2019-04-17 14:06:26.8075] ===> generating code
[2019-04-17 14:06:26.8395] ===> compiling
[2019-04-17 14:06:28.5606] ===> linking
[2019-04-17 14:06:28.6196] ===> finished; total time: 2.7711585s
Glad it's working, I'll close this for now. I'm also planning to add a way to set the entry point function's name, since some platforms don't use main
- that would be another way to resolve this.
Describe the problem. What did you see? What did you expect to see?
When I tried to compile a simple sdl2 hello-world, the compiler gave me an error.
If this is a code issue, provide a minimal code example:
It's just a line of SDL_Init
Environment