Clang error: unknown target triple 'A' (err_target_unknown_triple)

From emmtrix Wiki
Jump to navigation Jump to search
Text error: unknown target triple 'A'
Type Error
Category None
Internal Id err_target_unknown_triple
Internal Message unknown target triple '%0'
Regular Expression (?:error|fatal error)\: unknown target triple '(.*?)'
First Commit 2009-11-15 b9bbd54fdb5b Add TargetOptions and use it when constructing targets.

Description

<description>The error is issued by the Clang compiler when it encounters a target triple specification that is either malformed or not recognized. A target triple is a concise description of the target architecture, vendor, operating system, and optionally, the environment for which the code is being compiled. This specification is critical for the compiler to generate correct code for the intended platform. If the triple is unknown or incorrect, Clang cannot proceed with code generation, leading to this error. The issue often arises from typographical errors in the target triple or attempts to compile code for a target that is not supported by the installed version of Clang. Resolving the error typically involves verifying the target triple for accuracy or consulting documentation to ensure that the target is supported.</description>  
AI Generated

Example

In the following example, the Clang compiler is invoked with the option -target followed by unknown, which is intended to specify the target architecture, vendor, operating system, or environment for which the code is being compiled. The source code provided is a simple C++ program with a main function that returns 0. However, because the target triple unknown is not recognized by Clang, the compilation process is halted, and an error message is output indicating that the target triple is unknown. This demonstrates the importance of specifying a valid target triple when using the -target option with Clang.  
AI Generated


Flags -xc -target unknown

[Try out in Compiler Explorer]

Source
int main() { return 0; } // Simple function
Compiler Output
error: unknown target triple 'unknown'


Clang Internals (17.0.6)

Git Commit Message

Add TargetOptions and use it when constructing targets.
 - This ended up being hard to factor, sorry for the large diff.

 - Some post-commit cleanup to come.

llvm-svn: 88833

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/Basic/Targets.cpp (line 780)

/// CreateTargetInfo - Return the target info object for the specified target
/// options.
TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags, const std::shared_ptr<TargetOptions> &Opts) {
  // ...
  if (!Target) {
    Diags.Report(diag::err_target_unknown_triple) << Triple.str();

clang/lib/Driver/ToolChains/CrossWindows.cpp (line 97)

void tools::CrossWindows::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const {
  // ...
  default:
    D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str();

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

void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const {
  // ...
  if (const char *LDMOption = getLDMOption(ToolChain.getTriple(), Args)) {
  // ...
  } else {
    D.Diag(diag::err_target_unknown_triple) << Triple.str();

clang/lib/Driver/ToolChains/MinGW.cpp (line 138)

void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const {
  // ...
  default:
    D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str();

clang/tools/driver/cc1as_main.cpp (line 389)

static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) {
  // ...
  if (!TheTarget)
    return Diags.Report(diag::err_target_unknown_triple) << Opts.Triple;

clang/tools/driver/cc1as_main.cpp (line 573)

static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, DiagnosticsEngine &Diags) {
  // ...
  if (!TAP)
    Failed = Diags.Report(diag::err_target_unknown_triple) << Opts.Triple;

clang/unittests/Basic/DiagnosticTest.cpp (line 41)

// Check that DiagnosticErrorTrap works with SuppressAllDiagnostics.
TEST(DiagnosticTest, suppressAndTrap) {
  // ...
  {
    // ...
    Diags.Report(diag::err_target_unknown_triple) << "unknown";