problem with CMake not including library's path (with pkg-config)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

problem with CMake not including library's path (with pkg-config)

Francesco Abbate
Hi all,

I stumbled in a problem with CMake. Everything is working fine except
that, for two libraries that I locate with pkg-config, cmake does not
include during linking the library's path (-L<path>) which is given by
pkg-config.


Here an extract of the CMakeLists.txt:


[...]

include(FindPkgConfig)
pkg_search_module(AGG REQUIRED libagg)

[...]

target_link_libraries(libcanvas ${AGG_LIBRARIES})
target_include_directories(libcanvas PUBLIC
${PROJECT_SOURCE_DIR}/include ${AGG_INCLUDE_DIRS})
[...]

When I run pkg-config everything is correct:

> pkg-config --libs libagg
-Lc:/fra/local_msys64/lib -lagg -lm

One can notice that pkg-config provides a non-standard path for the library.

By inspecting CMakeCache.txt I found a trace of the library's path.
See below an extract:

AGG_CFLAGS:INTERNAL=-Ic:/fra/local_msys64/include/agg2
AGG_CFLAGS_I:INTERNAL=
AGG_CFLAGS_OTHER:INTERNAL=
AGG_FOUND:INTERNAL=1
AGG_INCLUDEDIR:INTERNAL=c:/fra/local_msys64/include/agg2
AGG_INCLUDE_DIRS:INTERNAL=c:/fra/local_msys64/include/agg2
AGG_LDFLAGS:INTERNAL=-Lc:/fra/local_msys64/lib;-lagg;-lm
AGG_LDFLAGS_OTHER:INTERNAL=
AGG_LIBDIR:INTERNAL=c:/fra/local_msys64/lib
AGG_LIBRARIES:INTERNAL=agg;m
AGG_LIBRARY_DIRS:INTERNAL=c:/fra/local_msys64/lib
AGG_LIBS:INTERNAL=
AGG_LIBS_L:INTERNAL=
AGG_LIBS_OTHER:INTERNAL=
AGG_LIBS_PATHS:INTERNAL=
AGG_PREFIX:INTERNAL=c:/fra/local_msys64
AGG_STATIC_CFLAGS:INTERNAL=-Ic:/fra/local_msys64/include/agg2
AGG_STATIC_CFLAGS_I:INTERNAL=
AGG_STATIC_CFLAGS_OTHER:INTERNAL=
AGG_STATIC_INCLUDE_DIRS:INTERNAL=c:/fra/local_msys64/include/agg2
AGG_STATIC_LDFLAGS:INTERNAL=-Lc:/fra/local_msys64/lib;-lagg;-lm
AGG_STATIC_LDFLAGS_OTHER:INTERNAL=
AGG_STATIC_LIBDIR:INTERNAL=
AGG_STATIC_LIBRARIES:INTERNAL=agg;m
AGG_STATIC_LIBRARY_DIRS:INTERNAL=c:/fra/local_msys64/lib
AGG_STATIC_LIBS:INTERNAL=
AGG_STATIC_LIBS_L:INTERNAL=
AGG_STATIC_LIBS_OTHER:INTERNAL=
AGG_STATIC_LIBS_PATHS:INTERNAL=
AGG_VERSION:INTERNAL=2.5.0
AGG_libagg_INCLUDEDIR:INTERNAL=
AGG_libagg_LIBDIR:INTERNAL=
AGG_libagg_PREFIX:INTERNAL=
AGG_libagg_VERSION:INTERNAL=

but in the Ninja build file the library's path is not given (below an extract):

----------
#############################################
# Link the executable tests\test-window.exe

build tests/test-window.exe: CXX_EXECUTABLE_LINKER__test-window tests/CMakeFiles
/test-window.dir/test-window.cpp.obj | win32/liblibcanvaswin32.a src/liblibcanva
s.a || src/liblibcanvas.a win32/liblibcanvaswin32.a
  LINK_LIBRARIES = win32/liblibcanvaswin32.a src/liblibcanvas.a -lagg
-lm -lfreetype -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32
-lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
------------

So the behavior of CMake looks wrong to me. Pkg-config is giving
explicitly a non-standard library path but CMake just decided to not
include it in the linker options.

To finish let me report that I'am using CMake 3.11.1 on a Windows
system using MSYS2.

