From 5afa94f2cc48eb54406c0cf3b52b5ec311cf9ed2 Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 20 Oct 2024 17:56:37 +1300 Subject: [PATCH] doc/pkg-config: add instructions about custom pkg-config files --- .gitignore | 3 +++ pkg-config/README.md | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 pkg-config/README.md diff --git a/.gitignore b/.gitignore index 40db9c24..2386f3a3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,9 @@ container-build-cache/ # local genbindings configuration cmd/genbindings/genbindings.local* +# local pkg-config configuration +pkg-config/*.pc + # binaries cmd/handbindings/handbindings cmd/handbindings/bindings_test/direct diff --git a/pkg-config/README.md b/pkg-config/README.md new file mode 100644 index 00000000..e26e0317 --- /dev/null +++ b/pkg-config/README.md @@ -0,0 +1,27 @@ +# pkg-config + +MIQT always uses [pkg-config](https://people.freedesktop.org/~dbn/pkg-config-guide.html) to find C++ libraries to bind to. + +For Qt Widgets, the `.pc` definition is supplied along with Qt, but for other third-party libraries, definitions might not be present. To use such third-party libraries, one option is to set the `CGO_CFLAGS`, `CGO_CXXFLAGS`, `CGO_LDFLAGS` environment variables for `go build`. However, this has a global effect and may cause issues if you use multiple libraries. Therefore, another option is to create a pkg-config file. + +To specify the CFLAGS/CXXFLAGS and LDFLAGS for a specific library, make a `MyLibrary.pc` file as follows: + +```pkgconfig +Name: My Library +Libs: -lfoo +Cflags: -I/path/ +``` + +Then run `PKG_CONFIG_PATH=/path/to/dir/ go build` so CGO will find your library. Then, the necessary flags for your system will be used only as required for the specific package. + +The `PKG_CONFIG_PATH` environment variable is understood both by CGO and by genbindings. + +## Further reading + +- [Guide to pkg-config](https://people.freedesktop.org/~dbn/pkg-config-guide.html) + +```bash +# Find where pkg-config looks for system libraries +$ pkg-config --variable pc_path pkg-config +/usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig +```