Skip to content
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

OCamlSDL2 fails to build and install (opam) on Windows, cygwin #31

Closed
jarmuszz opened this issue May 12, 2022 · 6 comments
Closed

OCamlSDL2 fails to build and install (opam) on Windows, cygwin #31

jarmuszz opened this issue May 12, 2022 · 6 comments

Comments

@jarmuszz
Copy link

Building on windows fails with "The system cannot find the path specified." (check the log.txt file. I translated the error message here in the issue as the original one in the logfile is in polish).

As the result, opam's CI system automatically prohibited this package from installing on win32:
opam install ocamlsdl2
results with
[ERROR] ocamlsdl2 unmet availability conditions, e.g. os != "win32"

Details:

  • ocamlc --version : 4.11.0
  • sdl2-config --version : 2.0.22
  • winver : Windows Server 1809
  • virtualization: vbox

This is the only spare virt machine on which I could test it on. I'd be glad if anyone would test this on other windows versions.

@jarmuszz jarmuszz changed the title OCamlSDL2 fails to build and install on Windows, cygwin OCamlSDL2 fails to build and install (opam) on Windows, cygwin May 12, 2022
@fccm
Copy link
Owner

fccm commented May 14, 2022

(You can set the English language with LANG=en)

Have you check what is the path for the headers?

@fccm
Copy link
Owner

fccm commented May 15, 2022

In the command line that produced the error the path for headers is /usr/include/SDL2.
Did you check if the headers for SDL2 are there?
This is usually the standard path for a C lib, but it can also be /usr/local/include for libs installed from sources.
Do you know what is the path where the headers for SDL2 have been installed on your system?

Header files in the C programming language are files with *.h file extension.
A C lib always provide header files like this. This is the equivalence of *.mli files of ocaml. In OCaml we call it signature files or interface files, but in C we call it header files.

In both C with gcc and OCaml this path is provided by -I as you can see in the log file you provided.

@jarmuszz
Copy link
Author

jarmuszz commented May 16, 2022

SDL headers are present in /usr/include/SDL2. Moreover,

#include <SDL2/SDL.h>
int
main(int argc, char *argv[])
{
        SDL_Init(SDL_INIT_VIDEO);
        SDL_Window *win = SDL_CreateWindow("foobar",
                        SDL_WINDOWPOS_UNDEFINED,
                        SDL_WINDOWPOS_UNDEFINED,
                        200, 200,
                        SDL_WINDOW_SHOWN);

        SDL_Delay(500);
        SDL_Quit();
}

compiles and runs fine with
x86_64-w64-mingw32-gcc main.c -I /usr/include/ -L /usr/lib -lmingw32 -lSDL2main -lSDL2 -mwindows

Interestingly, the x86_64-w64-mingw32-gcc binary doesn't seem to include nor link the "standard" directories such as /usr/lib and /usr/include.

I also noticed that the command that errors out uses the i686 gcc instead of the x86_64.

I tried to "extract" a c compiler command from the ocamlc line that fails to get a more in-depth error message but I was not able to reach anything worth mentioning.

Also, I think it's worth to mention that this is a windows's error message, not a cygwin/posix one.

@fccm
Copy link
Owner

fccm commented May 18, 2022

In the logs you provided, the command line was:
ocamlc -cc "c:/cygwin/bin/i686-w64-mingw32-gcc.exe -g -Wall -Werror" -ccopt "-static -I/usr/include/SDL2 -Dmain=SDL_main -g -O " sdlinit_stub.c
If your test in pure C does work, you can just put the same arguments.
You can replace gcc-32bits by gcc-64bit if you want.
You can see that the -cc command provides the gcc command.
You can probably remove -Wall and -Werror (kitykate already told me I should remove it from a release)
You can also remove -static if this is not a static version that you want, or if the SDL2 that you installed don't include the static version.
If you want to see what is the command line run by ocamlopt and ocamlc the argument is -verbose.
In the ocamlc call the argument -ccopt are the arguements that will be provided to the C compiler.

If this one works:
x86_64-w64-mingw32-gcc main.c -I /usr/include/ -L /usr/lib -lmingw32 -lSDL2main -lSDL2 -mwindows

You could try:
ocamlc -verbose -cc "x86_64-w64-mingw32-gcc" -ccopt "-I /usr/include/SDL2 -I /usr/include -L /usr/lib -lmingw32 -lSDL2main -lSDL2 -mwindows -Dmain=SDL_main -g -O " sdlinit_stub.c

(If you want to share a mini-game on the internet (for example on Itch.io), there are still people using old 32bit computers. If you compile for 64bit they will not be able to run your game. If you compile for 32bit, people with 64bit computers will be able to run your game fine.)

@fccm
Copy link
Owner

fccm commented May 18, 2022

Hi again, I just see on your page that you know some assembly, you may be interested to have a look at the assembly created by ocamlopt with -S:

echo 'print_endline "Hello"' > h.ml
ocamlopt -S -o h.opt h.ml
cat h.s

@jarmuszz
Copy link
Author

I feel kinda dumb now. I forgot that the Makefile.config file has to be created by hand, not generated by the main Makefile and so I was placing all of my fixes in Makefile.config.win32 wondering why won't they work... 🥲

The only change that has to be made to build successfully on windows is removing the -Werror (as you said above).

BTW thanks for all of this info, it surely will help me later :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants