Chris00 / ocaml-cairo

Binding to Cairo, a 2D Vector Graphics Library.
GNU Lesser General Public License v3.0
54 stars 8 forks source link

Version 0.6.4 cannot find pgkconf and ft2build.h #35

Open stumbles opened 1 year ago

stumbles commented 1 year ago

/usr/bin/pkgconf is present, why it's not found by which isn't clear to me. Running which pkgconf from cli and the correct path is returned.

The more puzzling part is c-test-2 and why /usr/include/cairo/cairo-ft.h says it cannot find ft2build.h. That file is present in /usr/include/freetype2/. AFAICT all the pathing is correct. As a check, I looked into for example grub2 and it finds ft2build.h with no problems.

pkgconf --cflags /usr/lib/pkgconfig/cairo-ft.pc returns; -I/usr/include/cairo -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1

pkgconf --libs /usr/lib/pkgconfig/cairo-ft.pc returns; -lcairo -lfreetype

pkgconf --cflags /usr/lib/pkgconfig/cairo-fc.pc returns; -I/usr/include/cairo -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1

pkgconf --libs /usr/lib/pkgconfig/cairo-fc.pc returns; -lcairo -lfontconfig -lfreetype

Running; dune build -p cairo2

File "src/dune", line 12, characters 0-132: 12 (rule 13 (targets c_flags.sexp c_library_flags.sexp cairo_ocaml.h) 14 (deps cairo_ocaml.h.p) 15 (action (run ../config/discover.exe))) (cd _build/default/src && ../config/discover.exe) which: /usr/bin/pkgconf -> not found compiling c program: #include #include
#define DUNE_ABS(x) ((x >= 0)? x: -(x))
#define DUNE_D0(x) ('0'+(DUNE_ABS(x)/1 )%10)
#define DUNE_D1(x) ('0'+(DUNE_ABS(x)/10 )%10), DUNE_D0(x)
#define DUNE_D2(x) ('0'+(DUNE_ABS(x)/100 )%10), DUNE_D1(x)
#define DUNE_D3(x) ('0'+(DUNE_ABS(x)/1000 )%10), DUNE_D2(x)
#define DUNE_D4(x) ('0'+(DUNE_ABS(x)/10000 )%10), DUNE_D3(x)
#define DUNE_D5(x) ('0'+(DUNE_ABS(x)/100000 )%10), DUNE_D4(x)
#define DUNE_D6(x) ('0'+(DUNE_ABS(x)/1000000 )%10), DUNE_D5(x)
#define DUNE_D7(x) ('0'+(DUNE_ABS(x)/10000000 )%10), DUNE_D6(x)
#define DUNE_D8(x) ('0'+(DUNE_ABS(x)/100000000 )%10), DUNE_D7(x)
#define DUNE_D9(x) ('0'+(DUNE_ABS(x)/1000000000)%10), DUNE_D8(x)
#define DUNE_SIGN(x) ((x >= 0)? '0': '-')
const char s0[] = {
'B', 'E', 'G', 'I', 'N', '-', '0', '-',
DUNE_SIGN((CAIRO_VERSION_MAJOR)),
DUNE_D9((CAIRO_VERSION_MAJOR)),
'-', 'E', 'N', 'D'
};
const char s1[] = {
'B', 'E', 'G', 'I', 'N', '-', '1', '-',
DUNE_SIGN((CAIRO_VERSION_MINOR)),
DUNE_D9((CAIRO_VERSION_MINOR)),
'-', 'E', 'N', 'D'
};
run: gcc -O2 -fno-strict-aliasing -fwrapv -pthread -g -fno-omit-frame-pointer -fPIC -O2 -march=native -pipe -Wp,-D_FORTIFY_SOURCE=2 -I/usr/include/cairo -I /usr/lib/ocaml -o /tmp/build_cf88f1_dune/ocaml-configuratord1e6f8/c-test-0/test.o -c /tmp/build_cf88f1_dune/ocaml-configuratord1e6f8/c-test-0/test.c -lm -lpthread -> process exited with code 0 -> stdout: -> stderr: compiling c program: #include #include
#ifdef CAIRO_HAS_FT_FONT
const char *s0 = "BEGIN-0-true-END";
#else
const char *s0 = "BEGIN-0-false-END";
#endif
#ifdef CAIRO_HAS_FC_FONT
const char *s1 = "BEGIN-1-true-END";
#else
const char *s1 = "BEGIN-1-false-END";
#endif

