When using a tool like pkg-config (see here), how is one supposed to know what the library name should be? It is not always intuitive. DLIB, for example, doesn't work for
pkg-config --cflags dlib
pkg-config --cflags libdlib
pkg-config --cflags dlib-19.9
I usually have to issue a command like sudo ldconfig -p | grep dlib, but all that does is return libdlib.so, which also doesn't work.
How do experts tackle this problem. Do they simply know all the library names?
It is called package name what you are using as a main parameter for pkg-config, and then applying --cflags or --libs, etc one just accesses the parameters specified and evaluated from the corresponding package config file ([some_package_name].pc, a.k.a pkg-config metadata file) that was found in pkg-config search paths.
And yes, there is no rule how package name relates to library name. Typically it's either library name without lib- prefix or just the whole library name. I found the following in pkg-config guide:
A common choice is to match the library name to the .pc name.
For instance, a package installing libfoo.so would have a
corresponding libfoo.pc file containing the pkg-config metadata. This
choice is not necessary; the .pc file should simply be a unique
identifier for your library. Following the above example, foo.pc or
foolib.pc would probably work just as well.
However, you can list all available in pkg-config search paths and find out the correct names before using them in Makefile:
$ pkg-config --list-all | grep dlib
Related
I've written a small library and I'm trying to set it up to be usable with pkg-config, for those in my organization who might need to make use of it later. So my installer places a .pc file in /usr/local/lib/pkgconfig, and I've recently discovered that for some reason this isn't in the default list of directories that pkg-config scans for its pc files, despite /usr/local being the canonical prefix for locally-compiled software. So, I need to add /usr/local/lib/pkgconfig to PKG_CONFIG_PATH.
However, I'm finding that despite claims in the man page, pkg-config's own error message and everywhere online, pkg-config doesn't actually look at PKG_CONFIG_PATH. The error message tells me to add /usr/local/lib/pkgconfig (which contains the .pc file I'm looking for) to PKG_CONFIG_PATH, when I've clearly already done that.
[chris#delphinus-a pkgconfig]$ pwd
/usr/local/lib/pkgconfig
[chris#delphinus-a pkgconfig]$ ls
libexample.pc
[chris#delphinus-a pkgconfig]$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
[chris#delphinus-a pkgconfig]$ echo $PKG_CONFIG_PATH
/usr/local/lib/pkgconfig
[chris#delphinus-a pkgconfig]$ pkg-config --cflags libexample
Package libexample was not found in the pkg-config search path.
Perhaps you should add the directory containing `libexample.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libexample', required by 'virtual:world', not found
[chris#delphinus-a pkgconfig]$ echo $PKG_CONFIG_PATH
/usr/local/lib/pkgconfig
[chris#delphinus-a pkgconfig]$ pkg-config --variable pc_path pkg-config
/usr/lib64/pkgconfig:/usr/share/pkgconfig
[chris#delphinus-a pkgconfig]$ pkg-config --version
1.6.3
The contents of libexample.pc:
prefix=/usr/local
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include
Name: libexample
Description: example library.
Libs: -L${libdir} -lpthread -ltimeutil -lczmq -lzmq
Cflags: -I${includedir}
So, if PKG_CONFIG_PATH is indeed the environment variable I need to set, how to I get pkg-config to actually use it? Or what else am I missing here? This is in Fedora 31, FWIW.
Apparently (judging by the very large version number), you're using some other implementation of pkg-config: namely, from this page I gather that it's something called pkgconf and is intended to somehow replace the FDO pkg-config program.
To succeed with PKG_CONFIG_PATH, I suppose, you should install a real pkg-config from FDO, whose version should be in the range of 0.29.x.
I'm using Cygwin on windows to run this command:
g++ `pkgconfig --libs --cflags opencv` -I. -o mergevec mergevec.cpp ....
But I get an error:
-bash: pkg-config: command not found
I've installed cygwin directly on C:. I've added to the PATH environment variable the following:
C:\cygwin64\bin;
C:\cygwin64\lib
I've run cygcheck -c and it gives me a whole list of packages, but pkg-config isn't in that list.
There is a folder called pkgconfig in C:\cygwin64\lib though.
How do I fix this error?
pkg-config is a piece of software that allow your computer to check installed libraries for source compilation. It may not be installed on Windows so in last scenario please check for install.
However in your case i think it is installed, but not set on the right path for linux commands. Try to type in cygwin:
$ export PKG_CONFIG_PATH=c:\\cygwin\\usr\\local\\lib\\pkgconfig
as stated in this post.
Otherwise just abandon Windows and try to compile mergevec on an Linux VM, which is really easier (it was made for it). The only down point of this method is that you will have to do the mergevec operation (and the ones before, otherwise you may have encoding problems) under your linux space. See my previous answer for this manipulation.
If any problem don't hesitate.
run cgywin setup and in package search type pkg-config then make sure that pkg-config utility is installed.
it should solve the not found command problem.
I think that in this case it has nothing to do with the PKG_CONFIG_PATH, because the user complains on the "command not found" error message.
The user probably mixes up pkg-config as a tool (with -) and pkgconfig (without -) as a directory as I see from the command. If I run it without dash on my system I get the same error message of course:
$ pkgconfig --libs --cflags opencv
-bash: pkgconfig: command not found
On Cygwin there is pkgconf.exe as a tool, pkg-config as a symlink to it and pkgconfig as a directory. There is no tool pkgconfig.
If it is not found as pkg-config then it means that pkg-config tool is missing in the Cygwin installation (the solution is to upgate Cygwin tools and select it in the checkbox) or it is probably the symlink problem which I described in https://stackoverflow.com/a/66037850/4807875 (the solution in this case is to use the indeed Cygwin console instead of the native cmd.exe with C:\Cygwin64\bin in PATH in it, or to call explicitly pkgconf.exe).
command
gcc -print-search-dirs
returns:
install: /usr/lib/gcc/i686-linux-gnu/4.6/
programs: =/usr/lib/gcc/i686-linux-gnu/4.6/:/usr/lib/gcc/i686-linux-gnu/4.6/:/usr/lib/gcc/i686-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.6/:/usr/lib/gcc/i686-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../../i686-linux-gnu/bin/i686-linux-gnu/4.6/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../../i686-linux-gnu/bin/i386-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../../i686-linux-gnu/bin/
libraries: =/usr/lib/gcc/i686-linux-gnu/4.6/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../../i686-linux-gnu/lib/i686-linux-gnu/4.6/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../../i686-linux-gnu/lib/i386-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../../i686-linux-gnu/lib/../lib/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../i686-linux-gnu/4.6/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/:/lib/i686-linux-gnu/4.6/:/lib/i386-linux-gnu/:/lib/../lib/:/usr/lib/i686-linux-gnu/4.6/:/usr/lib/i386-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../../i686-linux-gnu/lib/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../:/lib/:/usr/lib/
How to add some other path to libraries section? I want to make my custom library available via flag -lmylib instead specific path.
The usual way to do this is to install th library to /usr/lib on a user's system. The only way to change the built-in specs is by using a custom specs file (not recommended!) and this also requires an additional argument.
Either install it to /usr/lib or pass the location as an argument when linking.
You can also copy the path printed as you showed, and prepend your desired path element and pass it to the -B option.
I am, trying to find the gstreamer lib in windows (msvc) using pkg-config
pkg-config gstreamer-0.10 --cflags --libs
but i am getting any result like this
Package gstreamer-0.10 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gstreamer-0.10.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gstreamer-0.10' found
a .pc like is created when a library is installed (automatically through the use of an RPM, deb, or other binary packaging system or by compiling from the source).I can't find the .pc file in my gstreamer directory.
Should i just create a .pc file with all the necessary details.
prefix=C:\Program Files (x86)\OSSBuild\GStreamer\v0.10.7
exec_prefix=${prefix}
libdir=${exec_prefix}\lib
includedir=${prefix}\sdk\include\gstreamer-0.10
toolsdir=${exec_prefix}\bin
pluginsdir=${exec_prefix}\lib\gstreamer-0.10
datarootdir=${prefix}\share
datadir=${datarootdir}
girdir=${datadir}/gir-1.0
typelibdir=${libdir}/girepository-1.0
Name: GStreamer
Description: Streaming media framework
Requires: glib-2.0, gobject-2.0, gmodule-no-export-2.0, gthread-2.0, libxml-2.0
Version: 0.10.35
Libs: -L${libdir} -lgstreamer-0.10
Cflags: -I${includedir}
or there is any other way to do this or Am i missing somthing?
Hope you can help.Thankz for taking the time to read the problem.
Well i am doing this to find solution why i am getting not found message in my waf configure for gstreamer
conf.check_cfg(atleast_pkgconfig_version='0.0.0')
conf.check_cfg(package='gstreamer-0.10', uselib_store='GSTREAMER', args='--cflags --libs', mandatory=True)
the code works in linux and is supposed to work in windows too.
ADDED LATER
Well making the .pc and setting a path of the .pc dir to the PKG_CONFIG_PATH environment variable does the trick.Its not hard do it
Check out this out. Thankz for readings and helping me..:)
pkg-config is a great tool but unfortunately on Windows (vs. UNIX) there is no standard executable PATH or PKG_CONFIG_PATH.
While you can revert to defining options --with-gstreamer-include-dir ... --with-gstreamer-lib-dir ... and avoid the pkg-config dependency, you can also use --pkgconfig-exe c:\path\to\pkg-config.exe --pkgconfig-path c:\path\to\gstreamer;c:\path\to\otherlib, which will help having a good-looking wscript, especially when using a lot of pkg-config libs.
The typical Win32 user may have issues setting PKG_CONFIG_PATH and PATH directly or stumbling onto a cryptic "not found" error and then checking config.log.
If you do add the windows-specific pkg-config options, it might be interesting for everybody.
You could write a pkgconfig_opts tool and submit it as a waf extra.
I have two GTK builds on my Mac, an X11 one with headers and a Quartz one without. I can compile Vala code for X11 just fine, but how do I use the Quartz libraries?
This is probably a C question, but I only ever used that toolchain through valac.
When using valac, it gets the appropriate compile and link flags from pkg-config based on the --pkg flags. You can see what is being included with pkg-config --cflags --libs gtk+-2.0. If you wish to change this you have two opions:
Use valac -C to only produce C files and manage the compilation and linking yourself.
Set export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/sw/lib/pkgconfig or whatever collection of directories to get your packages coming in the desired order.
I'm not quite sure where your GTK+ installs are located, presumably in a MacPorts tree.