cc_library uses object files of static library

25 views
Skip to first unread message

andreash...@gmail.com

unread,
May 25, 2018, 5:53:49 AM5/25/18
to bazel-discuss
I'm trying to build a C++ node add-on and detected different behavior while linking on mac and linux. mac uses the static linked '.a' for dependencies but with linux the linker command uses a parameter file containing all object files of the dependencies. this causes come duplicated symbol problems. I tried to edit the Crosstool feature 'libraries_to_link'

```
flag_group {
flag_group {
flag: "-Wl,--start-lib"
expand_if_equal {
variable: "libraries_to_link.type"
value: "object_file_group"
}
}
flag_group {
flag_group {
flag: "%{libraries_to_link.object_files}"
expand_if_false: "libraries_to_link.is_whole_archive"
}
flag_group {
flag: "-Wl,-force_load,%{libraries_to_link.object_files}"
expand_if_true: "libraries_to_link.is_whole_archive"
}
iterate_over: "libraries_to_link.object_files"
expand_if_equal {
variable: "libraries_to_link.type"
value: "object_file_group"
}
}
flag_group {
flag: "-Wl,--end-lib"
expand_if_equal {
variable: "libraries_to_link.type"
value: "object_file_group"
}
}
}
```

but i think at this point it is to late to use the static libraries instead of the object files.

Does anyone know how to fix this?

Marcel Hlopko

unread,
May 25, 2018, 7:00:08 AM5/25/18
to andreash...@gmail.com, bazel-discuss
Hi Andreas,

Objects should be wrapped in --start-lib --end-lib block, which makes gold linker treat them as if they were in a .a archive. Can you isolate (even without bazel, just gcc/gold invocations) the problem so I can take a look what you mean?

Quick and dirty "fix" would be to uninstall gold, run bazel clean --expunge, and see if it's fixed (bfd ld doesn't support --start-lib --end-lib so bazel will produce proper .a).

--
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/ca67e713-25e0-4aa4-8e59-044be6b589a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891
Reply all
Reply to author
Forward
0 new messages