Circular linking dependency

938 views
Skip to first unread message

vikram....@gmail.com

unread,
Aug 25, 2015, 8:23:27 PM8/25/15
to bazel-discuss
Hi All,

How do we change the order of libraries being specified during linking? I do not think that bazel is maintaining the order in which the dependencies are specified for cc_binary target.

We have a lot of legacy code for which we have written bazel scripts and we are struggling to resolve the circular linker errors. There are linker options like --start-group/--end-group. I am not sure how much these are relevant for bazel.

Thanks,
Vikram

Lukács T. Berki

unread,
Aug 26, 2015, 4:05:51 AM8/26/15
to vikram....@gmail.com, bazel-discuss, Ulf Adams
Bazel *does* have well-defined ordering of libraries on the linker command line (you can see what you get it you run "bazel build" with the -s command line option):


It's somewhat complicated, but the gist is that we want the dependencies of a library to always come after the library itself and naive pre-ordering doesn't always do this. 

Exactly what kind of circular linker errors do you get?


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/53c3ce66-b614-4793-b62a-c29aef8c7ae3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Lukács T. Berki | Software Engineer | lbe...@google.com | 

Google Germany GmbH | Dienerstrasse 12 | 80331 München | Germany | Geschäftsführer: Graham Law, Christine Elizabeth Flores | Registergericht und -nummer: Hamburg, HRB 86891

Vikram Chhibber

unread,
Aug 26, 2015, 4:39:48 PM8/26/15
to Lukács T. Berki, bazel-discuss, Ulf Adams
Thanks. That is what I see is the difference between bazel and Makefile that we have in our project.
In makefile, all the compilation units are archived in one lib file while in bazel, many of these compilation units have their own lib archives. The reason is that because they have different cflags, all the source code files with common cflags are being clubbed into one archive. The cyclic dependencies among these difference lib files.
I can rearrange the dependencies among these targets but considering their numbers, it seems be some involved work. Bazel does not create one archive target with all the libs combined even if I declare a target will all the archive libs as dependency. It creates an empty target archive.  My understanding might be incorrect. Please let me know if you have any suggestions.

Vikram




Lukács T. Berki

unread,
Aug 27, 2015, 7:38:40 AM8/27/15
to Vikram Chhibber, bazel-discuss, Ulf Adams
It's kind of hard to draw any conclusions without seeing the source or, preferably, a minimal example of what you think is wrong. What do you mean by "create an empty target archive"? Bazel, in general, doesn't promise that it builds anything other than the binary rule it is told to build, so depending on the contents of your BUILD files, it creating an empty archive can be okay.

In general, cyclic dependencies don't work with Bazel. You'll need to either lump all the members of the cycle into a single cc_library rule or break the cycle somehow. This is in line with Bazel's "you need to declare your dependencies" philosophy.




Reply all
Reply to author
Forward
0 new messages