run: gcc -O2 -fno-strict-aliasing -fwrapv -pthread -g -fno-omit-frame-pointer -fPIC -O2 -march=native -pipe -Wp,-D_FORTIFY_SOURCE=2 -I/usr/include/cairo -I /usr/lib/ocaml -o /tmp/build_cf88f1_dune/ocaml-configuratord1e6f8/c-test-2/test.o -c /tmp/build_cf88f1_dune/ocaml-configuratord1e6f8/c-test-2/test.c -lm -lpthread -> process exited with code 1 -> stdout: -> stderr: | In file included from /tmp/build_cf88f1_dune/ocaml-configuratord1e6f8/c-test-2/test.c:2: | /usr/include/cairo/cairo-ft.h:46:10: fatal error: ft2build.h: No such file or directory | 46 | #include | | ^~~~ | compilation terminated. Error: failed to compile program

maroneze commented 1 year ago

I'm having a very similar problem, but on Cygwin. I even tried installing older versions of cairo2 (down to 0.6), but I got the same error everytime.

In my Fedora, I have no issues with the installation, but when I try it on Cygwin I get the same error, but with a different command line:

 x86_64-w64-mingw32-gcc -O2 -fno-strict-aliasing -fwrapv -mms-bitfields   -I/usr/include/cairo 
  -I C:/OCaml64/home/user/.opam/4.14.0+mingw64c/lib/ocaml
  -o C:\OCaml64\tmp\build_b20be0_dune\ocaml-configurator26b3b6\c-test-2\test.o 
  -c C:\OCaml64\tmp\build_b20be0_dune\ocaml-configurator26b3b6\c-test-2\test.c -lws2_32 -lversion
-> process exited with code 1
-> stdout:
-> stderr:
 | In file included from C:\OCaml64\tmp\build_b20be0_dune\ocaml-configurator26b3b6\c-test-2\test.c:2:
 | /usr/include/cairo/cairo-ft.h:46:10: fatal error: ft2build.h: No such file or directory
 |    46 | #include <ft2build.h>
 |       |          ^~~~~~~~~~~~
 | compilation terminated.

I did manage to install cairo2 on previous Cygwin setups, so I don't know if my Cygwin changed versions, or if I had different installed packages.

Actually, the beginning of the compilation message hints to pkg-config not being found:

$ (cd _build/default/src && ../config/discover.exe)
which: pkg-config
-> not found
compiling c program:
...

But it is there in my Cygwin (in /usr/bin, which is C:\OCaml64\bin). I suspect some environment issue when the discover.exe executable is launched, but when I had some similar issues with other packages, setting my PATH variable was enough to make it work. Not in this case...

Anyway, I'm adding this in case this helps tracking down the cause. Even if it is possible that the cause of my issue is unrelated to @stumbles' (with the same symptoms).

I found this open issue related to dune-configurator which seems suspiciously similar, but it seems limited to Windows builds, so probably unrelated to @stumbles' actual issue.

stumbles commented 1 year ago

@maroneze, same here about not finding pkgconf even though the pathing is correct, else I would have seen tons of other apps failing to compile.

maroneze commented 9 months ago

Ok, after seeing this for the first time, I tried checking my C:\OCaml64\bin folder (mapped to /usr/bin in Cygwin), and I noticed the pkg-config file inside it was a symlink to pkgconf.exe. Since I already had several issues with symlinks in Cygwin/MinGW, I erased it and copied pkgconf.exe as pkg-config.exe. Then re-running opam install cairo worked.

I didn't need this in the past (I was able to compile cairo2 without issues), but for some reason now I do.

maroneze commented 9 months ago

For future reference (for me and others): something is still not 100% right in my Cygwin+MinGW setting, because even if I could install cairo2, I then had issues with lablgtk3. I finally managed to get it working by running:

(export PKG_CONFIG_PATH="C:\OCaml64\usr\x86_64-w64-mingw32\sys-root\mingw\lib\pkgconfig" && opam install lablgtk3)

But the fact that I had to manually set my PKG_CONFIG_PATH (besides having installed Cygwin's mingw-based gtk3 packages) indicates that maybe something is not entirely right in my solution.

stumbles commented 9 months ago

On a side note, here is my current pkgconf pathing;

PKG_CONFIG_PATH=/usr/lib/qt6/pkgconfig:/usr/lib/qt5/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig: PKG_CONFIG=/usr/bin/pkgconf

Also here are the cairo related package configs installed by cairo on my system;

/usr/lib/pkgconfig/cairo-fc.pc /usr/lib/pkgconfig/cairo-ft.pc /usr/lib/pkgconfig/cairo-gobject.pc /usr/lib/pkgconfig/cairo.pc /usr/lib/pkgconfig/cairo-pdf.pc /usr/lib/pkgconfig/cairo-png.pc /usr/lib/pkgconfig/cairo-ps.pc /usr/lib/pkgconfig/cairo-script-interpreter.pc /usr/lib/pkgconfig/cairo-script.pc /usr/lib/pkgconfig/cairo-svg.pc /usr/lib/pkgconfig/cairo-tee.pc /usr/lib/pkgconfig/cairo-xcb.pc /usr/lib/pkgconfig/cairo-xcb-shm.pc /usr/lib/pkgconfig/cairo-xlib.pc /usr/lib/pkgconfig/cairo-xlib-xcb.pc /usr/lib/pkgconfig/cairo-xlib-xrender.pc

Is there some subtle bug in discover.ml I'm tripping over?

stumbles commented 1 month ago

Still a bit clueless what's going on here.

Line 15 in my OP;

15 | (action (run ../config/discover.exe))) (cd _build/default/src && ../config/discover.exe)