I can also mention that a similar Meson build just works fine but this
is only to make you, CMake guys, jealous.

Ok, just kidding :-)

Thank you in advance for any help.

Kind regards
Francesco





--
Francesco
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: problem with CMake not including library's path (with pkg-config)

Andreas Naumann
Dear Francesco,

I use the pkg-config module with IPopt and had the same problem.
According to the documentation, the library paths are in
<XPREFIX>_LIBRARY_DIRS. In your case, you should find the paths in the
variable AGG_LIBRARY_DIRS or all flags in the variableĀ  AGG_LDFLAGS .

Regards,
Andreas
Am 24.05.2018 um 18:48 schrieb Francesco Abbate:

> Hi all,
>
> I stumbled in a problem with CMake. Everything is working fine except
> that, for two libraries that I locate with pkg-config, cmake does not
> include during linking the library's path (-L<path>) which is given by
> pkg-config.
>
>
> Here an extract of the CMakeLists.txt:
>
>
> [...]
>
> include(FindPkgConfig)
> pkg_search_module(AGG REQUIRED libagg)
>
> [...]
>
> target_link_libraries(libcanvas ${AGG_LIBRARIES})
> target_include_directories(libcanvas PUBLIC
> ${PROJECT_SOURCE_DIR}/include ${AGG_INCLUDE_DIRS})
> [...]
>
> When I run pkg-config everything is correct:
>
>> pkg-config --libs libagg
> -Lc:/fra/local_msys64/lib -lagg -lm
>
> One can notice that pkg-config provides a non-standard path for the library.
>
> By inspecting CMakeCache.txt I found a trace of the library's path.
> See below an extract:
>
> AGG_CFLAGS:INTERNAL=-Ic:/fra/local_msys64/include/agg2
> AGG_CFLAGS_I:INTERNAL=
> AGG_CFLAGS_OTHER:INTERNAL=
> AGG_FOUND:INTERNAL=1
> AGG_INCLUDEDIR:INTERNAL=c:/fra/local_msys64/include/agg2
> AGG_INCLUDE_DIRS:INTERNAL=c:/fra/local_msys64/include/agg2
> AGG_LDFLAGS:INTERNAL=-Lc:/fra/local_msys64/lib;-lagg;-lm
> AGG_LDFLAGS_OTHER:INTERNAL=
> AGG_LIBDIR:INTERNAL=c:/fra/local_msys64/lib
> AGG_LIBRARIES:INTERNAL=agg;m
> AGG_LIBRARY_DIRS:INTERNAL=c:/fra/local_msys64/lib
> AGG_LIBS:INTERNAL=
> AGG_LIBS_L:INTERNAL=
> AGG_LIBS_OTHER:INTERNAL=
> AGG_LIBS_PATHS:INTERNAL=
> AGG_PREFIX:INTERNAL=c:/fra/local_msys64
> AGG_STATIC_CFLAGS:INTERNAL=-Ic:/fra/local_msys64/include/agg2
> AGG_STATIC_CFLAGS_I:INTERNAL=
> AGG_STATIC_CFLAGS_OTHER:INTERNAL=
> AGG_STATIC_INCLUDE_DIRS:INTERNAL=c:/fra/local_msys64/include/agg2
> AGG_STATIC_LDFLAGS:INTERNAL=-Lc:/fra/local_msys64/lib;-lagg;-lm
> AGG_STATIC_LDFLAGS_OTHER:INTERNAL=
> AGG_STATIC_LIBDIR:INTERNAL=
> AGG_STATIC_LIBRARIES:INTERNAL=agg;m
> AGG_STATIC_LIBRARY_DIRS:INTERNAL=c:/fra/local_msys64/lib
> AGG_STATIC_LIBS:INTERNAL=
> AGG_STATIC_LIBS_L:INTERNAL=
> AGG_STATIC_LIBS_OTHER:INTERNAL=
> AGG_STATIC_LIBS_PATHS:INTERNAL=
> AGG_VERSION:INTERNAL=2.5.0
> AGG_libagg_INCLUDEDIR:INTERNAL=
> AGG_libagg_LIBDIR:INTERNAL=
> AGG_libagg_PREFIX:INTERNAL=
> AGG_libagg_VERSION:INTERNAL=
>
> but in the Ninja build file the library's path is not given (below an extract):
>
> ----------
> #############################################
> # Link the executable tests\test-window.exe
>
> build tests/test-window.exe: CXX_EXECUTABLE_LINKER__test-window tests/CMakeFiles
> /test-window.dir/test-window.cpp.obj | win32/liblibcanvaswin32.a src/liblibcanva
> s.a || src/liblibcanvas.a win32/liblibcanvaswin32.a
>    LINK_LIBRARIES = win32/liblibcanvaswin32.a src/liblibcanvas.a -lagg
> -lm -lfreetype -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32
> -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
> ------------
>
> So the behavior of CMake looks wrong to me. Pkg-config is giving
> explicitly a non-standard library path but CMake just decided to not
> include it in the linker options.
>
> To finish let me report that I'am using CMake 3.11.1 on a Windows
> system using MSYS2.
>
> I can also mention that a similar Meson build just works fine but this
> is only to make you, CMake guys, jealous.
>
> Ok, just kidding :-)
>
> Thank you in advance for any help.
>
> Kind regards
> Francesco
>
>
>
>
>

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: problem with CMake not including library's path (with pkg-config)

