question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`illegal option -- D` when linking in macOS

See original GitHub issue

Description of the bug:

Any cc_library with a non-empty srcs fails to link when using a custom toolchain.

What’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

A minimal repro is here: https://github.com/asoffer/bazel_macos_repro

Which operating system are you running Bazel on?

macOS Monterey 12.4

What is the output of bazel info release?

release 5.2.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What’s the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

The D flag is valid on unix systems but not macOS. This has shown up on some other builds (python-related) but nothing C++ related that I’ve found.

Any other information, logs, or outputs that you want to share?

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
asoffercommented, Jul 13, 2022

Both the workaround and the direct fix work. Thank you. I’m not sure what the correct action is moving forward… I suspect it would be valuable to document that an unknown target-libc does not work for macOS builds. But I’m not sure where the best place would be for this.

1reaction
keithcommented, Jul 13, 2022

The quickest workaround would be to add the archiver_flags feature to your custom toolchain so you avoid the default one:

    archiver_flags_feature = feature(
        name = "archiver_flags",
        flag_sets = [
            flag_set(
                actions = [ACTION_NAMES.cpp_link_static_library],
                flag_groups = [
                    flag_group(flags = ["rcs"]),
                    flag_group(
                        flags = ["%{output_execpath}"],
                        expand_if_available = "output_execpath",
                    ),
                ],
            ),
            flag_set(
                actions = [ACTION_NAMES.cpp_link_static_library],
                flag_groups = [
                    flag_group(
                        iterate_over = "libraries_to_link",
                        flag_groups = [
                            flag_group(
                                flags = ["%{libraries_to_link.name}"],
                                expand_if_equal = variable_with_value(
                                    name = "libraries_to_link.type",
                                    value = "object_file",
                                ),
                            ),
                            flag_group(
                                flags = ["%{libraries_to_link.object_files}"],
                                iterate_over = "libraries_to_link.object_files",
                                expand_if_equal = variable_with_value(
                                    name = "libraries_to_link.type",
                                    value = "object_file_group",
                                ),
                            ),
                        ],
                        expand_if_available = "libraries_to_link",
                    ),
                ],
            ),
        ],
    )
Read more comments on GitHub >

github_iconTop Results From Across the Web

install: illegal option -- D - Ask Different - Apple Stack Exchange
Missing parent directories are created as required. I am attempting to install a library using a makefile and am getting this error on...
Read more >
macos - Bash touch - illegal option -d - Stack Overflow
I want to change modification date of all files in a specific directory to minus 10 hours . #!/bin/sh for i in /Users/slick/Desktop/100D5200/*; ......
Read more >
Easy symbolic linker please! - Apple Support Communities
... I think I do the ln -s thing own terminal I get 'illegal option'. ... You can't make symbolic links to a...
Read more >
Command line installation fails on OSX: illegal option -D #252
This is the output of make install for the commandline subdirectory, on my machine: $ make install Building for OS=macosx ...
Read more >
Restoring a Password in Single-User Mode? - macos
When I issued it, it said -d was an illegal option. Perhaps change your syntax? – sharksfan98 · Sorry, mistaken it for linux...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found