conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.17k stars 974 forks source link

[bug] PkgConfig generator is failing for QNX #7027

Open derived-coder opened 4 years ago

derived-coder commented 4 years ago

My Problem is that for the generated PkgConfig files from conan do not work for QNX profile.

/lhome/user/tools/qnx/qnx700/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.0.0-ld: cannot find -ldlt

The -ldlt cannot be found, because the path is not correctly provided.

Environment Details (include every applicable attribute)

Steps to reproduce (Include if Applicable)

This is my example cmake script:

find_package(PkgConfig)

pkg_check_modules(DltDaemon REQUIRED IMPORTED_TARGET automotive-dlt)

add_executable(example example.cpp)
target_link_libraries(example PkgConfig::DltDaemon)

This is a conan generated PkgConfig file with a profile for gcc 7.0, which will work!

prefix=/lhome/user/.conan/data2/dlt-daemon/2.18.1/company/stable/package/512d6cd809d2e8836e53318a8dc977b9d61e98f7
libdir=${prefix}/lib
includedir=${prefix}/include

Name: automotive-dlt
Description: GENIVI Diagnostic Log and Trace
Version: 2.18.1
Libs: -L${libdir} -ldlt  -lpthread  -Wl,-rpath="${libdir}"
Cflags: -I${includedir}
Requires: dbus-1

This is a PkgConfig file with a profile for qcc 5.4 (QNX)

prefix=/lhome/user/.conan/data2/dlt-daemon/2.18.1/company/stable/package/2d6a3cd5a258327478b206da119f3f11e2492dfc
libdir=${prefix}/lib
includedir=${prefix}/include

Name: automotive-dlt
Description: GENIVI Diagnostic Log and Trace
Version: 2.18.1
Libs: -L${libdir} -ldlt  -lsocket 
Cflags: -I${includedir}
Requires: dbus-1

The big difference between these two is Libs falgs: -Wl,-rpath="${libdir}" this is atteched for normal gcc build

Logs (Executed commands with output) (Include/Attach if Applicable)

the resulting link script used by CMake for gcc 7.0

/usr/bin/c++  -O3 -DNDEBUG  -rdynamic -Wl,-rpath=/lhome/user/.conan/data2/dlt-daemon/2.18.1/company/stable/package/
512d6cd809d2e8836e53318a8dc977b9d61e98f7/lib -Wl,-rpath=/lhome/user/.conan/data2/dbus/1.12.16/company/stable/package/
0d4e56cc1202812ba8997cd4cf8105d6b1efabf0/lib -Wl,-rpath=/lhome/user/.conan/data2/expat/2.2.9/company/stable/package/
d50a0d523d98c15bb147b18fa7d203887c38be8b/lib CMakeFiles/example.dir/example.cpp.o  -o bin/example  -Wl,-rpath,
/lhome/user/.conan/data2/dlt-daemon/2.18.1/company/stable/package/512d6cd809d2e8836e53318a8dc977b9d61e98f7/lib:/
lhome/user/.conan/data2/dbus/1.12.16/company/stable/package/0d4e56cc1202812ba8997cd4cf8105d6b1efabf0/lib /lhome/user/
.conan/data2/dlt-daemon/2.18.1/company/stable/package/512d6cd809d2e8836e53318a8dc977b9d61e98f7/lib/libdlt.so -lpthread 
/lhome/user/.conan/data2/dbus/1.12.16/company/stable/package/0d4e56cc1202812ba8997cd4cf8105d6b1efabf0/lib/libdbus-1.so 
-lpthread /lhome/user/.conan/data2/dbus/1.12.16/company/stable/package/0d4e56cc1202812ba8997cd4cf8105d6b1efabf0/lib/libdbus-1.so 
/lhome/user/.conan/data2/expat/2.2.9/company/stable/package/d50a0d523d98c15bb147b18fa7d203887c38be8b/lib/libexpat.a 

The link script used by CMake for qcc 5.4

/lhome/user/tools/qnx/qnx700/host/linux/x86_64/usr/bin/ntoaarch64-c++  -O3 -DNDEBUG   
CMakeFiles/example.dir/example.cpp.o 
 -o bin/example  -ldlt -lsocket -ldbus-1 -lsocket -ldbus-1 -lexpat 
memsharded commented 4 years ago

Quick question: who is providing the -ldlt library? Is it a system_libs? Is it defined in package_info()?

If it is a system_libs, the responsible of providing the path to it should probably be the build_system, not Conan (this is the main reason, it is called a system_lib, because it is not managed by Conan, and Conan doesn't know where it is located in the filesystem)

derived-coder commented 4 years ago

quick answer: dlt is actually the lib of the dlt-daemon package which I am creating. So it is not a system lib. the test_packge is actually failing. With gcc profile it works. With qnx not.

Here the package_info

    def package_info(self):
        self.cpp_info.name = "automotive-dlt"
        self.cpp_info.libs = tools.collect_libs(self)
        if not self.options.shared:
            self.cpp_info.libdirs = ["lib/static"]
        self.cpp_info.libs = tools.collect_libs(self)
        if self.settings.os == "Windows":
            self.cpp_info.libs.extend(['psapi', 'ws2_32'])
        elif self.settings.os == "Linux":
            self.cpp_info.libs.extend(['pthread'])

        if self.settings.os == "Neutrino":
            self.cpp_info.system_libs.extend(["socket"])

Such a side node. I saw a lot of test_package using the plain ${CONAN_LIBS} approach https://github.com/conan-io/conan-center-index/blob/master/recipes/zstd/all/test_package/CMakeLists.txt#L13 using this approach would fix it, however, that is not the best approach. I want a transparent integration so that existing code does not need to be changed. Can we do there something so that this kind of errors can be found earlier?

memsharded commented 4 years ago

A couple of quick tips:

I don't know what pkg_check_modules(DltDaemon REQUIRED IMPORTED_TARGET automotive-dlt) does. It is not clear how you are using the Conan generators, which generator, and how you are passing that information to the build system. Please try to provide something that we can reproduce here to investigate.

derived-coder commented 4 years ago

okay, thanks for the input. I fixed this double collect. I can uupload the whole recipe. However, you will be not be able to build it, because dlt-daemon depends on dbus, and this depends on more libs. Or do you want it anyway?

However, I want to bring your attention on the generated PkgConfig files from conan which I mentioned above, there is a difference visible like you can see. What is the reason for this -Wl,-rpath="${libdir}" in the working case with gcc?

derived-coder commented 4 years ago

@memsharded Any Idea? This issue is unfortunately a blocking issue for working with QNX