Rolf Eike Beer
In reply to this post by Francesco Abbate
Am 2018-05-24 18:48, schrieb Francesco Abbate:

> Hi all,
>
> I stumbled in a problem with CMake. Everything is working fine except
> that, for two libraries that I locate with pkg-config, cmake does not
> include during linking the library's path (-L<path>) which is given by
> pkg-config.
>
>
> Here an extract of the CMakeLists.txt:
>
>
> [...]
>
> include(FindPkgConfig)
> pkg_search_module(AGG REQUIRED libagg)
>
> [...]
>
> target_link_libraries(libcanvas ${AGG_LIBRARIES})
> target_include_directories(libcanvas PUBLIC
> ${PROJECT_SOURCE_DIR}/include ${AGG_INCLUDE_DIRS})
> [...]

Yes, this is a known shortcoming. But there is already help available!

For CMake >= 3.7 you can ask FindPkgConfig to create an imported target
for you, which will then include not only the library paths, but also
the include directories, so you do not need to explicitely call
target_include_directories() anymore:

pkg_search_module(AGG REQUIRED IMPORTED_TARGET libagg)

target_link_libraries(libcanvas PkgConfig::AGG)

I strongly encourage you to go this way as it also drags in needed
defines and the like.

If you can't go that route for whatever reason you need to do

link_directories(${AGG_LIBRARY_DIRS})

Side note: this is the only place I can still accept the usage of that
command.

And since it's crappy that you have the full library path in the target,
but not in a variable, there will be <PREFIX>_LINK_LIBARIES from CMake
3.12 on, which would be the thing you pass to target_link_libraries()
instead and which has the exact same information the imported target
already has.

Greetings,

Eike
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: problem with CMake not including library's path (with pkg-config)

Francesco Abbate
Hi,

thank you for the help.

As suggested by Andreas, AGG_LDFLAGS does what I think should be done
and it works for me.

As for the IMPORTED_TARGET approach, I still need to explicitly call
target_include_directories() and in addition the options given to the
linker with PkgConfig::AGG seems to be wrong. I am quite inclined to
forgot about this IMPORTED_TARGET approach, I prefer to use the more
simple approach that works.

If I can suggest something to the cmake developers: please make a more
extensive introduction by covering more common cases. For example the
standard cmake introduction does not mention how to find and use with
an external library. I had to use google and stackoverflow to find the
bit of information I needed. just my two cents.

Kind regards
Francesco
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: problem with CMake not including library's path (with pkg-config)

Rolf Eike Beer
Am Freitag, 25. Mai 2018, 18:53:43 schrieb Francesco Abbate:

> Hi,
>
> thank you for the help.
>
> As suggested by Andreas, AGG_LDFLAGS does what I think should be done
> and it works for me.
>
> As for the IMPORTED_TARGET approach, I still need to explicitly call
> target_include_directories() and in addition the options given to the
> linker with PkgConfig::AGG seems to be wrong. I am quite inclined to
> forgot about this IMPORTED_TARGET approach, I prefer to use the more
> simple approach that works.
I would like to hear that story, just in case the module still has bugs. But
please try with a recent development snapshot of CMake as there have been some
additional fixes to the module recently.

Eike
--

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

signature.asc (188 bytes) Download Attachment