Kakadu / lablqml

Interfacing Qt/QML with OCaml. Formely known as lablqt
http://kakadu.github.io/lablqml
GNU Lesser General Public License v2.1
159 stars 17 forks source link

Linking fails with "ld: library 'Qt5Quick' not found #69

Closed jbhoot closed 9 months ago

jbhoot commented 9 months ago

I have been able to opam install lablqml. Qt5 is installed in the system through MacPorts.

While trying to run the sample app as instructed in README, I get the following error:

zsh | ~/projects/demo_lablqml
$ ocamlfind opt -package lablqml main.ml -thread -linkpkg -cclib -lQt5Quick -cclib -lQt5Qml -cclib -lQt5Network -cclib -lQt5Widgets -cclib -lQt5Gui -cclib -lQt5Core -cclib -lstdc++ 
ld: library 'Qt5Quick' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
File "caml_startup", line 1:
Error: Error during linking (exit code 1)

I suspect that linker cannot find the location of Qt, but I don't know how to provide to it the location. Or I am wrong and there is another problem going on. Can you help?

Kakadu commented 9 months ago

It looks GNU/Linux has right paths by default, but Mac doesn't. I think, that MacPorts should install pkg-config files somewhere with Qt5. In particular, you need to find a file /usr/lib/x86_64-linux-gnu/pkgconfig/Qt5Quick.pc or something.

This file will be locate in some path and you could try to run

$ PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu pkg-config --libs-only-L Qt5Quick

In my GNU/Linux it gives and empty string (probably it is a reason why everyhting works out of box). Another useful command is

$ PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu pkg-config --libs-only-l Qt5Quick                                                        
-lQt5Quick -lQt5Gui -lQt5QmlModels -lQt5Qml -lQt5Network -lQt5Core

It is a list of libraries to link, which should be put into ocamlfind invocation with a proper amount of -ccopt switches (I hope you see the pattern).

As a final step you should run something like

$ PKG_CONFIG_PATH=<path with .pc files> ocamlfind opt -package lablqml main.ml -thread -linkpkg \
    -ccopt $(pkg-config --libs-only-L Qt5Quick)
    -cclib -lQt5Quick -cclib -lQt5Qml -cclib -lQt5Network -cclib -lQt5Widgets -cclib -lQt5Gui -cclib -lQt5Core \
    -cclib -lstdc++ 

N.B. I don't use MacOS, so my advice may be imprecise

P.S. There is a dune sample in the repo, you could try dune exec dune_test/program.exe. It should invoke pkg-config itself, if you give right PKG_CONFIG_PATH=... variable.

Kakadu commented 9 months ago

After some experiments in docker, it looks like the right command for Mac is

export PATH=/opt/local/libexec/qt5/bin:$PATH

dune b @install -p lablqml && dune install lablqml

# create right files
ocamlfind opt -package lablqml a.ml -thread -linkpkg \
                -ccopt -F/opt/local/libexec/qt5/lib -ccopt -framework -ccopt QtQuick -ccopt -framework -ccopt QtGui -ccopt -framework -ccopt QtQmlModels -ccopt -framework -ccopt QtQml -ccopt -framework -ccopt QtNetwork -ccopt -framework -ccopt QtCore \
        -ccopt -lstdc++
jbhoot commented 9 months ago

Your last suggestion works! Now on to test more complex GUIs