Hello,
Take a look a the abseil's conanfile.py here:
https://github.com/abseil/abseil-cpp/blob/master/conanfile.py
Its package info looks like this:
if self.settings.os == "Linux":
self.cpp_info.libs = ["-Wl,--start-group"]
self.cpp_info.libs.extend(tools.collect_libs(self))
if self.settings.os == "Linux":
self.cpp_info.libs.extend(["-Wl,--end-group", "pthread"])
Now, I am packaging my codebase with conan as well and rely on start-group/end-group to remove circular dependencies amongst my libs. My package info looks like this:
self.cpp_info.libs = ["-Wl,--start-group"]
self.cpp_info.libs.extend(['foo', 'bar'])
self.cpp_info.libs.extend(["-Wl,--end-group"])
Now here is the surprising bit. The final linker command removes start-group/end-group from my libraries if I also depend on abseil! (If I do not depend on abseil, then everything works fine).
linker command looks like this:
... foo.a bar.a -Wl,--start-group absl.a -Wl,--end-group -lpthread -Wl,--start-group -Wl,--end-group
As you can see, it created an empty start/end group at the end, and didn't encapsulate my libs in it. My suspicion is that since everything is a list of strings, GNU Linker (or cmake) changes the ordering since it thinks that start-group/end-group are just few more libs. Not sure what is the best course of action here, but any help is appreciated. Thanks!
If you run twice self.cpp_info.libs = xxx you are overwritting the values, so use self.cpp_info.lib.extend(["foo", "bar"]).
Said that including using like that -Wl,--start-group and -Wl,--end-group in the libs list sounds awful and should be avoided if possible. I really don't understand how it could work, honestly.
@lasote Apologies, I wrongly typed that. Corrected the original question.
I agree with you that start/end group is awful. I raised this in #2387 (https://github.com/conan-io/conan/issues/2387#issuecomment-474156925).
Right now, cmake knows the dependency between my archives, but there is no way to export that to conan. So as a roundabout, I added start/end group to future-proof myself in case I add more libraries.
Thanks. So, to be honest, I don't know what to do with this issue, I'm not surprised that using these groups fail somehow, internally Conan is considering each element as a library name, adding -l prefixes and so on, so I can bet some awful situation is happening there.
Is it not possible for you to just declare the right order in the library list? I talked with @uilianries and he is going to suggest to do that for the abseil recipe.
@lasote that is what I am currently doing. (i.e. specifying the order manually).
The bast we can do is forcing the order list by cpp_info.libs and set a specific version. Since Conan 1.14, the method tools.collect_libs sorts the libraries by name, which doesn't work for Abseil case.
collect_libs is evil ahaha, If I could go back in time I wouldn't implement it
I've created a new PR for Abseil:
https://github.com/abseil/abseil-cpp/pull/298
How to find the correct order list?
I listed all targets from abslTargets.cmake in target_link_libraries.