Clang error: cannot specify 'B' along with 'A' (err_drv_cannot_mix_options)

From emmtrix Wiki
Jump to navigation Jump to search
Text error: cannot specify 'B' along with 'A' (since 9.0)
Type Error
Category None (since 9.0)
Internal Id err_drv_cannot_mix_options (since 9.0)
Internal Message cannot specify '%1' along with '%0' (since 9.0)
Regular Expression (?:error|fatal error)\: cannot specify '(.*?)' along with '(.*?)'
First Commit 2018-08-15 4593e4131aff AMDGPU: Teach toolchain to link rocm device libs

Description

The error is issued by the Clang compiler when there is an attempt to specify incompatible or mutually exclusive options within a compilation command. It highlights the accidental combination of options that cannot function together, signaling a likely mistake in the construction of the command-line arguments. The sequence in which options are provided does not impact the occurrence of this error; it is strictly the presence of certain option pairings that triggers the diagnostic. The compiler expects each option to uniquely contribute to the configuration of the compilation process, and when options conflict, resolution is not automatically attempted. Instead, the error serves as a direct feedback mechanism, prompting for a review and correction of the provided options.  
AI Generated

Example

In the following example, the Clang compiler command line attempts to compile a simple C++ program targeted for iOS and macOS platforms simultaneously. The options -target arm64-apple-ios13.0-macabi and -mtargetos=macos10.15 are specified together, which are mutually exclusive. These options indicate the target platform and OS version for the compilation, respectively. Since one is aimed at an iOS target and the other specifies a macOS version, the Clang compiler flags this as an error. The output from the compiler clearly indicates that the -mtargetos=macos10.15 option cannot be used alongside the -target arm64-apple-ios13.0-macabi option, followed by another error message pointing out an invalid version number in the -target option. This enforces the rule that certain compilation options are incompatible when used together, and it serves as direct feedback to correct the command-line arguments used for compilation.  
AI Generated


Flags -xc++ -target arm64-apple-ios13.0-macabi -mtargetos=macos10.15

[Try out in Compiler Explorer]

Source
int main() { return 0; }
Compiler Output
clang++: error: cannot specify '-mtargetos=macos10.15' along with '-target arm64-apple-ios13.0-macabi'
clang++: error: invalid version number in '-target arm64-apple-ios13.0-macabi'


Clang Internals (17.0.6)

Git Commit Message

AMDGPU: Teach toolchain to link rocm device libs

Currently the library is separately linked, but this isn't correct to
implement fast math flags correctly. Each module should get the
version of the library appropriate for its combination of fast math
and related flags, with the attributes propagated into its functions
and internalized.

HIP already maintains the list of libraries, but this is not used for
OpenCL. Unfortunately, HIP uses a separate --hip-device-lib argument,
despite both languages using the same bitcode library. Eventually
these two searches need to be merged.

An additional problem is there are 3 different locations the libraries
are installed, depending on which build is used. This also needs to be
consolidated (or at least the search logic needs to deal with this
unnecessary complexity).

Used in Clang Sources

This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.

clang/lib/Driver/ToolChains/Darwin.cpp (line 2172)

void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
  // ...
  if (OSTarget) {
    // Disallow mixing -target and -mtargetos=.
    if (const auto *MTargetOSArg = Args.getLastArg(options::OPT_mtargetos_EQ)) {
      // ...
      getDriver().Diag(diag::err_drv_cannot_mix_options) << TargetArgStr << MTargetOSArgStr;

clang/lib/Driver/ToolChains/Darwin.cpp (line 2215)

void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
  // ...
  if (OSTarget) {
  // ...
  } else if ((OSTarget = getDeploymentTargetFromMTargetOSArg(Args, getDriver(), SDKInfo))) {
    // ...
    if (OSVersionArgTarget) {
      // ...
      getDriver().Diag(diag::err_drv_cannot_mix_options) << MTargetOSArgStr << OSVersionArgStr;

clang/lib/Driver/ToolChains/Gnu.cpp (line 316)

static bool getStaticPIE(const ArgList &Args, const ToolChain &TC) {
  // ...
  // -no-pie is an alias for -nopie. So, handling -nopie takes care of
  // -no-pie as well.
  if (HasStaticPIE && Args.hasArg(options::OPT_nopie)) {
    // ...
    D.Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;