tries to run discover.exe.

Well this is a linux box, not windows. Why is it not trying to run ../config/discover.ml? Just to be clear there are no *.exe files.

Or is that a red herring?

maroneze commented 1 month ago

I'm unable to reproduce any errors on Linux; with Fedora 40, after installing dependencies such as gtk2-devel and lablgtk, dune build just works.

Notice that, despite the unusual usage of .exe even on non-Windows systems, as mentioned here:

Note that native code executables will have the .exe extension on all platforms (including non-Windows systems).

Dune will build the .exe by itself according to the corresponding .ml. So that does not seem to be an issue, in my opinion.

By the way, my _build/default/config directory does contain a discover.exe file compiled by Dune. You can even try running dune build _build/default/config/discover.exe by itself to see if your Dune is able to compile it from the .ml file.

stumbles commented 1 month ago

I'm unable to reproduce any errors on Linux; with Fedora 40, after installing dependencies such as gtk2-devel and lablgtk, dune build just works.

Notice that, despite the unusual usage of .exe even on non-Windows systems, as mentioned here:

Note that native code executables will have the .exe extension on all platforms (including non-Windows systems).

Dune will build the .exe by itself according to the corresponding .ml. So that does not seem to be an issue, in my opinion.

By the way, my _build/default/config directory does contain a discover.exe file compiled by Dune. You can even try running dune build _build/default/config/discover.exe by itself to see if your Dune is able to compile it from the .ml file.

OK.

So I do not know why dune is not creating discover.exe. Here is how I'm building dune;

`_dune_release_pkgs=('dune' 'dune-action-plugin' 'dune-build-info' 'dune-configurator' 'dune-glob' 'dune-private-libs' 'dune-site' 'dune-rpc' 'dyn' 'stdune' 'ordering' 'xdg' 'chrome-trace' 'ocamlc-loc')

_opts+=" --libdir=/usr/lib/ocaml \ --mandir=/usr/share/man \ --datadir=/usr/share \ --docdir=/usr/share/doc \ --sbindir=/usr/bin \ --etcdir=/etc \ --bindir=/usr/bin"

./configure $_opts && make _boot/dune.exe &&

ocaml boot/bootstrap.ml &&

local dune_release_pkgs='dummy' && for _pkg in "${_dune_release_pkgs[@]}"; do dune_release_pkgs+=",${_pkg}" done dune_release_pkgs="${dune_release_pkgs#dummy,}" echo "Building packages: ${dune_release_pkgs}"

./dune.exe build -p "${dune_release_pkgs}" --profile dune-bootstrap &&

prepare_install &&

for _pkg in "${_dune_release_pkgs[@]}"; do ./dune.exe install "${_pkg}" $_opts done `

maroneze commented 1 month ago

What OS and architecture are you using? I think they might be relevant.

I personally never compiled Dune directly, I always installed it via opam (opam install dune).

stumbles commented 1 month ago

The OS is lunar-linux (source based), 12 × Intel® Core™ i7 CPU X 980 @ 3.33GHz.

I tried "opam install dune" but it said opam was not initialized and I stopped at that point.

maroneze commented 1 month ago

I still believe trying to use opam would be beneficial in the long run, it's nowadays the "standard" way to install most things in OCaml, and I'd not even considered using Dune without it (I started using opam long before Dune existed). Yes, the initial setup requires some thought (especially choosing the right compiler version, if it matters for the packages you need), but it should hopefully avoid issues in the future such as the one you are having with ocaml-cairo.

Ideally, opam init --comp 4.14.1 should give you a not-too-old compiler ; eval $(opam env) should then set the proper environment variables, and opam install cairo2 should work. You will likely need to manually install some OS packages (e.g. gtk for lablgtk), since lunar-linux probably uses its specific packages, but it should be easier to understand the errors with them.

But then again, I have never heard of it, so it's not impossible that there will still be issues with ocaml-cairo...