Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying link order of a conan package #1983

Closed
kevswims opened this issue Nov 2, 2017 · 7 comments
Closed

Specifying link order of a conan package #1983

kevswims opened this issue Nov 2, 2017 · 7 comments

Comments

@kevswims
Copy link

kevswims commented Nov 2, 2017

I have a conan package that includes a set of prebuilt binaries. ie. liba.a and libb.a. When calling
target_link_libraries(nameOfSharedLibrary CONAN_PKG::PackageName)
the libraries are linked to in the wrong order (libb.a liba.a). To work around this I am linking to these I am calling
target_link_libraries(nameOfSharedLibrary ${CONAN_LIB_DIRS_PACKAGENAME}/liba.a ${CONAN_LIB_DIRS_PACKAGENAME}/libb.b).

Is there a way to specify what this link order should be for a package? Either when creating the package or from the consuming project?

@memsharded
Copy link
Member

I think the libraries should be in the order they are declared in the package_info() method, like:

def package_info(self):
    self.cpp_info.libs = ["a", "b"]

Can you please check your package_info()? If not maybe it is a bug and should be fixed.

@kevswims
Copy link
Author

kevswims commented Nov 2, 2017

Looks like I was using self.cpp_info.libs = self.collect_libs() I will try explicitly setting them. Does self.collect_libs() sort by alphabetic order?

@memsharded
Copy link
Member

Nop, under the hood collect_libs() is using a os.listdir call, which does not guarantee the result order. And enforcing an alphabetic order on them in conan code is also quite arbitrary. I suggest going for the explicit definition, it should be more robust than the collects_libs one.

@danimtb
Copy link
Member

danimtb commented Dec 23, 2017

There is an issue about this to add a warning in the docs conan-io/docs#443 due to the same issue here #2201

@r-darwish
Copy link

I'm replying here as a followup for this issue. This issue is a bug in the package itself. However, due to the arbitrary order of os.listdir this bug was hard to reproduce and track down. It occurred on some machines, and on some didn't.

I agree that sorting the libraries alphabetically won't magically solve the dependency graph, and that it is up to the package maintainer to maintain the correct order. However, making tools.collect_libs's order deterministic will help spotting such issues.

@danimtb
Copy link
Member

danimtb commented Mar 14, 2018

Hi @r-darwish

There is no bug in the behavior of tools.collect_libs() as there is a warning regarding the order in the documentation. However, I see your point and maybe it should follow the same alphabetically order in all OS to be mor consistent.

Would you like to contribute with that enhancement? 😄

@danimtb
Copy link
Member

danimtb commented Jun 20, 2018

I thinks this could be closed due to lack of activity. Please open a new issue with info updated for tools.collect_libs() enhancements if needed.

@danimtb danimtb closed this as completed Jun 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants