CINXE.COM
C / C++ Rules | Bazel
<!doctype html> <html lang="en" dir="ltr"> <head> <meta name="google-signin-client-id" content="157101835696-ooapojlodmuabs2do2vuhhnf90bccmoi.apps.googleusercontent.com"> <meta name="google-signin-scope" content="profile email https://www.googleapis.com/auth/developerprofiles https://www.googleapis.com/auth/developerprofiles.award"> <meta property="og:site_name" content="Bazel"> <meta property="og:type" content="website"><meta name="theme-color" content="#0c713a"><meta charset="utf-8"> <meta content="IE=Edge" http-equiv="X-UA-Compatible"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="manifest" href="/_pwa/bazel/manifest.json" crossorigin="use-credentials"> <link rel="preconnect" href="//www.gstatic.com" crossorigin> <link rel="preconnect" href="//fonts.gstatic.com" crossorigin> <link rel="preconnect" href="//fonts.googleapis.com" crossorigin> <link rel="preconnect" href="//apis.google.com" crossorigin> <link rel="preconnect" href="//www.google-analytics.com" crossorigin><link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,400,400italic,500,500italic,700,700italic|Roboto+Mono:400,500,700&display=swap"> <link rel="stylesheet" href="//fonts.googleapis.com/css2?family=Material+Icons&family=Material+Symbols+Outlined&display=block"><link rel="stylesheet" href="https://www.gstatic.com/devrel-devsite/prod/v38a693baeb774512feb42f10aac8f755d8791ed41119b5be7a531f8e16f8279f/bazel/css/app.css"> <link rel="shortcut icon" href="https://www.gstatic.com/devrel-devsite/prod/v38a693baeb774512feb42f10aac8f755d8791ed41119b5be7a531f8e16f8279f/bazel/images/favicon-prod.png"> <link rel="apple-touch-icon" href="https://www.gstatic.com/devrel-devsite/prod/v38a693baeb774512feb42f10aac8f755d8791ed41119b5be7a531f8e16f8279f/bazel/images/touchicon-180.png"><link rel="canonical" href="https://bazel.build/reference/be/c-cpp"><link rel="search" type="application/opensearchdescription+xml" title="Bazel" href="https://bazel.build/s/opensearch.xml"> <link rel="alternate" hreflang="en" href="https://bazel.build/reference/be/c-cpp" /><link rel="alternate" hreflang="x-default" href="https://bazel.build/reference/be/c-cpp" /><link rel="alternate" hreflang="zh-Hans" href="https://bazel.build/reference/be/c-cpp?hl=zh-cn" /><link rel="alternate" hreflang="zh-Hant" href="https://bazel.build/reference/be/c-cpp?hl=zh-tw" /><link rel="alternate" hreflang="hi" href="https://bazel.build/reference/be/c-cpp?hl=hi" /><link rel="alternate" hreflang="id" href="https://bazel.build/reference/be/c-cpp?hl=id" /><link rel="alternate" hreflang="ja" href="https://bazel.build/reference/be/c-cpp?hl=ja" /><link rel="alternate" hreflang="ko" href="https://bazel.build/reference/be/c-cpp?hl=ko" /><link rel="alternate" hreflang="pt-BR" href="https://bazel.build/reference/be/c-cpp?hl=pt-br" /><link rel="alternate" hreflang="es-419" href="https://bazel.build/reference/be/c-cpp?hl=es-419" /><link rel="alternate" hreflang="th" href="https://bazel.build/reference/be/c-cpp?hl=th" /><link rel="alternate" hreflang="tr" href="https://bazel.build/reference/be/c-cpp?hl=tr" /><link rel="alternate" hreflang="vi" href="https://bazel.build/reference/be/c-cpp?hl=vi" /><link rel="alternate" hreflang="en-cn" href="https://bazel.google.cn/reference/be/c-cpp" /><link rel="alternate" hreflang="x-default" href="https://bazel.google.cn/reference/be/c-cpp" /><link rel="alternate" hreflang="zh-Hans-cn" href="https://bazel.google.cn/reference/be/c-cpp?hl=zh-cn" /><link rel="alternate" hreflang="zh-Hant-cn" href="https://bazel.google.cn/reference/be/c-cpp?hl=zh-tw" /><link rel="alternate" hreflang="hi-cn" href="https://bazel.google.cn/reference/be/c-cpp?hl=hi" /><link rel="alternate" hreflang="id-cn" href="https://bazel.google.cn/reference/be/c-cpp?hl=id" /><link rel="alternate" hreflang="ja-cn" href="https://bazel.google.cn/reference/be/c-cpp?hl=ja" /><link rel="alternate" hreflang="ko-cn" href="https://bazel.google.cn/reference/be/c-cpp?hl=ko" /><link rel="alternate" hreflang="pt-BR-cn" href="https://bazel.google.cn/reference/be/c-cpp?hl=pt-br" /><link rel="alternate" hreflang="es-419-cn" href="https://bazel.google.cn/reference/be/c-cpp?hl=es-419" /><link rel="alternate" hreflang="th-cn" href="https://bazel.google.cn/reference/be/c-cpp?hl=th" /><link rel="alternate" hreflang="tr-cn" href="https://bazel.google.cn/reference/be/c-cpp?hl=tr" /><link rel="alternate" hreflang="vi-cn" href="https://bazel.google.cn/reference/be/c-cpp?hl=vi" /><title>C / C++ Rules | Bazel</title> <meta property="og:title" content="C / C++ Rules | Bazel"><meta property="og:url" content="https://bazel.build/reference/be/c-cpp"><meta property="og:locale" content="en"><script type="application/ld+json"> { "@context": "https://schema.org", "@type": "Article", "headline": "C / C++ Rules" } </script> <link rel="stylesheet" href="/extras.css"></head> <body class="" template="page" theme="bazel-theme" type="article" layout="docs" display-toc pending> <devsite-progress type="indeterminate" id="app-progress"></devsite-progress> <a href="#main-content" class="skip-link button"> Skip to main content </a> <section class="devsite-wrapper"> <devsite-cookie-notification-bar></devsite-cookie-notification-bar><devsite-header role="banner"> <div class="devsite-header--inner nocontent"> <div class="devsite-top-logo-row-wrapper-wrapper"> <div class="devsite-top-logo-row-wrapper"> <div class="devsite-top-logo-row"> <button type="button" id="devsite-hamburger-menu" class="devsite-header-icon-button button-flat material-icons gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Navigation menu button" visually-hidden aria-label="Open menu"> </button> <div class="devsite-product-name-wrapper"> <a href="/" class="devsite-site-logo-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Site logo" track-type="globalNav" track-name="bazel" track-metadata-position="nav" track-metadata-eventDetail="nav"> <picture> <img src="https://www.gstatic.com/devrel-devsite/prod/v38a693baeb774512feb42f10aac8f755d8791ed41119b5be7a531f8e16f8279f/bazel/images/lockup.svg" class="devsite-site-logo" alt="Bazel"> </picture> </a> <span class="devsite-product-name"> <ul class="devsite-breadcrumb-list" > <li class="devsite-breadcrumb-item "> </li> </ul> </span> </div> <div class="devsite-top-logo-row-middle"> <div class="devsite-header-upper-tabs"> <devsite-tabs class="upper-tabs"> <nav class="devsite-tabs-wrapper" aria-label="Upper tabs"> <tab > <a href="https://bazel.build/about" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/about" track-type="nav" track-metadata-position="nav - about bazel" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: About Bazel" track-name="about bazel" > About Bazel </a> </tab> <tab > <a href="https://bazel.build/start" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/start" track-type="nav" track-metadata-position="nav - getting started" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Getting started" track-name="getting started" > Getting started </a> </tab> <tab > <a href="https://bazel.build/docs" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/docs" track-type="nav" track-metadata-position="nav - user guide" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: User guide" track-name="user guide" > User guide </a> </tab> <tab class="devsite-active"> <a href="https://bazel.build/reference" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/reference" track-type="nav" track-metadata-position="nav - reference" track-metadata-module="primary nav" aria-label="Reference, selected" data-category="Site-Wide Custom Events" data-label="Tab: Reference" track-name="reference" > Reference </a> </tab> <tab > <a href="https://bazel.build/extending" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/extending" track-type="nav" track-metadata-position="nav - extending" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Extending" track-name="extending" > Extending </a> </tab> <tab > <a href="https://bazel.build/community" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/community" track-type="nav" track-metadata-position="nav - community" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Community" track-name="community" > Community </a> </tab> <tab class="devsite-dropdown "> <a href="https://bazel.build/versions" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/versions" track-type="nav" track-metadata-position="nav - versioned docs" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Versioned docs" track-name="versioned docs" > Versioned docs </a> <button aria-haspopup="menu" aria-expanded="false" aria-label="Dropdown menu for Versioned docs" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions" track-metadata-position="nav - versioned docs" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Versioned docs" track-name="versioned docs" class="devsite-tabs-dropdown-toggle devsite-icon devsite-icon-arrow-drop-down"></button> <div class="devsite-tabs-dropdown" role="menu" aria-label="submenu" hidden> <div class="devsite-tabs-dropdown-content"> <div class="devsite-tabs-dropdown-column "> <ul class="devsite-tabs-dropdown-section "> <li class="devsite-nav-item"> <a href="https://bazel.build/versions/8.1.0" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions/8.1.0" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> 8.1 </div> </a> </li> <li class="devsite-nav-item"> <a href="https://bazel.build/versions/8.0.0" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions/8.0.0" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> 8.0 </div> </a> </li> <li class="devsite-nav-item"> <a href="https://bazel.build/versions/7.4.0" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions/7.4.0" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> 7.4 </div> </a> </li> <li class="devsite-nav-item"> <a href="https://bazel.build/versions/7.0.0" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions/7.0.0" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> 7.0 </div> </a> </li> <li class="devsite-nav-item"> <a href="https://bazel.build/versions/6.5.0" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions/6.5.0" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> 6.5 </div> </a> </li> <li class="devsite-nav-item"> <a href="https://docs.bazel.build/versions/5.4.1/bazel-overview.html" track-type="nav" track-metadata-eventdetail="https://docs.bazel.build/versions/5.4.1/bazel-overview.html" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> 5.4.1 </div> </a> </li> </ul> </div> <div class="devsite-tabs-dropdown-column "> <ul class="devsite-tabs-dropdown-section "> <li class="devsite-nav-item"> <a href="https://bazel.build/" track-type="nav" track-metadata-eventdetail="https://bazel.build/" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> Nightly </div> </a> </li> <li class="devsite-nav-item"> <a href="https://bazel.build/versions" track-type="nav" track-metadata-eventdetail="https://bazel.build/versions" track-metadata-position="nav - versioned docs" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> More… </div> </a> </li> </ul> </div> </div> </div> </tab> </nav> </devsite-tabs> </div> <devsite-search enable-signin enable-search enable-suggestions enable-query-completion project-name="Bazel" tenant-name="Bazel" > <form class="devsite-search-form" action="https://bazel.build/s/results" method="GET"> <div class="devsite-search-container"> <button type="button" search-open class="devsite-search-button devsite-header-icon-button button-flat material-icons" aria-label="Open search"></button> <div class="devsite-searchbox"> <input aria-activedescendant="" aria-autocomplete="list" aria-label="Search" aria-expanded="false" aria-haspopup="listbox" autocomplete="off" class="devsite-search-field devsite-search-query" name="q" placeholder="Search" role="combobox" type="text" value="" > <div class="devsite-search-image material-icons" aria-hidden="true"> </div> <div class="devsite-search-shortcut-icon-container" aria-hidden="true"> <kbd class="devsite-search-shortcut-icon">/</kbd> </div> </div> </div> </form> <button type="button" search-close class="devsite-search-button devsite-header-icon-button button-flat material-icons" aria-label="Close search"></button> </devsite-search> </div> <devsite-language-selector> <ul role="presentation"> <li role="presentation"> <a role="menuitem" lang="en" >English</a> </li> <li role="presentation"> <a role="menuitem" lang="es_419" >Español – América Latina</a> </li> <li role="presentation"> <a role="menuitem" lang="id" >Indonesia</a> </li> <li role="presentation"> <a role="menuitem" lang="pt_br" >Português – Brasil</a> </li> <li role="presentation"> <a role="menuitem" lang="vi" >Tiếng Việt</a> </li> <li role="presentation"> <a role="menuitem" lang="tr" >Türkçe</a> </li> <li role="presentation"> <a role="menuitem" lang="hi" >हिंदी</a> </li> <li role="presentation"> <a role="menuitem" lang="th" >ภาษาไทย</a> </li> <li role="presentation"> <a role="menuitem" lang="zh_cn" >中文 – 简体</a> </li> <li role="presentation"> <a role="menuitem" lang="zh_tw" >中文 – 繁體</a> </li> <li role="presentation"> <a role="menuitem" lang="ja" >日本語</a> </li> <li role="presentation"> <a role="menuitem" lang="ko" >한국어</a> </li> </ul> </devsite-language-selector> <a class="devsite-header-link devsite-top-button button gc-analytics-event" href="//github.com/bazelbuild/bazel/" data-category="Site-Wide Custom Events" data-label="Site header link" > GitHub </a> <devsite-user enable-profiles id="devsite-user"> <span class="button devsite-top-button" aria-hidden="true" visually-hidden>Sign in</span> </devsite-user> </div> </div> </div> <div class="devsite-collapsible-section "> <div class="devsite-header-background"> <div class="devsite-product-id-row" > <div class="devsite-product-description-row"> <ul class="devsite-breadcrumb-list" > <li class="devsite-breadcrumb-item "> <a href="https://bazel.build/reference" class="devsite-breadcrumb-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Lower Header" data-value="1" track-type="globalNav" track-name="breadcrumb" track-metadata-position="1" track-metadata-eventdetail="" > Searchable reference documents generated from Bazel's code </a> </li> </ul> </div> </div> <div class="devsite-doc-set-nav-row"> <devsite-tabs class="lower-tabs"> <nav class="devsite-tabs-wrapper" aria-label="Lower tabs"> <tab class="devsite-active"> <a href="https://bazel.build/reference/be/overview" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/reference/be/overview" track-type="nav" track-metadata-position="nav - build encyclopedia" track-metadata-module="primary nav" aria-label="Build encyclopedia, selected" data-category="Site-Wide Custom Events" data-label="Tab: Build encyclopedia" track-name="build encyclopedia" > Build encyclopedia </a> </tab> <tab > <a href="https://bazel.build/reference/command-line-reference" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/reference/command-line-reference" track-type="nav" track-metadata-position="nav - command line reference" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Command line reference" track-name="command line reference" > Command line reference </a> </tab> <tab > <a href="https://bazel.build/query/language" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/query/language" track-type="nav" track-metadata-position="nav - query language" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Query language" track-name="query language" > Query language </a> </tab> <tab > <a href="https://bazel.build/reference/glossary" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/reference/glossary" track-type="nav" track-metadata-position="nav - glossary" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Glossary" track-name="glossary" > Glossary </a> </tab> <tab > <a href="https://bazel.build/reference/flag-cheatsheet" class="devsite-tabs-content gc-analytics-event " track-metadata-eventdetail="https://bazel.build/reference/flag-cheatsheet" track-type="nav" track-metadata-position="nav - flag cheatsheet" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Flag cheatsheet" track-name="flag cheatsheet" > Flag cheatsheet </a> </tab> </nav> </devsite-tabs> </div> </div> </div> </div> </devsite-header> <devsite-book-nav scrollbars > <div class="devsite-book-nav-filter" > <span class="filter-list-icon material-icons" aria-hidden="true"></span> <input type="text" placeholder="Filter" aria-label="Type to filter" role="searchbox"> <span class="filter-clear-button hidden" data-title="Clear filter" aria-label="Clear filter" role="button" tabindex="0"></span> </div> <nav class="devsite-book-nav devsite-nav nocontent" aria-label="Side menu"> <div class="devsite-mobile-header"> <button type="button" id="devsite-close-nav" class="devsite-header-icon-button button-flat material-icons gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Close navigation" aria-label="Close navigation"> </button> <div class="devsite-product-name-wrapper"> <a href="/" class="devsite-site-logo-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Site logo" track-type="globalNav" track-name="bazel" track-metadata-position="nav" track-metadata-eventDetail="nav"> <picture> <img src="https://www.gstatic.com/devrel-devsite/prod/v38a693baeb774512feb42f10aac8f755d8791ed41119b5be7a531f8e16f8279f/bazel/images/lockup.svg" class="devsite-site-logo" alt="Bazel"> </picture> </a> <span class="devsite-product-name"> <ul class="devsite-breadcrumb-list" > <li class="devsite-breadcrumb-item "> </li> </ul> </span> </div> </div> <div class="devsite-book-nav-wrapper"> <div class="devsite-mobile-nav-top"> <ul class="devsite-nav-list"> <li class="devsite-nav-item"> <a href="/about" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: About Bazel" track-name="about bazel" data-category="Site-Wide Custom Events" data-label="Responsive Tab: About Bazel" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > About Bazel </span> </a> </li> <li class="devsite-nav-item"> <a href="/start" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Getting started" track-name="getting started" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Getting started" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Getting started </span> </a> </li> <li class="devsite-nav-item"> <a href="/docs" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: User guide" track-name="user guide" data-category="Site-Wide Custom Events" data-label="Responsive Tab: User guide" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > User guide </span> </a> </li> <li class="devsite-nav-item"> <a href="/reference" class="devsite-nav-title gc-analytics-event devsite-nav-active" data-category="Site-Wide Custom Events" data-label="Tab: Reference" track-name="reference" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Reference" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Reference </span> </a> <ul class="devsite-nav-responsive-tabs"> <li class="devsite-nav-item"> <a href="/reference/be/overview" class="devsite-nav-title gc-analytics-event devsite-nav-has-children devsite-nav-active" data-category="Site-Wide Custom Events" data-label="Tab: Build encyclopedia" track-name="build encyclopedia" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Build encyclopedia" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip menu="_book"> Build encyclopedia </span> <span class="devsite-nav-icon material-icons" data-icon="forward" menu="_book"> </span> </a> </li> <li class="devsite-nav-item"> <a href="/reference/command-line-reference" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Command line reference" track-name="command line reference" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Command line reference" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Command line reference </span> </a> </li> <li class="devsite-nav-item"> <a href="/query/language" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Query language" track-name="query language" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Query language" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Query language </span> </a> </li> <li class="devsite-nav-item"> <a href="/reference/glossary" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Glossary" track-name="glossary" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Glossary" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Glossary </span> </a> </li> <li class="devsite-nav-item"> <a href="/reference/flag-cheatsheet" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Flag cheatsheet" track-name="flag cheatsheet" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Flag cheatsheet" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Flag cheatsheet </span> </a> </li> </ul> </li> <li class="devsite-nav-item"> <a href="/extending" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Extending" track-name="extending" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Extending" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Extending </span> </a> </li> <li class="devsite-nav-item"> <a href="/community" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Community" track-name="community" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Community" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Community </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Versioned docs" track-name="versioned docs" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Versioned docs" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Versioned docs </span> </a> <ul class="devsite-nav-responsive-tabs devsite-nav-has-menu "> <li class="devsite-nav-item"> <span class="devsite-nav-title" tooltip data-category="Site-Wide Custom Events" data-label="Tab: Versioned docs" track-name="versioned docs" > <span class="devsite-nav-text" tooltip menu="Versioned docs"> More </span> <span class="devsite-nav-icon material-icons" data-icon="forward" menu="Versioned docs"> </span> </span> </li> </ul> </li> <li class="devsite-nav-item"> <a href="//github.com/bazelbuild/bazel/" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: GitHub" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > GitHub </span> </a> </li> </ul> </div> <div class="devsite-mobile-nav-bottom"> <ul class="devsite-nav-list" menu="_book"> <li class="devsite-nav-item devsite-nav-expandable"><div class="devsite-expandable-nav"> <a class="devsite-nav-toggle" aria-hidden="true"></a><div class="devsite-nav-title devsite-nav-title-no-path" tabindex="0" role="button"> <span class="devsite-nav-text" tooltip>Build encyclopedia</span> </div><ul class="devsite-nav-section"><li class="devsite-nav-item"><a href="/reference/be/overview" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/overview" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/overview" ><span class="devsite-nav-text" tooltip>Overview</span></a></li><li class="devsite-nav-item"><a href="/reference/be/common-definitions" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/common-definitions" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/common-definitions" ><span class="devsite-nav-text" tooltip>Common definitions</span></a></li><li class="devsite-nav-item"><a href="/reference/be/make-variables" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/make-variables" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/make-variables" ><span class="devsite-nav-text" tooltip>Make variables</span></a></li><li class="devsite-nav-item"><a href="/reference/be/functions" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/functions" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/functions" ><span class="devsite-nav-text" tooltip>Functions</span></a></li><li class="devsite-nav-item devsite-nav-expandable"><div class="devsite-expandable-nav"> <a class="devsite-nav-toggle" aria-hidden="true"></a><div class="devsite-nav-title devsite-nav-title-no-path" tabindex="0" role="button"> <span class="devsite-nav-text" tooltip>Core rules</span> </div><ul class="devsite-nav-section"><li class="devsite-nav-item"><a href="/reference/be/extra-actions" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/extra-actions" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/extra-actions" ><span class="devsite-nav-text" tooltip>Extra Actions</span></a></li><li class="devsite-nav-item"><a href="/reference/be/general" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/general" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/general" ><span class="devsite-nav-text" tooltip>General</span></a></li><li class="devsite-nav-item"><a href="/reference/be/platforms-and-toolchains" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/platforms-and-toolchains" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/platforms-and-toolchains" ><span class="devsite-nav-text" tooltip>Platforms and Toolchains</span></a></li><li class="devsite-nav-item"><a href="/reference/be/workspace" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/workspace" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/workspace" ><span class="devsite-nav-text" tooltip>Workspace</span></a></li></ul></div></li><li class="devsite-nav-item devsite-nav-expandable"><div class="devsite-expandable-nav"> <a class="devsite-nav-toggle" aria-hidden="true"></a><div class="devsite-nav-title devsite-nav-title-no-path" tabindex="0" role="button"> <span class="devsite-nav-text" tooltip>Language Specific rules</span> </div><ul class="devsite-nav-section"><li class="devsite-nav-item"><a href="/reference/be/c-cpp" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/c-cpp" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/c-cpp" ><span class="devsite-nav-text" tooltip>C / C++</span></a></li><li class="devsite-nav-item"><a href="/reference/be/java" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/java" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/java" ><span class="devsite-nav-text" tooltip>Java</span></a></li><li class="devsite-nav-item"><a href="/reference/be/objective-c" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/objective-c" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/objective-c" ><span class="devsite-nav-text" tooltip>Objective-C</span></a></li><li class="devsite-nav-item"><a href="/reference/be/protocol-buffer" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/protocol-buffer" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/protocol-buffer" ><span class="devsite-nav-text" tooltip>Protocol Buffer</span></a></li><li class="devsite-nav-item"><a href="/reference/be/python" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/python" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/python" ><span class="devsite-nav-text" tooltip>Python</span></a></li><li class="devsite-nav-item"><a href="/reference/be/shell" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/be/shell" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/be/shell" ><span class="devsite-nav-text" tooltip>Shell</span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_appengine" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_appengine" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_appengine" ><span class="devsite-nav-text" tooltip>AppEngine</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_apple" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_apple" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_apple" ><span class="devsite-nav-text" tooltip>Apple (Swift, iOS, macOS, tvOS, visionOS, watchOS)</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_dotnet" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_dotnet" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_dotnet" ><span class="devsite-nav-text" tooltip>C#</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_d" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_d" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_d" ><span class="devsite-nav-text" tooltip>D</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_docker" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_docker" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_docker" ><span class="devsite-nav-text" tooltip>Docker</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_groovy" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_groovy" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_groovy" ><span class="devsite-nav-text" tooltip>Groovy</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_go" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_go" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_go" ><span class="devsite-nav-text" tooltip>Go</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_closure" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_closure" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_closure" ><span class="devsite-nav-text" tooltip>JavaScript (Closure)</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_jsonnet" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_jsonnet" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_jsonnet" ><span class="devsite-nav-text" tooltip>Jsonnet</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_rust" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_rust" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_rust" ><span class="devsite-nav-text" tooltip>Rust</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_sass" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_sass" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_sass" ><span class="devsite-nav-text" tooltip>Sass</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li><li class="devsite-nav-item devsite-nav-external"><a href="https://github.com/bazelbuild/rules_scala" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: https://github.com/bazelbuild/rules_scala" track-type="bookNav" track-name="click" track-metadata-eventdetail="https://github.com/bazelbuild/rules_scala" ><span class="devsite-nav-text" tooltip>Scala</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li></ul></div></li></ul></div></li> <li class="devsite-nav-item"><a href="/reference/test-encyclopedia" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /reference/test-encyclopedia" track-type="bookNav" track-name="click" track-metadata-eventdetail="/reference/test-encyclopedia" ><span class="devsite-nav-text" tooltip>Test encyclopedia</span></a></li> </ul> <ul class="devsite-nav-list" menu="Versioned docs" aria-label="Side menu" hidden> <li class="devsite-nav-item"> <a href="/versions/8.1.0" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: 8.1" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > 8.1 </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions/8.0.0" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: 8.0" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > 8.0 </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions/7.4.0" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: 7.4" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > 7.4 </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions/7.0.0" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: 7.0" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > 7.0 </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions/6.5.0" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: 6.5" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > 6.5 </span> </a> </li> <li class="devsite-nav-item"> <a href="https://docs.bazel.build/versions/5.4.1/bazel-overview.html" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: 5.4.1" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > 5.4.1 </span> </a> </li> <li class="devsite-nav-item"> <a href="/" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: Nightly" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Nightly </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: More…" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > More… </span> </a> </li> </ul> </div> </div> </nav> </devsite-book-nav> <section id="gc-wrapper"> <main role="main" id="main-content" class="devsite-main-content" has-book-nav has-sidebar > <div class="devsite-sidebar"> <div class="devsite-sidebar-content"> <devsite-toc class="devsite-nav" role="navigation" aria-label="On this page" depth="2" scrollbars ></devsite-toc> <devsite-recommendations-sidebar class="nocontent devsite-nav"> </devsite-recommendations-sidebar> </div> </div> <devsite-content> <article class="devsite-article"> <div class="devsite-article-meta nocontent" role="navigation"> <ul class="devsite-breadcrumb-list" aria-label="Breadcrumb"> <li class="devsite-breadcrumb-item "> <a href="https://bazel.build/" class="devsite-breadcrumb-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Breadcrumbs" data-value="1" track-type="globalNav" track-name="breadcrumb" track-metadata-position="1" track-metadata-eventdetail="Bazel" > Bazel </a> </li> <li class="devsite-breadcrumb-item "> <div class="devsite-breadcrumb-guillemet material-icons" aria-hidden="true"></div> <a href="https://bazel.build/reference" class="devsite-breadcrumb-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Breadcrumbs" data-value="2" track-type="globalNav" track-name="breadcrumb" track-metadata-position="2" track-metadata-eventdetail="" > Reference </a> </li> <li class="devsite-breadcrumb-item "> <div class="devsite-breadcrumb-guillemet material-icons" aria-hidden="true"></div> <a href="https://bazel.build/reference/be/overview" class="devsite-breadcrumb-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Breadcrumbs" data-value="3" track-type="globalNav" track-name="breadcrumb" track-metadata-position="3" track-metadata-eventdetail="" > Build encyclopedia </a> </li> </ul> <devsite-thumb-rating position="header"> </devsite-thumb-rating> </div> <devsite-feedback position="header" project-name="Bazel" product-id="5052038" bucket="https-bazel-build" context="" version="t-devsite-webserver-20250211-r00-rc00.466928218230179509" data-label="Send Feedback Button" track-type="feedback" track-name="sendFeedbackLink" track-metadata-position="header" class="nocontent" project-icon="https://www.gstatic.com/devrel-devsite/prod/v38a693baeb774512feb42f10aac8f755d8791ed41119b5be7a531f8e16f8279f/bazel/images/touchicon-180.png" > <button> Send feedback </button> </devsite-feedback> <h1 class="devsite-page-title" tabindex="-1"> C / C++ Rules </h1> <devsite-feature-tooltip ack-key="AckCollectionsBookmarkTooltipDismiss" analytics-category="Site-Wide Custom Events" analytics-action-show="Callout Profile displayed" analytics-action-close="Callout Profile dismissed" analytics-label="Create Collection Callout" class="devsite-page-bookmark-tooltip nocontent" dismiss-button="true" id="devsite-collections-dropdown" dismiss-button-text="Dismiss" close-button-text="Got it"> <devsite-bookmark></devsite-bookmark> <span slot="popout-heading"> Stay organized with collections </span> <span slot="popout-contents"> Save and categorize content based on your preferences. </span> </devsite-feature-tooltip> <div class="devsite-page-title-meta"><devsite-view-release-notes></devsite-view-release-notes></div> <devsite-toc class="devsite-nav" depth="2" devsite-toc-embedded > </devsite-toc> <div class="devsite-article-body clearfix "> <!-- This document is synchronized with Bazel releases. To edit, submit changes to the Bazel source code. --> <!-- Generated by //src/main/java/com/google/devtools/build/docgen:build-encyclopedia.zip --> <html> <body> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/issues/new?title=%5Bbazel.build%5D+Problem+with+/reference/be/c-cpp&template=doc_issue.yml&link=https%3A%2F%2Fbazel.build/reference/be/c-cpp" target="_blank"> Report an issue<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/tree/master/src/main/java/com/google/devtools/build/docgen/templates/be/rules.vm" target="_blank"> View source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <span style="float: right; line-height: 36px"> <strong>Nightly</strong> <!-- The lines below are updated by //scripts/docs:gen_new_toc --> <!-- BEGIN_VERSION_INDICATOR --> <a href="/versions/8.1.0/reference/be/c-cpp">8.1</a> · <a href="/versions/8.0.0/reference/be/c-cpp">8.0</a> · <a href="/versions/7.5.0/reference/be/c-cpp">7.5</a> · <a href="/versions/7.4.0/reference/be/c-cpp">7.4</a> · <a href="/versions/7.3.0/reference/be/c-cpp">7.3</a> · <a href="/versions/7.2.0/reference/be/c-cpp">7.2</a> <!-- END_VERSION_INDICATOR --> </span> <p/> <h2 id="rules" data-text="Rules" tabindex="-1">Rules</h2> <ul> <li> <a href="#cc_binary"> cc_binary </a> </li> <li> <a href="#cc_import"> cc_import </a> </li> <li> <a href="#cc_library"> cc_library </a> </li> <li> <a href="#cc_shared_library"> cc_shared_library </a> </li> <li> <a href="#cc_static_library"> cc_static_library </a> </li> <li> <a href="#cc_test"> cc_test </a> </li> <li> <a href="#cc_toolchain"> cc_toolchain </a> </li> <li> <a href="#cc_toolchain_suite"> cc_toolchain_suite </a> </li> <li> <a href="#fdo_prefetch_hints"> fdo_prefetch_hints </a> </li> <li> <a href="#fdo_profile"> fdo_profile </a> </li> <li> <a href="#memprof_profile"> memprof_profile </a> </li> <li> <a href="#propeller_optimize"> propeller_optimize </a> </li> </ul> <h2 id="cc_binary" data-text=" cc_binary " tabindex="-1"> cc_binary </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/blob/master/src/main/starlark/builtins_bzl/common/cc/cc_binary.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>cc_binary(<a href="#cc_binary.name">name</a>, <a href="#cc_binary.deps">deps</a>, <a href="#cc_binary.srcs">srcs</a>, <a href="#cc_binary.data">data</a>, <a href="#cc_binary.additional_linker_inputs">additional_linker_inputs</a>, <a href="/reference/be/common-definitions#binary.args">args</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="#cc_binary.conlyopts">conlyopts</a>, <a href="#cc_binary.copts">copts</a>, <a href="#cc_binary.cxxopts">cxxopts</a>, <a href="#cc_binary.defines">defines</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.distribs">distribs</a>, <a href="#cc_binary.dynamic_deps">dynamic_deps</a>, <a href="/reference/be/common-definitions#binary.env">env</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="#cc_binary.hdrs_check">hdrs_check</a>, <a href="#cc_binary.includes">includes</a>, <a href="/reference/be/common-definitions#typical.licenses">licenses</a>, <a href="#cc_binary.link_extra_lib">link_extra_lib</a>, <a href="#cc_binary.linkopts">linkopts</a>, <a href="#cc_binary.linkshared">linkshared</a>, <a href="#cc_binary.linkstatic">linkstatic</a>, <a href="#cc_binary.local_defines">local_defines</a>, <a href="#cc_binary.malloc">malloc</a>, <a href="#cc_binary.module_interfaces">module_interfaces</a>, <a href="#cc_binary.nocopts">nocopts</a>, <a href="/reference/be/common-definitions#binary.output_licenses">output_licenses</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="#cc_binary.reexport_deps">reexport_deps</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="#cc_binary.stamp">stamp</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>, <a href="#cc_binary.win_def_file">win_def_file</a>)</pre></devsite-code> <p>It produces an executable binary.</p> <br/>The <code translate="no" dir="ltr">name</code> of the target should be the same as the name of the source file that is the main entry point of the application (minus the extension). For example, if your entry point is in <code translate="no" dir="ltr">main.cc</code>, then your name should be <code translate="no" dir="ltr">main</code>. <h4 id="implicit-output-targets" data-text="Implicit output targets" tabindex="-1">Implicit output targets</h4> <ul> <li><code translate="no" dir="ltr"><var translate="no">name</var>.stripped</code> (only built if explicitly requested): A stripped version of the binary. <code translate="no" dir="ltr">strip -g</code> is run on the binary to remove debug symbols. Additional strip options can be provided on the command line using <code translate="no" dir="ltr">--stripopt=-foo</code>.</li> <li><code translate="no" dir="ltr"><var translate="no">name</var>.dwp</code> (only built if explicitly requested): If <a href="https://gcc.gnu.org/wiki/DebugFission">Fission</a> is enabled: a debug information package file suitable for debugging remotely deployed binaries. Else: an empty file.</li> </ul> <h3 id="cc_binary_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="cc_binary.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="cc_binary.deps"> <code translate="no" dir="ltr">deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of other libraries to be linked in to the binary target. <p>These can be <code translate="no" dir="ltr">cc_library</code> or <code translate="no" dir="ltr">objc_library</code> targets.</p> It is also allowed to put linker scripts (.lds) into deps, and reference them in <a href="#cc_binary.linkopts">linkopts</a>. </td> </tr> <tr> <td id="cc_binary.srcs"> <code translate="no" dir="ltr">srcs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of C and C++ files that are processed to create the library target. These are C/C++ source and header files, either non-generated (normal source code) or generated. <p>All <code translate="no" dir="ltr">.cc</code>, <code translate="no" dir="ltr">.c</code>, and <code translate="no" dir="ltr">.cpp</code> files will be compiled. These might be generated files: if a named file is in the <code translate="no" dir="ltr">outs</code> of some other rule, this <code translate="no" dir="ltr">cc_library</code> will automatically depend on that other rule. </p> <p>Pure assembler files (.s, .asm) are not preprocessed and are typically built using the assembler. Preprocessed assembly files (.S) are preprocessed and are typically built using the C/C++ compiler. </p> <p>A <code translate="no" dir="ltr">.h</code> file will not be compiled, but will be available for inclusion by sources in this rule. Both <code translate="no" dir="ltr">.cc</code> and <code translate="no" dir="ltr">.h</code> files can directly include headers listed in these <code translate="no" dir="ltr">srcs</code> or in the <code translate="no" dir="ltr">hdrs</code> of this rule or any rule listed in the <code translate="no" dir="ltr">deps</code> argument. </p> <p>All <code translate="no" dir="ltr">#include</code>d files must be mentioned in the <code translate="no" dir="ltr">hdrs</code> attribute of this or referenced <code translate="no" dir="ltr">cc_library</code> rules, or they should be listed in <code translate="no" dir="ltr">srcs</code> if they are private to this library. See <a href="#hdrs">"Header inclusion checking"</a> for a more detailed description. </p> <p><code translate="no" dir="ltr">.so</code>, <code translate="no" dir="ltr">.lo</code>, and <code translate="no" dir="ltr">.a</code> files are pre-compiled files. Your library might have these as <code translate="no" dir="ltr">srcs</code> if it uses third-party code for which we don't have source code. </p> <p>If the <code translate="no" dir="ltr">srcs</code> attribute includes the label of another rule, <code translate="no" dir="ltr">cc_library</code> will use the output files of that rule as source files to compile. This is useful for one-off generation of source code (for more than occasional use, it's better to implement a Starlark rule class and use the <code translate="no" dir="ltr">cc_common</code> API) </p> <p> Permitted <code translate="no" dir="ltr">srcs</code> file types: </p> <ul> <li>C and C++ source files: <code translate="no" dir="ltr">.c</code>, <code translate="no" dir="ltr">.cc</code>, <code translate="no" dir="ltr">.cpp</code>, <code translate="no" dir="ltr">.cxx</code>, <code translate="no" dir="ltr">.c++</code>, <code translate="no" dir="ltr">.C</code></li> <li>C and C++ header files: <code translate="no" dir="ltr">.h</code>, <code translate="no" dir="ltr">.hh</code>, <code translate="no" dir="ltr">.hpp</code>, <code translate="no" dir="ltr">.hxx</code>, <code translate="no" dir="ltr">.inc</code>, <code translate="no" dir="ltr">.inl</code>, <code translate="no" dir="ltr">.H</code></li> <li>Assembler with C preprocessor: <code translate="no" dir="ltr">.S</code></li> <li>Archive: <code translate="no" dir="ltr">.a</code>, <code translate="no" dir="ltr">.pic.a</code></li> <li>"Always link" library: <code translate="no" dir="ltr">.lo</code>, <code translate="no" dir="ltr">.pic.lo</code></li> <li>Shared library, versioned or unversioned: <code translate="no" dir="ltr">.so</code>, <code translate="no" dir="ltr">.so.<i>version</i></code></li> <li>Object file: <code translate="no" dir="ltr">.o</code>, <code translate="no" dir="ltr">.pic.o</code></li> </ul> <p> ... and any rules that produce those files (e.g. <code translate="no" dir="ltr">cc_embed_data</code>). Different extensions denote different programming languages in accordance with gcc convention. </p> </td> </tr> <tr> <td id="cc_binary.data"> <code translate="no" dir="ltr">data</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of files needed by this library at runtime. See general comments about <code translate="no" dir="ltr">data</code> at <a href="/reference/be/common-definitions#typical-attributes">Typical attributes defined by most build rules</a>. <p>If a <code translate="no" dir="ltr">data</code> is the name of a generated file, then this <code translate="no" dir="ltr">cc_library</code> rule automatically depends on the generating rule. </p> <p>If a <code translate="no" dir="ltr">data</code> is a rule name, then this <code translate="no" dir="ltr">cc_library</code> rule automatically depends on that rule, and that rule's <code translate="no" dir="ltr">outs</code> are automatically added to this <code translate="no" dir="ltr">cc_library</code>'s data files. </p> <p>Your C++ code can access these data files like so:</p> <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> const std::string path = devtools_build::GetDataDependencyFilepath( "my/test/data/file"); </code></pre></devsite-code> </td> </tr> <tr> <td id="cc_binary.additional_linker_inputs"> <code translate="no" dir="ltr">additional_linker_inputs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Pass these files to the C++ linker command. <p> For example, compiled Windows .res files can be provided here to be embedded in the binary target. </p> </td> </tr> <tr> <td id="cc_binary.conlyopts"> <code translate="no" dir="ltr">conlyopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Add these options to the C compilation command. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. </td> </tr> <tr> <td id="cc_binary.copts"> <code translate="no" dir="ltr">copts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Add these options to the C/C++ compilation command. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. <p> Each string in this attribute is added in the given order to <code translate="no" dir="ltr">COPTS</code> before compiling the binary target. The flags take effect only for compiling this target, not its dependencies, so be careful about header files included elsewhere. All paths should be relative to the workspace, not to the current package. This attribute should not be needed outside of <code translate="no" dir="ltr">third_party</code>. </p> <p> If the package declares the <a href="/reference/be/functions#package.features">feature</a> <code translate="no" dir="ltr">no_copts_tokenization</code>, Bourne shell tokenization applies only to strings that consist of a single "Make" variable. </p> </td> </tr> <tr> <td id="cc_binary.cxxopts"> <code translate="no" dir="ltr">cxxopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Add these options to the C++ compilation command. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. </td> </tr> <tr> <td id="cc_binary.defines"> <code translate="no" dir="ltr">defines</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> List of defines to add to the compile line. Subject to <a href="/reference/be/make-variables">"Make" variable</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. Each string, which must consist of a single Bourne shell token, is prepended with <code translate="no" dir="ltr">-D</code> and added to the compile command line to this target, as well as to every rule that depends on it. Be very careful, since this may have far-reaching effects. When in doubt, add define values to <a href="#cc_binary.local_defines"><code translate="no" dir="ltr">local_defines</code></a> instead. </td> </tr> <tr> <td id="cc_binary.dynamic_deps"> <code translate="no" dir="ltr">dynamic_deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> These are other <code translate="no" dir="ltr">cc_shared_library</code> dependencies the current target depends on. <p> The <code translate="no" dir="ltr">cc_shared_library</code> implementation will use the list of <code translate="no" dir="ltr">dynamic_deps</code> (transitively, i.e. also the <code translate="no" dir="ltr">dynamic_deps</code> of the current target's <code translate="no" dir="ltr">dynamic_deps</code>) to decide which <code translate="no" dir="ltr">cc_libraries</code> in the transitive <code translate="no" dir="ltr">deps</code> should not be linked in because they are already provided by a different <code translate="no" dir="ltr">cc_shared_library</code>. </td> </tr> <tr> <td id="cc_binary.hdrs_check"> <code translate="no" dir="ltr">hdrs_check</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> Deprecated, no-op. </td> </tr> <tr> <td id="cc_binary.includes"> <code translate="no" dir="ltr">includes</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> List of include dirs to be added to the compile line. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution. Each string is prepended with the package path and passed to the C++ toolchain for expansion via the "include_paths" CROSSTOOL feature. A toolchain running on a POSIX system with typical feature definitions will produce <code translate="no" dir="ltr">-isystem path_to_package/include_entry</code>. This should only be used for third-party libraries that do not conform to the Google style of writing #include statements. Unlike <a href="#cc_binary.copts">COPTS</a>, these flags are added for this rule and every rule that depends on it. (Note: not the rules it depends upon!) Be very careful, since this may have far-reaching effects. When in doubt, add "-I" flags to <a href="#cc_binary.copts">COPTS</a> instead. <p> The added <code translate="no" dir="ltr">include</code> paths will include generated files as well as files in the source tree. </p> </td> </tr> <tr> <td id="cc_binary.link_extra_lib"> <code translate="no" dir="ltr">link_extra_lib</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">"@bazel_tools//tools/cpp:link_extra_lib"</code></p> Control linking of extra libraries. <p> By default, C++ binaries are linked against <code translate="no" dir="ltr">//tools/cpp:link_extra_lib</code>, which by default depends on the label flag <code translate="no" dir="ltr">//tools/cpp:link_extra_libs</code>. Without setting the flag, this library is empty by default. Setting the label flag allows linking optional dependencies, such as overrides for weak symbols, interceptors for shared library functions, or special runtime libraries (for malloc replacements, prefer <code translate="no" dir="ltr">malloc</code> or <code translate="no" dir="ltr">--custom_malloc</code>). Setting this attribute to <code translate="no" dir="ltr">None</code> disables this behaviour. </p> </td> </tr> <tr> <td id="cc_binary.linkopts"> <code translate="no" dir="ltr">linkopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Add these flags to the C++ linker command. Subject to <a href="/reference/be/make-variables">"Make" variable</a> substitution, <a href="/reference/be/common-definitions#sh-tokenization"> Bourne shell tokenization</a> and <a href="/reference/be/common-definitions#label-expansion">label expansion</a>. Each string in this attribute is added to <code translate="no" dir="ltr">LINKOPTS</code> before linking the binary target. <p> Each element of this list that does not start with <code translate="no" dir="ltr">$</code> or <code translate="no" dir="ltr">-</code> is assumed to be the label of a target in <code translate="no" dir="ltr">deps</code>. The list of files generated by that target is appended to the linker options. An error is reported if the label is invalid, or is not declared in <code translate="no" dir="ltr">deps</code>. </p> </td> </tr> <tr> <td id="cc_binary.linkshared"> <code translate="no" dir="ltr">linkshared</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> Create a shared library. To enable this attribute, include <code translate="no" dir="ltr">linkshared=True</code> in your rule. By default this option is off. <p> The presence of this flag means that linking occurs with the <code translate="no" dir="ltr">-shared</code> flag to <code translate="no" dir="ltr">gcc</code>, and the resulting shared library is suitable for loading into for example a Java program. However, for build purposes it will never be linked into the dependent binary, as it is assumed that shared libraries built with a <a href="#cc_binary">cc_binary</a> rule are only loaded manually by other programs, so it should not be considered a substitute for the <a href="#cc_library">cc_library</a> rule. For sake of scalability we recommend avoiding this approach altogether and simply letting <code translate="no" dir="ltr">java_library</code> depend on <code translate="no" dir="ltr">cc_library</code> rules instead. </p> <p> If you specify both <code translate="no" dir="ltr">linkopts=['-static']</code> and <code translate="no" dir="ltr">linkshared=True</code>, you get a single completely self-contained unit. If you specify both <code translate="no" dir="ltr">linkstatic=True</code> and <code translate="no" dir="ltr">linkshared=True</code>, you get a single, mostly self-contained unit. </p> </td> </tr> <tr> <td id="cc_binary.linkstatic"> <code translate="no" dir="ltr">linkstatic</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">True</code></p> For <a href="/reference/be/c-cpp#cc_binary"><code translate="no" dir="ltr">cc_binary</code></a> and <a href="/reference/be/c-cpp#cc_test"><code translate="no" dir="ltr">cc_test</code></a>: link the binary in static mode. For <code translate="no" dir="ltr">cc_library.link_static</code>: see below. <p>By default this option is on for <code translate="no" dir="ltr">cc_binary</code> and off for the rest.</p> <p> If enabled and this is a binary or test, this option tells the build tool to link in <code translate="no" dir="ltr">.a</code>'s instead of <code translate="no" dir="ltr">.so</code>'s for user libraries whenever possible. System libraries such as libc (but <i>not</i> the C/C++ runtime libraries, see below) are still linked dynamically, as are libraries for which there is no static library. So the resulting executable will still be dynamically linked, hence only <i>mostly</i> static. </p> <p> There are really three different ways to link an executable: </p> <ul> <li> STATIC with fully_static_link feature, in which everything is linked statically; e.g. "<code translate="no" dir="ltr">gcc -static foo.o libbar.a libbaz.a -lm</code>".<br/> This mode is enabled by specifying <code translate="no" dir="ltr">fully_static_link</code> in the <a href="/reference/be/common-definitions#features"><code translate="no" dir="ltr">features</code></a> attribute.</li> <li> STATIC, in which all user libraries are linked statically (if a static version is available), but where system libraries (excluding C/C++ runtime libraries) are linked dynamically, e.g. "<code translate="no" dir="ltr">gcc foo.o libfoo.a libbaz.a -lm</code>".<br/> This mode is enabled by specifying <code translate="no" dir="ltr">linkstatic=True</code>.</li> <li> DYNAMIC, in which all libraries are linked dynamically (if a dynamic version is available), e.g. "<code translate="no" dir="ltr">gcc foo.o libfoo.so libbaz.so -lm</code>".<br/> This mode is enabled by specifying <code translate="no" dir="ltr">linkstatic=False</code>.</li> </ul> <p> If the <code translate="no" dir="ltr">linkstatic</code> attribute or <code translate="no" dir="ltr">fully_static_link</code> in <code translate="no" dir="ltr">features</code> is used outside of <code translate="no" dir="ltr">//third_party</code> please include a comment near the rule to explain why. </p> <p> The <code translate="no" dir="ltr">linkstatic</code> attribute has a different meaning if used on a <a href="/reference/be/c-cpp#cc_library"><code translate="no" dir="ltr">cc_library()</code></a> rule. For a C++ library, <code translate="no" dir="ltr">linkstatic=True</code> indicates that only static linking is allowed, so no <code translate="no" dir="ltr">.so</code> will be produced. linkstatic=False does not prevent static libraries from being created. The attribute is meant to control the creation of dynamic libraries. </p> <p> There should be very little code built with <code translate="no" dir="ltr">linkstatic=False</code> in production. If <code translate="no" dir="ltr">linkstatic=False</code>, then the build tool will create symlinks to depended-upon shared libraries in the <code translate="no" dir="ltr">*.runfiles</code> area. </p> </td> </tr> <tr> <td id="cc_binary.local_defines"> <code translate="no" dir="ltr">local_defines</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> List of defines to add to the compile line. Subject to <a href="/reference/be/make-variables">"Make" variable</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. Each string, which must consist of a single Bourne shell token, is prepended with <code translate="no" dir="ltr">-D</code> and added to the compile command line for this target, but not to its dependents. </td> </tr> <tr> <td id="cc_binary.malloc"> <code translate="no" dir="ltr">malloc</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">"@bazel_tools//tools/cpp:malloc"</code></p> Override the default dependency on malloc. <p> By default, C++ binaries are linked against <code translate="no" dir="ltr">//tools/cpp:malloc</code>, which is an empty library so the binary ends up using libc malloc. This label must refer to a <code translate="no" dir="ltr">cc_library</code>. If compilation is for a non-C++ rule, this option has no effect. The value of this attribute is ignored if <code translate="no" dir="ltr">linkshared=True</code> is specified. </p> </td> </tr> <tr> <td id="cc_binary.module_interfaces"> <code translate="no" dir="ltr">module_interfaces</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of files are regarded as C++20 Modules Interface. <p> C++ Standard has no restriction about module interface file extension <ul> <li>Clang use cppm </li> <li>GCC can use any source file extension </li> <li>MSVC use ixx </li> </ul> </p> <p>The use is guarded by the flag <code translate="no" dir="ltr">--experimental_cpp_modules</code>.</p> </td> </tr> <tr> <td id="cc_binary.nocopts"> <code translate="no" dir="ltr">nocopts</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> Remove matching options from the C++ compilation command. Subject to <a href="/reference/be/make-variables">"Make" variable</a> substitution. The value of this attribute is interpreted as a regular expression. Any preexisting <code translate="no" dir="ltr">COPTS</code> that match this regular expression (including values explicitly specified in the rule's <a href="#cc_binary.copts">copts</a> attribute) will be removed from <code translate="no" dir="ltr">COPTS</code> for purposes of compiling this rule. This attribute should not be needed or used outside of <code translate="no" dir="ltr">third_party</code>. The values are not preprocessed in any way other than the "Make" variable substitution. </td> </tr> <tr> <td id="cc_binary.reexport_deps"> <code translate="no" dir="ltr">reexport_deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> </td> </tr> <tr> <td id="cc_binary.stamp"> <code translate="no" dir="ltr">stamp</code> </td> <td> <p>Integer; default is <code translate="no" dir="ltr">-1</code></p> Whether to encode build information into the binary. Possible values: <ul> <li> <code translate="no" dir="ltr">stamp = 1</code>: Always stamp the build information into the binary, even in <a href="/docs/user-manual#flag--stamp"><code translate="no" dir="ltr">--nostamp</code></a> builds. <b>This setting should be avoided</b>, since it potentially kills remote caching for the binary and any downstream actions that depend on it. </li> <li> <code translate="no" dir="ltr">stamp = 0</code>: Always replace build information by constant values. This gives good build result caching. </li> <li> <code translate="no" dir="ltr">stamp = -1</code>: Embedding of build information is controlled by the <a href="/docs/user-manual#flag--stamp"><code translate="no" dir="ltr">--[no]stamp</code></a> flag. </li> </ul> <p>Stamped binaries are <em>not</em> rebuilt unless their dependencies change.</p> </td> </tr> <tr> <td id="cc_binary.win_def_file"> <code translate="no" dir="ltr">win_def_file</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> The Windows DEF file to be passed to linker. <p>This attribute should only be used when Windows is the target platform. It can be used to <a href="https://msdn.microsoft.com/en-us/library/d91k01sh.aspx"> export symbols</a> during linking a shared library.</p> </td> </tr> </tbody> </table> <h2 id="cc_import" data-text=" cc_import " tabindex="-1"> cc_import </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/blob/master/src/main/starlark/builtins_bzl/common/cc/cc_import.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>cc_import(<a href="#cc_import.name">name</a>, <a href="#cc_import.deps">deps</a>, <a href="/reference/be/common-definitions#typical.data">data</a>, <a href="#cc_import.hdrs">hdrs</a>, <a href="#cc_import.alwayslink">alwayslink</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.distribs">distribs</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="#cc_import.includes">includes</a>, <a href="#cc_import.interface_library">interface_library</a>, <a href="#cc_import.linkopts">linkopts</a>, <a href="#cc_import.objects">objects</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="#cc_import.pic_objects">pic_objects</a>, <a href="#cc_import.pic_static_library">pic_static_library</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="#cc_import.shared_library">shared_library</a>, <a href="#cc_import.static_library">static_library</a>, <a href="#cc_import.system_provided">system_provided</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>)</pre></devsite-code> <p> <code translate="no" dir="ltr">cc_import</code> rules allows users to import precompiled C/C++ libraries. </p> <p> The following are the typical use cases: <br/> 1. Linking a static library <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> cc_import( name = "mylib", hdrs = ["mylib.h"], static_library = "libmylib.a", # If alwayslink is turned on, # libmylib.a will be forcely linked into any binary that depends on it. # alwayslink = True, ) </code></pre></devsite-code> 2. Linking a shared library (Unix) <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> cc_import( name = "mylib", hdrs = ["mylib.h"], shared_library = "libmylib.so", ) </code></pre></devsite-code> 3. Linking a shared library with interface library <p>On Unix: <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> cc_import( name = "mylib", hdrs = ["mylib.h"], # libmylib.ifso is an interface library for libmylib.so which will be passed to linker interface_library = "libmylib.ifso", # libmylib.so will be available for runtime shared_library = "libmylib.so", ) </code></pre></devsite-code> <p>On Windows: <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> cc_import( name = "mylib", hdrs = ["mylib.h"], # mylib.lib is an import library for mylib.dll which will be passed to linker interface_library = "mylib.lib", # mylib.dll will be available for runtime shared_library = "mylib.dll", ) </code></pre></devsite-code> 4. Linking a shared library with <code translate="no" dir="ltr">system_provided=True</code> <p>On Unix: <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> cc_import( name = "mylib", hdrs = ["mylib.h"], interface_library = "libmylib.ifso", # Or we can also use libmylib.so as its own interface library # libmylib.so is provided by system environment, for example it can be found in LD_LIBRARY_PATH. # This indicates that Bazel is not responsible for making libmylib.so available. system_provided = True, ) </code></pre></devsite-code> <p>On Windows: <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> cc_import( name = "mylib", hdrs = ["mylib.h"], # mylib.lib is an import library for mylib.dll which will be passed to linker interface_library = "mylib.lib", # mylib.dll is provided by system environment, for example it can be found in PATH. # This indicates that Bazel is not responsible for making mylib.dll available. system_provided = True, ) </code></pre></devsite-code> 5. Linking to static or shared library <p>On Unix: <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> cc_import( name = "mylib", hdrs = ["mylib.h"], static_library = "libmylib.a", shared_library = "libmylib.so", ) </code></pre></devsite-code> <p>On Windows: <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> cc_import( name = "mylib", hdrs = ["mylib.h"], static_library = "libmylib.lib", # A normal static library interface_library = "mylib.lib", # An import library for mylib.dll shared_library = "mylib.dll", ) </code></pre></devsite-code> <p>The remaining is the same on Unix and Windows: <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> # first will link to libmylib.a (or libmylib.lib) cc_binary( name = "first", srcs = ["first.cc"], deps = [":mylib"], linkstatic = True, # default value ) # second will link to libmylib.so (or libmylib.lib) cc_binary( name = "second", srcs = ["second.cc"], deps = [":mylib"], linkstatic = False, ) </code></pre></devsite-code> <p> <code translate="no" dir="ltr">cc_import</code> supports an include attribute. For example: <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> cc_import( name = "curl_lib", hdrs = glob(["vendor/curl/include/curl/*.h"]), includes = ["vendor/curl/include"], shared_library = "vendor/curl/lib/.libs/libcurl.dylib", ) </code></pre></devsite-code> </p> <h3 id="cc_import_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="cc_import.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="cc_import.deps"> <code translate="no" dir="ltr">deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of other libraries that the target depends upon. See general comments about <code translate="no" dir="ltr">deps</code> at <a href="/reference/be/common-definitions#typical-attributes">Typical attributes defined by most build rules</a>. </td> </tr> <tr> <td id="cc_import.hdrs"> <code translate="no" dir="ltr">hdrs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of header files published by this precompiled library to be directly included by sources in dependent rules. </td> </tr> <tr> <td id="cc_import.alwayslink"> <code translate="no" dir="ltr">alwayslink</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> If 1, any binary that depends (directly or indirectly) on this C++ precompiled library will link in all the object files archived in the static library, even if some contain no symbols referenced by the binary. This is useful if your code isn't explicitly called by code in the binary, e.g., if your code registers to receive some callback provided by some service. <p>If alwayslink doesn't work with VS 2017 on Windows, that is due to a <a href="https://github.com/bazelbuild/bazel/issues/3949">known issue</a>, please upgrade your VS 2017 to the latest version.</p> </td> </tr> <tr> <td id="cc_import.includes"> <code translate="no" dir="ltr">includes</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> List of include dirs to be added to the compile line. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution. Each string is prepended with the package path and passed to the C++ toolchain for expansion via the "include_paths" CROSSTOOL feature. A toolchain running on a POSIX system with typical feature definitions will produce <code translate="no" dir="ltr">-isystem path_to_package/include_entry</code>. This should only be used for third-party libraries that do not conform to the Google style of writing #include statements. Unlike <a href="#cc_binary.copts">COPTS</a>, these flags are added for this rule and every rule that depends on it. (Note: not the rules it depends upon!) Be very careful, since this may have far-reaching effects. When in doubt, add "-I" flags to <a href="#cc_binary.copts">COPTS</a> instead. <p> The default <code translate="no" dir="ltr">include</code> path doesn't include generated files. If you need to <code translate="no" dir="ltr">#include</code> a generated header file, list it in the <code translate="no" dir="ltr">srcs</code>. </p> </td> </tr> <tr> <td id="cc_import.interface_library"> <code translate="no" dir="ltr">interface_library</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> A single interface library for linking the shared library. <p> Permitted file types: <code translate="no" dir="ltr">.ifso</code>, <code translate="no" dir="ltr">.tbd</code>, <code translate="no" dir="ltr">.lib</code>, <code translate="no" dir="ltr">.so</code> or <code translate="no" dir="ltr">.dylib</code> </p> </td> </tr> <tr> <td id="cc_import.linkopts"> <code translate="no" dir="ltr">linkopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Add these flags to the C++ linker command. Subject to <a href="/reference/be/make-variables">"Make" variable</a> substitution, <a href="/reference/be/common-definitions#sh-tokenization"> Bourne shell tokenization</a> and <a href="/reference/be/common-definitions#label-expansion">label expansion</a>. Each string in this attribute is added to <code translate="no" dir="ltr">LINKOPTS</code> before linking the binary target. <p> Each element of this list that does not start with <code translate="no" dir="ltr">$</code> or <code translate="no" dir="ltr">-</code> is assumed to be the label of a target in <code translate="no" dir="ltr">deps</code>. The list of files generated by that target is appended to the linker options. An error is reported if the label is invalid, or is not declared in <code translate="no" dir="ltr">deps</code>. </p> </td> </tr> <tr> <td id="cc_import.objects"> <code translate="no" dir="ltr">objects</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> </td> </tr> <tr> <td id="cc_import.pic_objects"> <code translate="no" dir="ltr">pic_objects</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> </td> </tr> <tr> <td id="cc_import.pic_static_library"> <code translate="no" dir="ltr">pic_static_library</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> </td> </tr> <tr> <td id="cc_import.shared_library"> <code translate="no" dir="ltr">shared_library</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> A single precompiled shared library. Bazel ensures it is available to the binary that depends on it during runtime. <p> Permitted file types: <code translate="no" dir="ltr">.so</code>, <code translate="no" dir="ltr">.dll</code> or <code translate="no" dir="ltr">.dylib</code> </p> </td> </tr> <tr> <td id="cc_import.static_library"> <code translate="no" dir="ltr">static_library</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> A single precompiled static library. <p> Permitted file types: <code translate="no" dir="ltr">.a</code>, <code translate="no" dir="ltr">.pic.a</code> or <code translate="no" dir="ltr">.lib</code> </p> </td> </tr> <tr> <td id="cc_import.system_provided"> <code translate="no" dir="ltr">system_provided</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> If 1, it indicates the shared library required at runtime is provided by the system. In this case, <code translate="no" dir="ltr">interface_library</code> should be specified and <code translate="no" dir="ltr">shared_library</code> should be empty. </td> </tr> </tbody> </table> <h2 id="cc_library" data-text=" cc_library " tabindex="-1"> cc_library </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/blob/master/src/main/starlark/builtins_bzl/common/cc/cc_library.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>cc_library(<a href="#cc_library.name">name</a>, <a href="#cc_library.deps">deps</a>, <a href="#cc_library.srcs">srcs</a>, <a href="#cc_library.data">data</a>, <a href="#cc_library.hdrs">hdrs</a>, <a href="#cc_library.additional_compiler_inputs">additional_compiler_inputs</a>, <a href="#cc_library.additional_linker_inputs">additional_linker_inputs</a>, <a href="#cc_library.alwayslink">alwayslink</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="#cc_library.conlyopts">conlyopts</a>, <a href="#cc_library.copts">copts</a>, <a href="#cc_library.cxxopts">cxxopts</a>, <a href="#cc_library.defines">defines</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.distribs">distribs</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="#cc_library.hdrs_check">hdrs_check</a>, <a href="#cc_library.implementation_deps">implementation_deps</a>, <a href="#cc_library.include_prefix">include_prefix</a>, <a href="#cc_library.includes">includes</a>, <a href="/reference/be/common-definitions#typical.licenses">licenses</a>, <a href="#cc_library.linkopts">linkopts</a>, <a href="#cc_library.linkstamp">linkstamp</a>, <a href="#cc_library.linkstatic">linkstatic</a>, <a href="#cc_library.local_defines">local_defines</a>, <a href="#cc_library.module_interfaces">module_interfaces</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="#cc_library.strip_include_prefix">strip_include_prefix</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="#cc_library.textual_hdrs">textual_hdrs</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>, <a href="#cc_library.win_def_file">win_def_file</a>)</pre></devsite-code> <p>Use <code translate="no" dir="ltr">cc_library()</code> for C++-compiled libraries. The result is either a <code translate="no" dir="ltr">.so</code>, <code translate="no" dir="ltr">.lo</code>, or <code translate="no" dir="ltr">.a</code>, depending on what is needed. </p> <p> If you build something with static linking that depends on a <code translate="no" dir="ltr">cc_library</code>, the output of a depended-on library rule is the <code translate="no" dir="ltr">.a</code> file. If you specify <code translate="no" dir="ltr">alwayslink=True</code>, you get the <code translate="no" dir="ltr">.lo</code> file. </p> <p> The actual output file name is <code translate="no" dir="ltr">lib<i>foo</i>.so</code> for the shared library, where <i>foo</i> is the name of the rule. The other kinds of libraries end with <code translate="no" dir="ltr">.lo</code> and <code translate="no" dir="ltr">.a</code>, respectively. If you need a specific shared library name, for example, to define a Python module, use a genrule to copy the library to the desired name. </p> <h4 id="hdrs" data-text="Header inclusion checking" tabindex="-1">Header inclusion checking</h4> <p> All header files that are used in the build must be declared in the <code translate="no" dir="ltr">hdrs</code> or <code translate="no" dir="ltr">srcs</code> of <code translate="no" dir="ltr">cc_*</code> rules. This is enforced. </p> <p> For <code translate="no" dir="ltr">cc_library</code> rules, headers in <code translate="no" dir="ltr">hdrs</code> comprise the public interface of the library and can be directly included both from the files in <code translate="no" dir="ltr">hdrs</code> and <code translate="no" dir="ltr">srcs</code> of the library itself as well as from files in <code translate="no" dir="ltr">hdrs</code> and <code translate="no" dir="ltr">srcs</code> of <code translate="no" dir="ltr">cc_*</code> rules that list the library in their <code translate="no" dir="ltr">deps</code>. Headers in <code translate="no" dir="ltr">srcs</code> must only be directly included from the files in <code translate="no" dir="ltr">hdrs</code> and <code translate="no" dir="ltr">srcs</code> of the library itself. When deciding whether to put a header into <code translate="no" dir="ltr">hdrs</code> or <code translate="no" dir="ltr">srcs</code>, you should ask whether you want consumers of this library to be able to directly include it. This is roughly the same decision as between <code translate="no" dir="ltr">public</code> and <code translate="no" dir="ltr">private</code> visibility in programming languages. </p> <p> <code translate="no" dir="ltr">cc_binary</code> and <code translate="no" dir="ltr">cc_test</code> rules do not have an exported interface, so they also do not have a <code translate="no" dir="ltr">hdrs</code> attribute. All headers that belong to the binary or test directly should be listed in the <code translate="no" dir="ltr">srcs</code>. </p> <p> To illustrate these rules, look at the following example. </p> <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> cc_binary( name = "foo", srcs = [ "foo.cc", "foo.h", ], deps = [":bar"], ) cc_library( name = "bar", srcs = [ "bar.cc", "bar-impl.h", ], hdrs = ["bar.h"], deps = [":baz"], ) cc_library( name = "baz", srcs = [ "baz.cc", "baz-impl.h", ], hdrs = ["baz.h"], ) </code></pre></devsite-code> <p> The allowed direct inclusions in this example are listed in the table below. For example <code translate="no" dir="ltr">foo.cc</code> is allowed to directly include <code translate="no" dir="ltr">foo.h</code> and <code translate="no" dir="ltr">bar.h</code>, but not <code translate="no" dir="ltr">baz.h</code>. </p> <table class="table table-striped table-bordered table-condensed"> <thead> <tr><th>Including file</th><th>Allowed inclusions</th></tr> </thead> <tbody> <tr><td>foo.h</td><td>bar.h</td></tr> <tr><td>foo.cc</td><td>foo.h bar.h</td></tr> <tr><td>bar.h</td><td>bar-impl.h baz.h</td></tr> <tr><td>bar-impl.h</td><td>bar.h baz.h</td></tr> <tr><td>bar.cc</td><td>bar.h bar-impl.h baz.h</td></tr> <tr><td>baz.h</td><td>baz-impl.h</td></tr> <tr><td>baz-impl.h</td><td>baz.h</td></tr> <tr><td>baz.cc</td><td>baz.h baz-impl.h</td></tr> </tbody> </table> <p> The inclusion checking rules only apply to <em>direct</em> inclusions. In the example above <code translate="no" dir="ltr">foo.cc</code> is allowed to include <code translate="no" dir="ltr">bar.h</code>, which may include <code translate="no" dir="ltr">baz.h</code>, which in turn is allowed to include <code translate="no" dir="ltr">baz-impl.h</code>. Technically, the compilation of a <code translate="no" dir="ltr">.cc</code> file may transitively include any header file in the <code translate="no" dir="ltr">hdrs</code> or <code translate="no" dir="ltr">srcs</code> in any <code translate="no" dir="ltr">cc_library</code> in the transitive <code translate="no" dir="ltr">deps</code> closure. In this case the compiler may read <code translate="no" dir="ltr">baz.h</code> and <code translate="no" dir="ltr">baz-impl.h</code> when compiling <code translate="no" dir="ltr">foo.cc</code>, but <code translate="no" dir="ltr">foo.cc</code> must not contain <code translate="no" dir="ltr">#include "baz.h"</code>. For that to be allowed, <code translate="no" dir="ltr">baz</code> must be added to the <code translate="no" dir="ltr">deps</code> of <code translate="no" dir="ltr">foo</code>. </p> <p> Bazel depends on toolchain support to enforce the inclusion checking rules. The <code translate="no" dir="ltr">layering_check</code> feature has to be supported by the toolchain and requested explicitly, for example via the <code translate="no" dir="ltr">--features=layering_check</code> command-line flag or the <code translate="no" dir="ltr">features</code> parameter of the <a href="/reference/be/functions#package"><code translate="no" dir="ltr">package</code></a> function. The toolchains provided by Bazel only support this feature with clang on Unix and macOS. </p> <h4 id="cc_library_examples" data-text="Examples" tabindex="-1">Examples</h4> <p id="alwayslink_lib_example"> We use the <code translate="no" dir="ltr">alwayslink</code> flag to force the linker to link in this code although the main binary code doesn't reference it. </p> <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> cc_library( name = "ast_inspector_lib", srcs = ["ast_inspector_lib.cc"], hdrs = ["ast_inspector_lib.h"], visibility = ["//visibility:public"], deps = ["//third_party/llvm/llvm/tools/clang:frontend"], # alwayslink as we want to be able to call things in this library at # debug time, even if they aren't used anywhere in the code. alwayslink = 1, ) </code></pre></devsite-code> <p>The following example comes from <code translate="no" dir="ltr">third_party/python2_4_3/BUILD</code>. Some of the code uses the <code translate="no" dir="ltr">dl</code> library (to load another, dynamic library), so this rule specifies the <code translate="no" dir="ltr">-ldl</code> link option to link the <code translate="no" dir="ltr">dl</code> library. </p> <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> cc_library( name = "python2_4_3", linkopts = [ "-ldl", "-lutil", ], deps = ["//third_party/expat"], ) </code></pre></devsite-code> <p>The following example comes from <code translate="no" dir="ltr">third_party/kde/BUILD</code>. We keep pre-built <code translate="no" dir="ltr">.so</code> files in the depot. The header files live in a subdirectory named <code translate="no" dir="ltr">include</code>. </p> <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> cc_library( name = "kde", srcs = [ "lib/libDCOP.so", "lib/libkdesu.so", "lib/libkhtml.so", "lib/libkparts.so", <var translate="no">...more .so files...</var>, ], includes = ["include"], deps = ["//third_party/X11"], ) </code></pre></devsite-code> <p>The following example comes from <code translate="no" dir="ltr">third_party/gles/BUILD</code>. Third-party code often needs some <code translate="no" dir="ltr">defines</code> and <code translate="no" dir="ltr">linkopts</code>. </p> <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> cc_library( name = "gles", srcs = [ "GLES/egl.h", "GLES/gl.h", "ddx.c", "egl.c", ], defines = [ "USE_FLOAT", "__GL_FLOAT", "__GL_COMMON", ], linkopts = ["-ldl"], # uses dlopen(), dl library deps = [ "es", "//third_party/X11", ], ) </code></pre></devsite-code> <h3 id="cc_library_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="cc_library.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="cc_library.deps"> <code translate="no" dir="ltr">deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of other libraries that the library target depends upon. <p>These can be <code translate="no" dir="ltr">cc_library</code> or <code translate="no" dir="ltr">objc_library</code> targets.</p> <p>See general comments about <code translate="no" dir="ltr">deps</code> at <a href="/reference/be/common-definitions#typical-attributes">Typical attributes defined by most build rules</a>. </p> <p>These should be names of C++ library rules. When you build a binary that links this rule's library, you will also link the libraries in <code translate="no" dir="ltr">deps</code>. </p> <p>Despite the "deps" name, not all of this library's clients belong here. Run-time data dependencies belong in <code translate="no" dir="ltr">data</code>. Source files generated by other rules belong in <code translate="no" dir="ltr">srcs</code>. </p> <p>To link in a pre-compiled third-party library, add its name to the <code translate="no" dir="ltr">srcs</code> instead. </p> <p>To depend on something without linking it to this library, add its name to the <code translate="no" dir="ltr">data</code> instead. </p> </td> </tr> <tr> <td id="cc_library.srcs"> <code translate="no" dir="ltr">srcs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of C and C++ files that are processed to create the library target. These are C/C++ source and header files, either non-generated (normal source code) or generated. <p>All <code translate="no" dir="ltr">.cc</code>, <code translate="no" dir="ltr">.c</code>, and <code translate="no" dir="ltr">.cpp</code> files will be compiled. These might be generated files: if a named file is in the <code translate="no" dir="ltr">outs</code> of some other rule, this <code translate="no" dir="ltr">cc_library</code> will automatically depend on that other rule. </p> <p>Pure assembler files (.s, .asm) are not preprocessed and are typically built using the assembler. Preprocessed assembly files (.S) are preprocessed and are typically built using the C/C++ compiler. </p> <p>A <code translate="no" dir="ltr">.h</code> file will not be compiled, but will be available for inclusion by sources in this rule. Both <code translate="no" dir="ltr">.cc</code> and <code translate="no" dir="ltr">.h</code> files can directly include headers listed in these <code translate="no" dir="ltr">srcs</code> or in the <code translate="no" dir="ltr">hdrs</code> of this rule or any rule listed in the <code translate="no" dir="ltr">deps</code> argument. </p> <p>All <code translate="no" dir="ltr">#include</code>d files must be mentioned in the <code translate="no" dir="ltr">hdrs</code> attribute of this or referenced <code translate="no" dir="ltr">cc_library</code> rules, or they should be listed in <code translate="no" dir="ltr">srcs</code> if they are private to this library. See <a href="#hdrs">"Header inclusion checking"</a> for a more detailed description. </p> <p><code translate="no" dir="ltr">.so</code>, <code translate="no" dir="ltr">.lo</code>, and <code translate="no" dir="ltr">.a</code> files are pre-compiled files. Your library might have these as <code translate="no" dir="ltr">srcs</code> if it uses third-party code for which we don't have source code. </p> <p>If the <code translate="no" dir="ltr">srcs</code> attribute includes the label of another rule, <code translate="no" dir="ltr">cc_library</code> will use the output files of that rule as source files to compile. This is useful for one-off generation of source code (for more than occasional use, it's better to implement a Starlark rule class and use the <code translate="no" dir="ltr">cc_common</code> API) </p> <p> Permitted <code translate="no" dir="ltr">srcs</code> file types: </p> <ul> <li>C and C++ source files: <code translate="no" dir="ltr">.c</code>, <code translate="no" dir="ltr">.cc</code>, <code translate="no" dir="ltr">.cpp</code>, <code translate="no" dir="ltr">.cxx</code>, <code translate="no" dir="ltr">.c++</code>, <code translate="no" dir="ltr">.C</code></li> <li>C and C++ header files: <code translate="no" dir="ltr">.h</code>, <code translate="no" dir="ltr">.hh</code>, <code translate="no" dir="ltr">.hpp</code>, <code translate="no" dir="ltr">.hxx</code>, <code translate="no" dir="ltr">.inc</code>, <code translate="no" dir="ltr">.inl</code>, <code translate="no" dir="ltr">.H</code></li> <li>Assembler with C preprocessor: <code translate="no" dir="ltr">.S</code></li> <li>Archive: <code translate="no" dir="ltr">.a</code>, <code translate="no" dir="ltr">.pic.a</code></li> <li>"Always link" library: <code translate="no" dir="ltr">.lo</code>, <code translate="no" dir="ltr">.pic.lo</code></li> <li>Shared library, versioned or unversioned: <code translate="no" dir="ltr">.so</code>, <code translate="no" dir="ltr">.so.<i>version</i></code></li> <li>Object file: <code translate="no" dir="ltr">.o</code>, <code translate="no" dir="ltr">.pic.o</code></li> </ul> <p> ... and any rules that produce those files (e.g. <code translate="no" dir="ltr">cc_embed_data</code>). Different extensions denote different programming languages in accordance with gcc convention. </p> </td> </tr> <tr> <td id="cc_library.data"> <code translate="no" dir="ltr">data</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of files needed by this library at runtime. See general comments about <code translate="no" dir="ltr">data</code> at <a href="/reference/be/common-definitions#typical-attributes">Typical attributes defined by most build rules</a>. <p>If a <code translate="no" dir="ltr">data</code> is the name of a generated file, then this <code translate="no" dir="ltr">cc_library</code> rule automatically depends on the generating rule. </p> <p>If a <code translate="no" dir="ltr">data</code> is a rule name, then this <code translate="no" dir="ltr">cc_library</code> rule automatically depends on that rule, and that rule's <code translate="no" dir="ltr">outs</code> are automatically added to this <code translate="no" dir="ltr">cc_library</code>'s data files. </p> <p>Your C++ code can access these data files like so:</p> <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> const std::string path = devtools_build::GetDataDependencyFilepath( "my/test/data/file"); </code></pre></devsite-code> </td> </tr> <tr> <td id="cc_library.hdrs"> <code translate="no" dir="ltr">hdrs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of header files published by this library to be directly included by sources in dependent rules. <p>This is the strongly preferred location for declaring header files that describe the interface for the library. These headers will be made available for inclusion by sources in this rule or in dependent rules. Headers not meant to be included by a client of this library should be listed in the <code translate="no" dir="ltr">srcs</code> attribute instead, even if they are included by a published header. See <a href="#hdrs">"Header inclusion checking"</a> for a more detailed description. </p> <p>Permitted <code translate="no" dir="ltr">headers</code> file types: <code translate="no" dir="ltr">.h</code>, <code translate="no" dir="ltr">.hh</code>, <code translate="no" dir="ltr">.hpp</code>, <code translate="no" dir="ltr">.hxx</code>. </p> </td> </tr> <tr> <td id="cc_library.additional_compiler_inputs"> <code translate="no" dir="ltr">additional_compiler_inputs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Any additional files you might want to pass to the compiler command line, such as sanitizer ignorelists, for example. Files specified here can then be used in copts with the $(location) function. </td> </tr> <tr> <td id="cc_library.additional_linker_inputs"> <code translate="no" dir="ltr">additional_linker_inputs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Pass these files to the C++ linker command. <p> For example, compiled Windows .res files can be provided here to be embedded in the binary target. </p> </td> </tr> <tr> <td id="cc_library.alwayslink"> <code translate="no" dir="ltr">alwayslink</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> If 1, any binary that depends (directly or indirectly) on this C++ library will link in all the object files for the files listed in <code translate="no" dir="ltr">srcs</code>, even if some contain no symbols referenced by the binary. This is useful if your code isn't explicitly called by code in the binary, e.g., if your code registers to receive some callback provided by some service. <p>If alwayslink doesn't work with VS 2017 on Windows, that is due to a <a href="https://github.com/bazelbuild/bazel/issues/3949">known issue</a>, please upgrade your VS 2017 to the latest version.</p> </td> </tr> <tr> <td id="cc_library.conlyopts"> <code translate="no" dir="ltr">conlyopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Add these options to the C compilation command. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. </td> </tr> <tr> <td id="cc_library.copts"> <code translate="no" dir="ltr">copts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Add these options to the C/C++ compilation command. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. <p> Each string in this attribute is added in the given order to <code translate="no" dir="ltr">COPTS</code> before compiling the binary target. The flags take effect only for compiling this target, not its dependencies, so be careful about header files included elsewhere. All paths should be relative to the workspace, not to the current package. This attribute should not be needed outside of <code translate="no" dir="ltr">third_party</code>. </p> <p> If the package declares the <a href="/reference/be/functions#package.features">feature</a> <code translate="no" dir="ltr">no_copts_tokenization</code>, Bourne shell tokenization applies only to strings that consist of a single "Make" variable. </p> </td> </tr> <tr> <td id="cc_library.cxxopts"> <code translate="no" dir="ltr">cxxopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Add these options to the C++ compilation command. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. </td> </tr> <tr> <td id="cc_library.defines"> <code translate="no" dir="ltr">defines</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> List of defines to add to the compile line. Subject to <a href="/reference/be/make-variables">"Make" variable</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. Each string, which must consist of a single Bourne shell token, is prepended with <code translate="no" dir="ltr">-D</code> and added to the compile command line to this target, as well as to every rule that depends on it. Be very careful, since this may have far-reaching effects. When in doubt, add define values to <a href="#cc_binary.local_defines"><code translate="no" dir="ltr">local_defines</code></a> instead. </td> </tr> <tr> <td id="cc_library.hdrs_check"> <code translate="no" dir="ltr">hdrs_check</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> Deprecated, no-op. </td> </tr> <tr> <td id="cc_library.implementation_deps"> <code translate="no" dir="ltr">implementation_deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of other libraries that the library target depends on. Unlike with <code translate="no" dir="ltr">deps</code>, the headers and include paths of these libraries (and all their transitive deps) are only used for compilation of this library, and not libraries that depend on it. Libraries specified with <code translate="no" dir="ltr">implementation_deps</code> are still linked in binary targets that depend on this library. </td> </tr> <tr> <td id="cc_library.include_prefix"> <code translate="no" dir="ltr">include_prefix</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> The prefix to add to the paths of the headers of this rule. <p>When set, the headers in the <code translate="no" dir="ltr">hdrs</code> attribute of this rule are accessible at is the value of this attribute prepended to their repository-relative path. <p>The prefix in the <code translate="no" dir="ltr">strip_include_prefix</code> attribute is removed before this prefix is added. <p>This attribute is only legal under <code translate="no" dir="ltr">third_party</code>. </td> </tr> <tr> <td id="cc_library.includes"> <code translate="no" dir="ltr">includes</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> List of include dirs to be added to the compile line. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution. Each string is prepended with the package path and passed to the C++ toolchain for expansion via the "include_paths" CROSSTOOL feature. A toolchain running on a POSIX system with typical feature definitions will produce <code translate="no" dir="ltr">-isystem path_to_package/include_entry</code>. This should only be used for third-party libraries that do not conform to the Google style of writing #include statements. Unlike <a href="#cc_binary.copts">COPTS</a>, these flags are added for this rule and every rule that depends on it. (Note: not the rules it depends upon!) Be very careful, since this may have far-reaching effects. When in doubt, add "-I" flags to <a href="#cc_binary.copts">COPTS</a> instead. <p> The added <code translate="no" dir="ltr">include</code> paths will include generated files as well as files in the source tree. </p> </td> </tr> <tr> <td id="cc_library.linkopts"> <code translate="no" dir="ltr">linkopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> See <a href="/reference/be/c-cpp#cc_binary.linkopts"><code translate="no" dir="ltr">cc_binary.linkopts</code></a>. The <code translate="no" dir="ltr">linkopts</code> attribute is also applied to any target that depends, directly or indirectly, on this library via <code translate="no" dir="ltr">deps</code> attributes (or via other attributes that are treated similarly: the <a href="/reference/be/c-cpp#cc_binary.malloc"><code translate="no" dir="ltr">malloc</code></a> attribute of <a href="/reference/be/c-cpp#cc_binary"><code translate="no" dir="ltr">cc_binary</code></a>). Dependency linkopts take precedence over dependent linkopts (i.e. dependency linkopts appear later in the command line). Linkopts specified in <a href="https://bazel.build/reference/user-manual.html#flag--linkopt"><code translate="no" dir="ltr">--linkopt</code></a> take precedence over rule linkopts. </p> <p> Note that the <code translate="no" dir="ltr">linkopts</code> attribute only applies when creating <code translate="no" dir="ltr">.so</code> files or executables, not when creating <code translate="no" dir="ltr">.a</code> or <code translate="no" dir="ltr">.lo</code> files. So if the <code translate="no" dir="ltr">linkstatic=True</code> attribute is set, the <code translate="no" dir="ltr">linkopts</code> attribute has no effect on the creation of this library, only on other targets which depend on this library. </p> <p> Also, it is important to note that "-Wl,-soname" or "-Xlinker -soname" options are not supported and should never be specified in this attribute. </p> <p> The <code translate="no" dir="ltr">.so</code> files produced by <code translate="no" dir="ltr">cc_library</code> rules are not linked against the libraries that they depend on. If you're trying to create a shared library for use outside of the main repository, e.g. for manual use with <code translate="no" dir="ltr">dlopen()</code> or <code translate="no" dir="ltr">LD_PRELOAD</code>, it may be better to use a <code translate="no" dir="ltr">cc_binary</code> rule with the <code translate="no" dir="ltr">linkshared=True</code> attribute. See <a href="/reference/be/c-cpp#cc_binary.linkshared"><code translate="no" dir="ltr">cc_binary.linkshared</code></a>. </p> </td> </tr> <tr> <td id="cc_library.linkstamp"> <code translate="no" dir="ltr">linkstamp</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Simultaneously compiles and links the specified C++ source file into the final binary. This trickery is required to introduce timestamp information into binaries; if we compiled the source file to an object file in the usual way, the timestamp would be incorrect. A linkstamp compilation may not include any particular set of compiler flags and so should not depend on any particular header, compiler option, or other build variable. <em class='harmful'>This option should only be needed in the <code translate="no" dir="ltr">base</code> package.</em> </td> </tr> <tr> <td id="cc_library.linkstatic"> <code translate="no" dir="ltr">linkstatic</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> For <a href="/reference/be/c-cpp#cc_binary"><code translate="no" dir="ltr">cc_binary</code></a> and <a href="/reference/be/c-cpp#cc_test"><code translate="no" dir="ltr">cc_test</code></a>: link the binary in static mode. For <code translate="no" dir="ltr">cc_library.link_static</code>: see below. <p>By default this option is on for <code translate="no" dir="ltr">cc_binary</code> and off for the rest.</p> <p> If enabled and this is a binary or test, this option tells the build tool to link in <code translate="no" dir="ltr">.a</code>'s instead of <code translate="no" dir="ltr">.so</code>'s for user libraries whenever possible. System libraries such as libc (but <i>not</i> the C/C++ runtime libraries, see below) are still linked dynamically, as are libraries for which there is no static library. So the resulting executable will still be dynamically linked, hence only <i>mostly</i> static. </p> <p> There are really three different ways to link an executable: </p> <ul> <li> STATIC with fully_static_link feature, in which everything is linked statically; e.g. "<code translate="no" dir="ltr">gcc -static foo.o libbar.a libbaz.a -lm</code>".<br/> This mode is enabled by specifying <code translate="no" dir="ltr">fully_static_link</code> in the <a href="/reference/be/common-definitions#features"><code translate="no" dir="ltr">features</code></a> attribute.</li> <li> STATIC, in which all user libraries are linked statically (if a static version is available), but where system libraries (excluding C/C++ runtime libraries) are linked dynamically, e.g. "<code translate="no" dir="ltr">gcc foo.o libfoo.a libbaz.a -lm</code>".<br/> This mode is enabled by specifying <code translate="no" dir="ltr">linkstatic=True</code>.</li> <li> DYNAMIC, in which all libraries are linked dynamically (if a dynamic version is available), e.g. "<code translate="no" dir="ltr">gcc foo.o libfoo.so libbaz.so -lm</code>".<br/> This mode is enabled by specifying <code translate="no" dir="ltr">linkstatic=False</code>.</li> </ul> <p> If the <code translate="no" dir="ltr">linkstatic</code> attribute or <code translate="no" dir="ltr">fully_static_link</code> in <code translate="no" dir="ltr">features</code> is used outside of <code translate="no" dir="ltr">//third_party</code> please include a comment near the rule to explain why. </p> <p> The <code translate="no" dir="ltr">linkstatic</code> attribute has a different meaning if used on a <a href="/reference/be/c-cpp#cc_library"><code translate="no" dir="ltr">cc_library()</code></a> rule. For a C++ library, <code translate="no" dir="ltr">linkstatic=True</code> indicates that only static linking is allowed, so no <code translate="no" dir="ltr">.so</code> will be produced. linkstatic=False does not prevent static libraries from being created. The attribute is meant to control the creation of dynamic libraries. </p> <p> There should be very little code built with <code translate="no" dir="ltr">linkstatic=False</code> in production. If <code translate="no" dir="ltr">linkstatic=False</code>, then the build tool will create symlinks to depended-upon shared libraries in the <code translate="no" dir="ltr">*.runfiles</code> area. </p> </td> </tr> <tr> <td id="cc_library.local_defines"> <code translate="no" dir="ltr">local_defines</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> List of defines to add to the compile line. Subject to <a href="/reference/be/make-variables">"Make" variable</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. Each string, which must consist of a single Bourne shell token, is prepended with <code translate="no" dir="ltr">-D</code> and added to the compile command line for this target, but not to its dependents. </td> </tr> <tr> <td id="cc_library.module_interfaces"> <code translate="no" dir="ltr">module_interfaces</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of files are regarded as C++20 Modules Interface. <p> C++ Standard has no restriction about module interface file extension <ul> <li>Clang use cppm </li> <li>GCC can use any source file extension </li> <li>MSVC use ixx </li> </ul> </p> <p>The use is guarded by the flag <code translate="no" dir="ltr">--experimental_cpp_modules</code>.</p> </td> </tr> <tr> <td id="cc_library.strip_include_prefix"> <code translate="no" dir="ltr">strip_include_prefix</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> The prefix to strip from the paths of the headers of this rule. <p>When set, the headers in the <code translate="no" dir="ltr">hdrs</code> attribute of this rule are accessible at their path with this prefix cut off. <p>If it's a relative path, it's taken as a package-relative one. If it's an absolute one, it's understood as a repository-relative path. <p>The prefix in the <code translate="no" dir="ltr">include_prefix</code> attribute is added after this prefix is stripped. <p>This attribute is only legal under <code translate="no" dir="ltr">third_party</code>. </td> </tr> <tr> <td id="cc_library.textual_hdrs"> <code translate="no" dir="ltr">textual_hdrs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of header files published by this library to be textually included by sources in dependent rules. <p>This is the location for declaring header files that cannot be compiled on their own; that is, they always need to be textually included by other source files to build valid code.</p> </td> </tr> <tr> <td id="cc_library.win_def_file"> <code translate="no" dir="ltr">win_def_file</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> The Windows DEF file to be passed to linker. <p>This attribute should only be used when Windows is the target platform. It can be used to <a href="https://msdn.microsoft.com/en-us/library/d91k01sh.aspx"> export symbols</a> during linking a shared library.</p> </td> </tr> </tbody> </table> <h2 id="cc_shared_library" data-text=" cc_shared_library " tabindex="-1"> cc_shared_library </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/blob/master/src/main/starlark/builtins_bzl/common/cc/cc_shared_library.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>cc_shared_library(<a href="#cc_shared_library.name">name</a>, <a href="#cc_shared_library.deps">deps</a>, <a href="#cc_shared_library.additional_linker_inputs">additional_linker_inputs</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.distribs">distribs</a>, <a href="#cc_shared_library.dynamic_deps">dynamic_deps</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="#cc_shared_library.exports_filter">exports_filter</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="#cc_shared_library.roots">roots</a>, <a href="#cc_shared_library.shared_lib_name">shared_lib_name</a>, <a href="#cc_shared_library.static_deps">static_deps</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="#cc_shared_library.user_link_flags">user_link_flags</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>, <a href="#cc_shared_library.win_def_file">win_def_file</a>)</pre></devsite-code> <p>It produces a shared library.</p> <h4 id="cc_shard_library_examples" data-text="Example" tabindex="-1">Example</h4> <div></div><devsite-code><pre class="code" translate="no" dir="ltr" is-upgraded> cc_shared_library( name = "foo_shared", deps = [ ":foo", ], dynamic_deps = [ ":bar_shared", ], additional_linker_inputs = [ ":foo.lds", ], user_link_flags = [ "-Wl,--version-script=$(location :foo.lds)", ], ) cc_library( name = "foo", srcs = ["foo.cc"], hdrs = ["foo.h"], deps = [ ":bar", ":baz", ], ) cc_shared_library( name = "bar_shared", shared_lib_name = "bar.so", deps = [":bar"], ) cc_library( name = "bar", srcs = ["bar.cc"], hdrs = ["bar.h"], ) cc_library( name = "baz", srcs = ["baz.cc"], hdrs = ["baz.h"], ) </pre></devsite-code> <p>In the example <code translate="no" dir="ltr">foo_shared</code> statically links <code translate="no" dir="ltr">foo</code> and <code translate="no" dir="ltr">baz</code>, the latter being a transitive dependency. It doesn't link <code translate="no" dir="ltr">bar</code> because it is already provided dynamically by the <code translate="no" dir="ltr">dynamic_dep</code> <code translate="no" dir="ltr">bar_shared</code>.</p> <p><code translate="no" dir="ltr">foo_shared</code> uses a linker script *.lds file to control which symbols should be exported. The <code translate="no" dir="ltr">cc_shared_library</code> rule logic does not control which symbols get exported, it only uses what is assumed to be exported to give errors during analysis phase if two shared libraries export the same targets.</p> <p>Every direct dependency of <code translate="no" dir="ltr">cc_shared_library</code> is assumed to be exported. Therefore, Bazel assumes during analysis that <code translate="no" dir="ltr">foo</code> is being exported by <code translate="no" dir="ltr">foo_shared</code>. <code translate="no" dir="ltr">baz</code> is not assumed to be exported by <code translate="no" dir="ltr">foo_shared</code>. Every target matched by the <code translate="no" dir="ltr">exports_filter</code> is also assumed to be exported.</p> <p>Every single <code translate="no" dir="ltr">cc_library</code> in the example should appear at most in one <code translate="no" dir="ltr">cc_shared_library</code>. If we wanted to link <code translate="no" dir="ltr">baz</code> also into <code translate="no" dir="ltr">bar_shared</code> we would need to add <code translate="no" dir="ltr">tags = ["LINKABLE_MORE_THAN_ONCE"]</code> to <code translate="no" dir="ltr">baz</code>.</p> <p>Due to the <code translate="no" dir="ltr">shared_lib_name</code> attribute, the file produced by <code translate="no" dir="ltr">bar_shared</code> will have the name <code translate="no" dir="ltr">bar.so</code> as opposed to the name <code translate="no" dir="ltr">libbar.so</code> that it would have by default on Linux.</p> <h4 id="cc_shard_library_examples" data-text="Errors" tabindex="-1">Errors</h4> <h5 id="two-shared-libraries-in-dependencies-export-the-same-symbols." data-text="Two shared libraries in dependencies export the same symbols." tabindex="-1"><code translate="no" dir="ltr">Two shared libraries in dependencies export the same symbols.</code></h5> <p>This will happen whenever you are creating a target with two different <code translate="no" dir="ltr">cc_shared_library</code> dependencies that export the same target. To fix this you need to stop the libraries from being exported in one of the <code translate="no" dir="ltr">cc_shared_library</code> dependencies.</p> <h5 id="two-shared-libraries-in-dependencies-link-the-same-library-statically" data-text="Two shared libraries in dependencies link the same library statically" tabindex="-1"><code translate="no" dir="ltr">Two shared libraries in dependencies link the same library statically</code></h5> <p>This will happen whenever you are creating a new <code translate="no" dir="ltr">cc_shared_library</code> with two different <code translate="no" dir="ltr">cc_shared_library</code> dependencies that link the same target statically. Similar to the error with exports.</p> <p>One way to fix this is to stop linking the library into one of the <code translate="no" dir="ltr">cc_shared_library</code> dependencies. At the same time, the one that still links it needs to export the library so that the one not linking it keeps visibility to the symbols. Another way is to pull out a third library that exports the target. A third way is to tag the culprit <code translate="no" dir="ltr">cc_library</code> with <code translate="no" dir="ltr">LINKABLE_MORE_THAN_ONCE</code> but this fix should be rare and you should absolutely make sure that the <code translate="no" dir="ltr">cc_library</code> is indeed safe to link more than once.</p> <h5 id="foo:foo-is-already-linked-statically-in-bar:bar-but-not-exported`" data-text="'//foo:foo' is already linked statically in '//bar:bar' but not exported`" tabindex="-1"><code translate="no" dir="ltr">'//foo:foo' is already linked statically in '//bar:bar' but not exported`</code></h5> <p>This means that a library in the transitive closure of your <code translate="no" dir="ltr">deps</code> is reachable without going through one of the <code translate="no" dir="ltr">cc_shared_library</code> dependencies but is already linked into a different <code translate="no" dir="ltr">cc_shared_library</code> in <code translate="no" dir="ltr">dynamic_deps</code> and is not exported.</p> <p>The solution is to export it from the <code translate="no" dir="ltr">cc_shared_library</code> dependency or pull out a third <code translate="no" dir="ltr">cc_shared_library</code> that exports it.</p> <h5 id="do-not-place-libraries-which-only-contain-a-precompiled-dynamic-library-in-deps." data-text="Do not place libraries which only contain a precompiled dynamic library in deps. " tabindex="-1"><code translate="no" dir="ltr">Do not place libraries which only contain a precompiled dynamic library in deps. </code></h5> <p>If you have a precompiled dynamic library, this doesn't need to and cannot be linked statically into the current <code translate="no" dir="ltr">cc_shared_library</code> target that you are currently creating. Therefore, it doesn't belong in <code translate="no" dir="ltr">deps</code> of the <code translate="no" dir="ltr">cc_shared_library</code>. If this precompiled dynamic library is a dependency of one of your <code translate="no" dir="ltr">cc_libraries</code>, then the <code translate="no" dir="ltr">cc_library</code> needs to depend on it directly.</p> <h5 id="trying-to-export-a-library-already-exported-by-a-different-shared-library" data-text="Trying to export a library already exported by a different shared library" tabindex="-1"><code translate="no" dir="ltr">Trying to export a library already exported by a different shared library</code></h5> <p>You will see this error if on the current rule you are claiming to export a target that is already being exported by one of your dynamic dependencies.</p> <p>To fix this, remove the target from <code translate="no" dir="ltr">deps</code> and just rely on it from the dynamic dependency or make sure that the <code translate="no" dir="ltr">exports_filter</code> doesn't catch this target.</p> <h3 id="cc_shared_library_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="cc_shared_library.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="cc_shared_library.deps"> <code translate="no" dir="ltr">deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Top level libraries that will unconditionally be statically linked into the shared library after being whole-archived. <p> Any transitive library dependency of these direct deps will be linked into this shared library as long as they have not already been linked by a <code translate="no" dir="ltr">cc_shared_library</code> in <code translate="no" dir="ltr">dynamic_deps</code>.</p> <p> During analysis, the rule implementation will consider any target listed in <code translate="no" dir="ltr">deps</code> as being exported by the shared library in order to give errors when multiple <code translate="no" dir="ltr">cc_shared_libraries</code> export the same targets. The rule implementation does not take care of informing the linker about which symbols should be exported by the shared object. The user should take care of this via linker scripts or visibility declarations in the source code.</p> <p> The implementation will also trigger errors whenever the same library is linked statically into more than one <code translate="no" dir="ltr">cc_shared_library</code>. This can be avoided by adding <code translate="no" dir="ltr">"LINKABLE_MORE_THAN_ONCE"</code> to the <code translate="no" dir="ltr">cc_library.tags</code> or by listing the `cc_library` as an export of one of the shared libraries so that one can be made a <code translate="no" dir="ltr">dynamic_dep</code> of the other. </p> </td> </tr> <tr> <td id="cc_shared_library.additional_linker_inputs"> <code translate="no" dir="ltr">additional_linker_inputs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Any additional files that you may want to pass to the linker, for example, linker scripts. You have to separately pass any linker flags that the linker needs in order to be aware of this file. You can do so via the <code translate="no" dir="ltr">user_link_flags</code> attribute. </td> </tr> <tr> <td id="cc_shared_library.dynamic_deps"> <code translate="no" dir="ltr">dynamic_deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> These are other <code translate="no" dir="ltr">cc_shared_library</code> dependencies the current target depends on. <p> The <code translate="no" dir="ltr">cc_shared_library</code> implementation will use the list of <code translate="no" dir="ltr">dynamic_deps</code> (transitively, i.e. also the <code translate="no" dir="ltr">dynamic_deps</code> of the current target's <code translate="no" dir="ltr">dynamic_deps</code>) to decide which <code translate="no" dir="ltr">cc_libraries</code> in the transitive <code translate="no" dir="ltr">deps</code> should not be linked in because they are already provided by a different <code translate="no" dir="ltr">cc_shared_library</code>. </p> </td> </tr> <tr> <td id="cc_shared_library.exports_filter"> <code translate="no" dir="ltr">exports_filter</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> This attribute contains a list of targets that are claimed to be exported by the current shared library. <p> Any target <code translate="no" dir="ltr">deps</code> is already understood to be exported by the shared library. This attribute should be used to list any targets that are exported by the shared library but are transitive dependencies of <code translate="no" dir="ltr">deps</code>. </p> <p> Note that this attribute is not actually adding a dependency edge to those targets, the dependency edge should instead be created by <code translate="no" dir="ltr">deps</code>.The entries in this attribute are just strings. Keep in mind that when placing a target in this attribute, this is considered a claim that the shared library exports the symbols from that target. The <code translate="no" dir="ltr">cc_shared_library</code> logic doesn't actually handle telling the linker which symbols should be exported. </p> <p>The following syntax is allowed:</p> <p><code translate="no" dir="ltr">//foo:__pkg__</code> to account for any target in foo/BUILD</p> <p><code translate="no" dir="ltr">//foo:__subpackages__</code> to account for any target in foo/BUILD or any other package below foo/ like foo/bar/BUILD</p> </td> </tr> <tr> <td id="cc_shared_library.roots"> <code translate="no" dir="ltr">roots</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> </td> </tr> <tr> <td id="cc_shared_library.shared_lib_name"> <code translate="no" dir="ltr">shared_lib_name</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> By default cc_shared_library will use a name for the shared library output file based on the target's name and the platform. This includes an extension and sometimes a prefix. Sometimes you may not want the default name, for example, when loading C++ shared libraries for Python the default lib* prefix is often not desired, in which case you can use this attribute to choose a custom name. </td> </tr> <tr> <td id="cc_shared_library.static_deps"> <code translate="no" dir="ltr">static_deps</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> </td> </tr> <tr> <td id="cc_shared_library.user_link_flags"> <code translate="no" dir="ltr">user_link_flags</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Any additional flags that you may want to pass to the linker. For example, to make the linker aware of a linker script passed via additional_linker_inputs you can use the following: <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> cc_shared_library( name = "foo_shared", additional_linker_inputs = select({ "//src/conditions:linux": [ ":foo.lds", ":additional_script.txt", ], "//conditions:default": []}), user_link_flags = select({ "//src/conditions:linux": [ "-Wl,-rpath,kittens", "-Wl,--version-script=$(location :foo.lds)", "-Wl,--script=$(location :additional_script.txt)", ], "//conditions:default": []}), ... ) </code></pre></devsite-code> </td> </tr> <tr> <td id="cc_shared_library.win_def_file"> <code translate="no" dir="ltr">win_def_file</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> The Windows DEF file to be passed to linker. <p>This attribute should only be used when Windows is the target platform. It can be used to <a href="https://msdn.microsoft.com/en-us/library/d91k01sh.aspx"> export symbols</a> during linking a shared library.</p> </td> </tr> </tbody> </table> <h2 id="cc_static_library" data-text=" cc_static_library " tabindex="-1"> cc_static_library </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/blob/master/src/main/starlark/builtins_bzl/common/cc/experimental_cc_static_library.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>cc_static_library(<a href="#cc_static_library.name">name</a>, <a href="#cc_static_library.deps">deps</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.distribs">distribs</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>)</pre></devsite-code> <b>This rule is currently experimental and can only be used with the <code translate="no" dir="ltr"> --experimental_cc_static_library</code> flag.</b> Produces a static library from a list of targets and their transitive dependencies. <p>The resulting static library contains the object files of the targets listed in <code translate="no" dir="ltr">deps</code> as well as their transitive dependencies, with preference given to <code translate="no" dir="ltr">PIC</code> objects.</p> <h4 id="cc_static_library_output_groups" data-text="Output groups" tabindex="-1">Output groups</h4> <h5 id="linkdeps" data-text="linkdeps" tabindex="-1"><code translate="no" dir="ltr">linkdeps</code></h5> <p>A text file containing the labels of those transitive dependencies of targets listed in <code translate="no" dir="ltr">deps</code> that did not contribute any object files to the static library, but do provide at least one static, dynamic or interface library. The resulting static library may require these libraries to be available at link time.</p> <h5 id="linkopts" data-text="linkopts" tabindex="-1"><code translate="no" dir="ltr">linkopts</code></h5> <p>A text file containing the user-provided <code translate="no" dir="ltr">linkopts</code> of all transitive dependencies of targets listed in <code translate="no" dir="ltr">deps</code>. <h4 id="cc_static_library_symbol_check" data-text="Duplicate symbols" tabindex="-1">Duplicate symbols</h4> <p>By default, the <code translate="no" dir="ltr">cc_static_library</code> rule checks that the resulting static library does not contain any duplicate symbols. If it does, the build fails with an error message that lists the duplicate symbols and the object files containing them.</p> <p>This check can be disabled per target or per package by setting <code translate="no" dir="ltr">features = ["-symbol_check"]</code> or globally via <code translate="no" dir="ltr">--features=-symbol_check</code>.</p> <h5 id="cc_static_library_symbol_check_toolchain" data-text="Toolchain support for symbol_check" tabindex="-1">Toolchain support for <code translate="no" dir="ltr">symbol_check</code></h5> <p>The auto-configured C++ toolchains shipped with Bazel support the <code translate="no" dir="ltr">symbol_check</code> feature on all platforms. Custom toolchains can add support for it in one of two ways:</p> <ul> <li>Implementing the <code translate="no" dir="ltr">ACTION_NAMES.validate_static_library</code> action and enabling it with the <code translate="no" dir="ltr">symbol_check</code> feature. The tool set in the action is invoked with two arguments, the static library to check for duplicate symbols and the path of a file that must be created if the check passes.</li> <li>Having the <code translate="no" dir="ltr">symbol_check</code> feature add archiver flags that cause the action creating the static library to fail on duplicate symbols.</li> </ul> <h3 id="cc_static_library_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="cc_static_library.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="cc_static_library.deps"> <code translate="no" dir="ltr">deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of targets to combine into a static library, including all their transitive dependencies. <p>Dependencies that do not provide any object files are not included in the static library, but their labels are collected in the file provided by the <code translate="no" dir="ltr">linkdeps</code> output group.</p> </td> </tr> </tbody> </table> <h2 id="cc_test" data-text=" cc_test " tabindex="-1"> cc_test </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/blob/master/src/main/starlark/builtins_bzl/common/cc/cc_test.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>cc_test(<a href="#cc_test.name">name</a>, <a href="#cc_test.deps">deps</a>, <a href="#cc_test.srcs">srcs</a>, <a href="#cc_test.data">data</a>, <a href="#cc_test.additional_linker_inputs">additional_linker_inputs</a>, <a href="/reference/be/common-definitions#test.args">args</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="#cc_test.conlyopts">conlyopts</a>, <a href="#cc_test.copts">copts</a>, <a href="#cc_test.cxxopts">cxxopts</a>, <a href="#cc_test.defines">defines</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.distribs">distribs</a>, <a href="#cc_test.dynamic_deps">dynamic_deps</a>, <a href="/reference/be/common-definitions#test.env">env</a>, <a href="/reference/be/common-definitions#test.env_inherit">env_inherit</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="/reference/be/common-definitions#test.flaky">flaky</a>, <a href="#cc_test.hdrs_check">hdrs_check</a>, <a href="#cc_test.includes">includes</a>, <a href="/reference/be/common-definitions#typical.licenses">licenses</a>, <a href="#cc_test.link_extra_lib">link_extra_lib</a>, <a href="#cc_test.linkopts">linkopts</a>, <a href="#cc_test.linkshared">linkshared</a>, <a href="#cc_test.linkstatic">linkstatic</a>, <a href="/reference/be/common-definitions#test.local">local</a>, <a href="#cc_test.local_defines">local_defines</a>, <a href="#cc_test.malloc">malloc</a>, <a href="#cc_test.module_interfaces">module_interfaces</a>, <a href="#cc_test.nocopts">nocopts</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="#cc_test.reexport_deps">reexport_deps</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="/reference/be/common-definitions#test.shard_count">shard_count</a>, <a href="/reference/be/common-definitions#test.size">size</a>, <a href="#cc_test.stamp">stamp</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#test.timeout">timeout</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>, <a href="#cc_test.win_def_file">win_def_file</a>)</pre></devsite-code> <p> A <code translate="no" dir="ltr">cc_test()</code> rule compiles a test. Here, a test is a binary wrapper around some testing code. </p> <p><i>By default, C++ tests are dynamically linked.</i><br/> To statically link a unit test, specify <a href="/reference/be/c-cpp#cc_binary.linkstatic"><code translate="no" dir="ltr">linkstatic=True</code></a>. It would probably be good to comment why your test needs <code translate="no" dir="ltr">linkstatic</code>; this is probably not obvious.</p> <h4 id="implicit-output-targets_1" data-text="Implicit output targets" tabindex="-1">Implicit output targets</h4> <ul> <li><code translate="no" dir="ltr"><var translate="no">name</var>.stripped</code> (only built if explicitly requested): A stripped version of the binary. <code translate="no" dir="ltr">strip -g</code> is run on the binary to remove debug symbols. Additional strip options can be provided on the command line using <code translate="no" dir="ltr">--stripopt=-foo</code>.</li> <li><code translate="no" dir="ltr"><var translate="no">name</var>.dwp</code> (only built if explicitly requested): If <a href="https://gcc.gnu.org/wiki/DebugFission">Fission</a> is enabled: a debug information package file suitable for debugging remotely deployed binaries. Else: an empty file.</li> </ul> <p> See the <a href="/reference/be/c-cpp#cc_binary_args">cc_binary()</a> arguments, except that the <code translate="no" dir="ltr">stamp</code> argument is set to 0 by default for tests and that <code translate="no" dir="ltr">cc_test</code> has extra <a href="/reference/be/common-definitions#common-attributes-tests"> attributes common to all test rules (*_test)</a>.</p> <h3 id="cc_test_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="cc_test.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="cc_test.deps"> <code translate="no" dir="ltr">deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of other libraries to be linked in to the binary target. <p>These can be <code translate="no" dir="ltr">cc_library</code> or <code translate="no" dir="ltr">objc_library</code> targets.</p> It is also allowed to put linker scripts (.lds) into deps, and reference them in <a href="#cc_binary.linkopts">linkopts</a>. </td> </tr> <tr> <td id="cc_test.srcs"> <code translate="no" dir="ltr">srcs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of C and C++ files that are processed to create the library target. These are C/C++ source and header files, either non-generated (normal source code) or generated. <p>All <code translate="no" dir="ltr">.cc</code>, <code translate="no" dir="ltr">.c</code>, and <code translate="no" dir="ltr">.cpp</code> files will be compiled. These might be generated files: if a named file is in the <code translate="no" dir="ltr">outs</code> of some other rule, this <code translate="no" dir="ltr">cc_library</code> will automatically depend on that other rule. </p> <p>Pure assembler files (.s, .asm) are not preprocessed and are typically built using the assembler. Preprocessed assembly files (.S) are preprocessed and are typically built using the C/C++ compiler. </p> <p>A <code translate="no" dir="ltr">.h</code> file will not be compiled, but will be available for inclusion by sources in this rule. Both <code translate="no" dir="ltr">.cc</code> and <code translate="no" dir="ltr">.h</code> files can directly include headers listed in these <code translate="no" dir="ltr">srcs</code> or in the <code translate="no" dir="ltr">hdrs</code> of this rule or any rule listed in the <code translate="no" dir="ltr">deps</code> argument. </p> <p>All <code translate="no" dir="ltr">#include</code>d files must be mentioned in the <code translate="no" dir="ltr">hdrs</code> attribute of this or referenced <code translate="no" dir="ltr">cc_library</code> rules, or they should be listed in <code translate="no" dir="ltr">srcs</code> if they are private to this library. See <a href="#hdrs">"Header inclusion checking"</a> for a more detailed description. </p> <p><code translate="no" dir="ltr">.so</code>, <code translate="no" dir="ltr">.lo</code>, and <code translate="no" dir="ltr">.a</code> files are pre-compiled files. Your library might have these as <code translate="no" dir="ltr">srcs</code> if it uses third-party code for which we don't have source code. </p> <p>If the <code translate="no" dir="ltr">srcs</code> attribute includes the label of another rule, <code translate="no" dir="ltr">cc_library</code> will use the output files of that rule as source files to compile. This is useful for one-off generation of source code (for more than occasional use, it's better to implement a Starlark rule class and use the <code translate="no" dir="ltr">cc_common</code> API) </p> <p> Permitted <code translate="no" dir="ltr">srcs</code> file types: </p> <ul> <li>C and C++ source files: <code translate="no" dir="ltr">.c</code>, <code translate="no" dir="ltr">.cc</code>, <code translate="no" dir="ltr">.cpp</code>, <code translate="no" dir="ltr">.cxx</code>, <code translate="no" dir="ltr">.c++</code>, <code translate="no" dir="ltr">.C</code></li> <li>C and C++ header files: <code translate="no" dir="ltr">.h</code>, <code translate="no" dir="ltr">.hh</code>, <code translate="no" dir="ltr">.hpp</code>, <code translate="no" dir="ltr">.hxx</code>, <code translate="no" dir="ltr">.inc</code>, <code translate="no" dir="ltr">.inl</code>, <code translate="no" dir="ltr">.H</code></li> <li>Assembler with C preprocessor: <code translate="no" dir="ltr">.S</code></li> <li>Archive: <code translate="no" dir="ltr">.a</code>, <code translate="no" dir="ltr">.pic.a</code></li> <li>"Always link" library: <code translate="no" dir="ltr">.lo</code>, <code translate="no" dir="ltr">.pic.lo</code></li> <li>Shared library, versioned or unversioned: <code translate="no" dir="ltr">.so</code>, <code translate="no" dir="ltr">.so.<i>version</i></code></li> <li>Object file: <code translate="no" dir="ltr">.o</code>, <code translate="no" dir="ltr">.pic.o</code></li> </ul> <p> ... and any rules that produce those files (e.g. <code translate="no" dir="ltr">cc_embed_data</code>). Different extensions denote different programming languages in accordance with gcc convention. </p> </td> </tr> <tr> <td id="cc_test.data"> <code translate="no" dir="ltr">data</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of files needed by this library at runtime. See general comments about <code translate="no" dir="ltr">data</code> at <a href="/reference/be/common-definitions#typical-attributes">Typical attributes defined by most build rules</a>. <p>If a <code translate="no" dir="ltr">data</code> is the name of a generated file, then this <code translate="no" dir="ltr">cc_library</code> rule automatically depends on the generating rule. </p> <p>If a <code translate="no" dir="ltr">data</code> is a rule name, then this <code translate="no" dir="ltr">cc_library</code> rule automatically depends on that rule, and that rule's <code translate="no" dir="ltr">outs</code> are automatically added to this <code translate="no" dir="ltr">cc_library</code>'s data files. </p> <p>Your C++ code can access these data files like so:</p> <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> const std::string path = devtools_build::GetDataDependencyFilepath( "my/test/data/file"); </code></pre></devsite-code> </td> </tr> <tr> <td id="cc_test.additional_linker_inputs"> <code translate="no" dir="ltr">additional_linker_inputs</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> Pass these files to the C++ linker command. <p> For example, compiled Windows .res files can be provided here to be embedded in the binary target. </p> </td> </tr> <tr> <td id="cc_test.conlyopts"> <code translate="no" dir="ltr">conlyopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Add these options to the C compilation command. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. </td> </tr> <tr> <td id="cc_test.copts"> <code translate="no" dir="ltr">copts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Add these options to the C/C++ compilation command. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. <p> Each string in this attribute is added in the given order to <code translate="no" dir="ltr">COPTS</code> before compiling the binary target. The flags take effect only for compiling this target, not its dependencies, so be careful about header files included elsewhere. All paths should be relative to the workspace, not to the current package. This attribute should not be needed outside of <code translate="no" dir="ltr">third_party</code>. </p> <p> If the package declares the <a href="/reference/be/functions#package.features">feature</a> <code translate="no" dir="ltr">no_copts_tokenization</code>, Bourne shell tokenization applies only to strings that consist of a single "Make" variable. </p> </td> </tr> <tr> <td id="cc_test.cxxopts"> <code translate="no" dir="ltr">cxxopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Add these options to the C++ compilation command. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. </td> </tr> <tr> <td id="cc_test.defines"> <code translate="no" dir="ltr">defines</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> List of defines to add to the compile line. Subject to <a href="/reference/be/make-variables">"Make" variable</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. Each string, which must consist of a single Bourne shell token, is prepended with <code translate="no" dir="ltr">-D</code> and added to the compile command line to this target, as well as to every rule that depends on it. Be very careful, since this may have far-reaching effects. When in doubt, add define values to <a href="#cc_binary.local_defines"><code translate="no" dir="ltr">local_defines</code></a> instead. </td> </tr> <tr> <td id="cc_test.dynamic_deps"> <code translate="no" dir="ltr">dynamic_deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> These are other <code translate="no" dir="ltr">cc_shared_library</code> dependencies the current target depends on. <p> The <code translate="no" dir="ltr">cc_shared_library</code> implementation will use the list of <code translate="no" dir="ltr">dynamic_deps</code> (transitively, i.e. also the <code translate="no" dir="ltr">dynamic_deps</code> of the current target's <code translate="no" dir="ltr">dynamic_deps</code>) to decide which <code translate="no" dir="ltr">cc_libraries</code> in the transitive <code translate="no" dir="ltr">deps</code> should not be linked in because they are already provided by a different <code translate="no" dir="ltr">cc_shared_library</code>. </td> </tr> <tr> <td id="cc_test.hdrs_check"> <code translate="no" dir="ltr">hdrs_check</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> Deprecated, no-op. </td> </tr> <tr> <td id="cc_test.includes"> <code translate="no" dir="ltr">includes</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> List of include dirs to be added to the compile line. Subject to <a href="/reference/be/make-variables">"Make variable"</a> substitution. Each string is prepended with the package path and passed to the C++ toolchain for expansion via the "include_paths" CROSSTOOL feature. A toolchain running on a POSIX system with typical feature definitions will produce <code translate="no" dir="ltr">-isystem path_to_package/include_entry</code>. This should only be used for third-party libraries that do not conform to the Google style of writing #include statements. Unlike <a href="#cc_binary.copts">COPTS</a>, these flags are added for this rule and every rule that depends on it. (Note: not the rules it depends upon!) Be very careful, since this may have far-reaching effects. When in doubt, add "-I" flags to <a href="#cc_binary.copts">COPTS</a> instead. <p> The added <code translate="no" dir="ltr">include</code> paths will include generated files as well as files in the source tree. </p> </td> </tr> <tr> <td id="cc_test.link_extra_lib"> <code translate="no" dir="ltr">link_extra_lib</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">"@bazel_tools//tools/cpp:link_extra_lib"</code></p> Control linking of extra libraries. <p> By default, C++ binaries are linked against <code translate="no" dir="ltr">//tools/cpp:link_extra_lib</code>, which by default depends on the label flag <code translate="no" dir="ltr">//tools/cpp:link_extra_libs</code>. Without setting the flag, this library is empty by default. Setting the label flag allows linking optional dependencies, such as overrides for weak symbols, interceptors for shared library functions, or special runtime libraries (for malloc replacements, prefer <code translate="no" dir="ltr">malloc</code> or <code translate="no" dir="ltr">--custom_malloc</code>). Setting this attribute to <code translate="no" dir="ltr">None</code> disables this behaviour. </p> </td> </tr> <tr> <td id="cc_test.linkopts"> <code translate="no" dir="ltr">linkopts</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> Add these flags to the C++ linker command. Subject to <a href="/reference/be/make-variables">"Make" variable</a> substitution, <a href="/reference/be/common-definitions#sh-tokenization"> Bourne shell tokenization</a> and <a href="/reference/be/common-definitions#label-expansion">label expansion</a>. Each string in this attribute is added to <code translate="no" dir="ltr">LINKOPTS</code> before linking the binary target. <p> Each element of this list that does not start with <code translate="no" dir="ltr">$</code> or <code translate="no" dir="ltr">-</code> is assumed to be the label of a target in <code translate="no" dir="ltr">deps</code>. The list of files generated by that target is appended to the linker options. An error is reported if the label is invalid, or is not declared in <code translate="no" dir="ltr">deps</code>. </p> </td> </tr> <tr> <td id="cc_test.linkshared"> <code translate="no" dir="ltr">linkshared</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> Create a shared library. To enable this attribute, include <code translate="no" dir="ltr">linkshared=True</code> in your rule. By default this option is off. <p> The presence of this flag means that linking occurs with the <code translate="no" dir="ltr">-shared</code> flag to <code translate="no" dir="ltr">gcc</code>, and the resulting shared library is suitable for loading into for example a Java program. However, for build purposes it will never be linked into the dependent binary, as it is assumed that shared libraries built with a <a href="#cc_binary">cc_binary</a> rule are only loaded manually by other programs, so it should not be considered a substitute for the <a href="#cc_library">cc_library</a> rule. For sake of scalability we recommend avoiding this approach altogether and simply letting <code translate="no" dir="ltr">java_library</code> depend on <code translate="no" dir="ltr">cc_library</code> rules instead. </p> <p> If you specify both <code translate="no" dir="ltr">linkopts=['-static']</code> and <code translate="no" dir="ltr">linkshared=True</code>, you get a single completely self-contained unit. If you specify both <code translate="no" dir="ltr">linkstatic=True</code> and <code translate="no" dir="ltr">linkshared=True</code>, you get a single, mostly self-contained unit. </p> </td> </tr> <tr> <td id="cc_test.linkstatic"> <code translate="no" dir="ltr">linkstatic</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> For <a href="/reference/be/c-cpp#cc_binary"><code translate="no" dir="ltr">cc_binary</code></a> and <a href="/reference/be/c-cpp#cc_test"><code translate="no" dir="ltr">cc_test</code></a>: link the binary in static mode. For <code translate="no" dir="ltr">cc_library.link_static</code>: see below. <p>By default this option is on for <code translate="no" dir="ltr">cc_binary</code> and off for the rest.</p> <p> If enabled and this is a binary or test, this option tells the build tool to link in <code translate="no" dir="ltr">.a</code>'s instead of <code translate="no" dir="ltr">.so</code>'s for user libraries whenever possible. System libraries such as libc (but <i>not</i> the C/C++ runtime libraries, see below) are still linked dynamically, as are libraries for which there is no static library. So the resulting executable will still be dynamically linked, hence only <i>mostly</i> static. </p> <p> There are really three different ways to link an executable: </p> <ul> <li> STATIC with fully_static_link feature, in which everything is linked statically; e.g. "<code translate="no" dir="ltr">gcc -static foo.o libbar.a libbaz.a -lm</code>".<br/> This mode is enabled by specifying <code translate="no" dir="ltr">fully_static_link</code> in the <a href="/reference/be/common-definitions#features"><code translate="no" dir="ltr">features</code></a> attribute.</li> <li> STATIC, in which all user libraries are linked statically (if a static version is available), but where system libraries (excluding C/C++ runtime libraries) are linked dynamically, e.g. "<code translate="no" dir="ltr">gcc foo.o libfoo.a libbaz.a -lm</code>".<br/> This mode is enabled by specifying <code translate="no" dir="ltr">linkstatic=True</code>.</li> <li> DYNAMIC, in which all libraries are linked dynamically (if a dynamic version is available), e.g. "<code translate="no" dir="ltr">gcc foo.o libfoo.so libbaz.so -lm</code>".<br/> This mode is enabled by specifying <code translate="no" dir="ltr">linkstatic=False</code>.</li> </ul> <p> If the <code translate="no" dir="ltr">linkstatic</code> attribute or <code translate="no" dir="ltr">fully_static_link</code> in <code translate="no" dir="ltr">features</code> is used outside of <code translate="no" dir="ltr">//third_party</code> please include a comment near the rule to explain why. </p> <p> The <code translate="no" dir="ltr">linkstatic</code> attribute has a different meaning if used on a <a href="/reference/be/c-cpp#cc_library"><code translate="no" dir="ltr">cc_library()</code></a> rule. For a C++ library, <code translate="no" dir="ltr">linkstatic=True</code> indicates that only static linking is allowed, so no <code translate="no" dir="ltr">.so</code> will be produced. linkstatic=False does not prevent static libraries from being created. The attribute is meant to control the creation of dynamic libraries. </p> <p> There should be very little code built with <code translate="no" dir="ltr">linkstatic=False</code> in production. If <code translate="no" dir="ltr">linkstatic=False</code>, then the build tool will create symlinks to depended-upon shared libraries in the <code translate="no" dir="ltr">*.runfiles</code> area. </p> </td> </tr> <tr> <td id="cc_test.local_defines"> <code translate="no" dir="ltr">local_defines</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> List of defines to add to the compile line. Subject to <a href="/reference/be/make-variables">"Make" variable</a> substitution and <a href="/reference/be/common-definitions#sh-tokenization">Bourne shell tokenization</a>. Each string, which must consist of a single Bourne shell token, is prepended with <code translate="no" dir="ltr">-D</code> and added to the compile command line for this target, but not to its dependents. </td> </tr> <tr> <td id="cc_test.malloc"> <code translate="no" dir="ltr">malloc</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">"@bazel_tools//tools/cpp:malloc"</code></p> Override the default dependency on malloc. <p> By default, C++ binaries are linked against <code translate="no" dir="ltr">//tools/cpp:malloc</code>, which is an empty library so the binary ends up using libc malloc. This label must refer to a <code translate="no" dir="ltr">cc_library</code>. If compilation is for a non-C++ rule, this option has no effect. The value of this attribute is ignored if <code translate="no" dir="ltr">linkshared=True</code> is specified. </p> </td> </tr> <tr> <td id="cc_test.module_interfaces"> <code translate="no" dir="ltr">module_interfaces</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> The list of files are regarded as C++20 Modules Interface. <p> C++ Standard has no restriction about module interface file extension <ul> <li>Clang use cppm </li> <li>GCC can use any source file extension </li> <li>MSVC use ixx </li> </ul> </p> <p>The use is guarded by the flag <code translate="no" dir="ltr">--experimental_cpp_modules</code>.</p> </td> </tr> <tr> <td id="cc_test.nocopts"> <code translate="no" dir="ltr">nocopts</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> Remove matching options from the C++ compilation command. Subject to <a href="/reference/be/make-variables">"Make" variable</a> substitution. The value of this attribute is interpreted as a regular expression. Any preexisting <code translate="no" dir="ltr">COPTS</code> that match this regular expression (including values explicitly specified in the rule's <a href="#cc_binary.copts">copts</a> attribute) will be removed from <code translate="no" dir="ltr">COPTS</code> for purposes of compiling this rule. This attribute should not be needed or used outside of <code translate="no" dir="ltr">third_party</code>. The values are not preprocessed in any way other than the "Make" variable substitution. </td> </tr> <tr> <td id="cc_test.reexport_deps"> <code translate="no" dir="ltr">reexport_deps</code> </td> <td> <p>List of <a href="/concepts/labels">labels</a>; default is <code translate="no" dir="ltr">[]</code></p> </td> </tr> <tr> <td id="cc_test.stamp"> <code translate="no" dir="ltr">stamp</code> </td> <td> <p>Integer; default is <code translate="no" dir="ltr">0</code></p> Whether to encode build information into the binary. Possible values: <ul> <li> <code translate="no" dir="ltr">stamp = 1</code>: Always stamp the build information into the binary, even in <a href="/docs/user-manual#flag--stamp"><code translate="no" dir="ltr">--nostamp</code></a> builds. <b>This setting should be avoided</b>, since it potentially kills remote caching for the binary and any downstream actions that depend on it. </li> <li> <code translate="no" dir="ltr">stamp = 0</code>: Always replace build information by constant values. This gives good build result caching. </li> <li> <code translate="no" dir="ltr">stamp = -1</code>: Embedding of build information is controlled by the <a href="/docs/user-manual#flag--stamp"><code translate="no" dir="ltr">--[no]stamp</code></a> flag. </li> </ul> <p>Stamped binaries are <em>not</em> rebuilt unless their dependencies change.</p> </td> </tr> <tr> <td id="cc_test.win_def_file"> <code translate="no" dir="ltr">win_def_file</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> The Windows DEF file to be passed to linker. <p>This attribute should only be used when Windows is the target platform. It can be used to <a href="https://msdn.microsoft.com/en-us/library/d91k01sh.aspx"> export symbols</a> during linking a shared library.</p> </td> </tr> </tbody> </table> <h2 id="cc_toolchain" data-text=" cc_toolchain " tabindex="-1"> cc_toolchain </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/blob/master/src/main/starlark/builtins_bzl/common/cc/cc_toolchain.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>cc_toolchain(<a href="#cc_toolchain.name">name</a>, <a href="#cc_toolchain.all_files">all_files</a>, <a href="#cc_toolchain.ar_files">ar_files</a>, <a href="#cc_toolchain.as_files">as_files</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="#cc_toolchain.compiler_files">compiler_files</a>, <a href="#cc_toolchain.compiler_files_without_includes">compiler_files_without_includes</a>, <a href="#cc_toolchain.coverage_files">coverage_files</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.distribs">distribs</a>, <a href="#cc_toolchain.dwp_files">dwp_files</a>, <a href="#cc_toolchain.dynamic_runtime_lib">dynamic_runtime_lib</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="#cc_toolchain.exec_transition_for_inputs">exec_transition_for_inputs</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="#cc_toolchain.libc_top">libc_top</a>, <a href="/reference/be/common-definitions#typical.licenses">licenses</a>, <a href="#cc_toolchain.linker_files">linker_files</a>, <a href="#cc_toolchain.module_map">module_map</a>, <a href="#cc_toolchain.objcopy_files">objcopy_files</a>, <a href="#cc_toolchain.output_licenses">output_licenses</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="#cc_toolchain.static_runtime_lib">static_runtime_lib</a>, <a href="#cc_toolchain.strip_files">strip_files</a>, <a href="#cc_toolchain.supports_header_parsing">supports_header_parsing</a>, <a href="#cc_toolchain.supports_param_files">supports_param_files</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="#cc_toolchain.toolchain_config">toolchain_config</a>, <a href="#cc_toolchain.toolchain_identifier">toolchain_identifier</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>)</pre></devsite-code> <p>Represents a C++ toolchain.</p> <p> This rule is responsible for: <ul> <li> Collecting all artifacts needed for C++ actions to run. This is done by attributes such as <code translate="no" dir="ltr">all_files</code>, <code translate="no" dir="ltr">compiler_files</code>, <code translate="no" dir="ltr">linker_files</code>, or other attributes ending with <code translate="no" dir="ltr">_files</code>). These are most commonly filegroups globbing all required files. </li> <li> Generating correct command lines for C++ actions. This is done using <code translate="no" dir="ltr">CcToolchainConfigInfo</code> provider (details below). </li> </ul> </p> <p> Use <code translate="no" dir="ltr">toolchain_config</code> attribute to configure the C++ toolchain. See also this <a href="https://bazel.build/docs/cc-toolchain-config-reference"> page </a> for elaborate C++ toolchain configuration and toolchain selection documentation. </p> <p> Use <code translate="no" dir="ltr">tags = ["manual"]</code> in order to prevent toolchains from being built and configured unnecessarily when invoking <code translate="no" dir="ltr">bazel build //...</code> </p> <h3 id="cc_toolchain_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="cc_toolchain.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="cc_toolchain.all_files"> <code translate="no" dir="ltr">all_files</code> </td> <td> <p><a href="/concepts/labels">Label</a>; required</p> Collection of all cc_toolchain artifacts. These artifacts will be added as inputs to all rules_cc related actions (with the exception of actions that are using more precise sets of artifacts from attributes below). Bazel assumes that <code translate="no" dir="ltr">all_files</code> is a superset of all other artifact-providing attributes (e.g. linkstamp compilation needs both compile and link files, so it takes <code translate="no" dir="ltr">all_files</code>). <p> This is what <code translate="no" dir="ltr">cc_toolchain.files</code> contains, and this is used by all Starlark rules using C++ toolchain.</p> </td> </tr> <tr> <td id="cc_toolchain.ar_files"> <code translate="no" dir="ltr">ar_files</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Collection of all cc_toolchain artifacts required for archiving actions. </td> </tr> <tr> <td id="cc_toolchain.as_files"> <code translate="no" dir="ltr">as_files</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Collection of all cc_toolchain artifacts required for assembly actions. </td> </tr> <tr> <td id="cc_toolchain.compiler_files"> <code translate="no" dir="ltr">compiler_files</code> </td> <td> <p><a href="/concepts/labels">Label</a>; required</p> Collection of all cc_toolchain artifacts required for compile actions. </td> </tr> <tr> <td id="cc_toolchain.compiler_files_without_includes"> <code translate="no" dir="ltr">compiler_files_without_includes</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Collection of all cc_toolchain artifacts required for compile actions in case when input discovery is supported (currently Google-only). </td> </tr> <tr> <td id="cc_toolchain.coverage_files"> <code translate="no" dir="ltr">coverage_files</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Collection of all cc_toolchain artifacts required for coverage actions. If not specified, all_files are used. </td> </tr> <tr> <td id="cc_toolchain.dwp_files"> <code translate="no" dir="ltr">dwp_files</code> </td> <td> <p><a href="/concepts/labels">Label</a>; required</p> Collection of all cc_toolchain artifacts required for dwp actions. </td> </tr> <tr> <td id="cc_toolchain.dynamic_runtime_lib"> <code translate="no" dir="ltr">dynamic_runtime_lib</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Dynamic library artifact for the C++ runtime library (e.g. libstdc++.so). <p>This will be used when 'static_link_cpp_runtimes' feature is enabled, and we're linking dependencies dynamically.</p> </td> </tr> <tr> <td id="cc_toolchain.exec_transition_for_inputs"> <code translate="no" dir="ltr">exec_transition_for_inputs</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> Deprecated. No-op. </td> </tr> <tr> <td id="cc_toolchain.libc_top"> <code translate="no" dir="ltr">libc_top</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> A collection of artifacts for libc passed as inputs to compile/linking actions. </td> </tr> <tr> <td id="cc_toolchain.linker_files"> <code translate="no" dir="ltr">linker_files</code> </td> <td> <p><a href="/concepts/labels">Label</a>; required</p> Collection of all cc_toolchain artifacts required for linking actions. </td> </tr> <tr> <td id="cc_toolchain.module_map"> <code translate="no" dir="ltr">module_map</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Module map artifact to be used for modular builds. </td> </tr> <tr> <td id="cc_toolchain.objcopy_files"> <code translate="no" dir="ltr">objcopy_files</code> </td> <td> <p><a href="/concepts/labels">Label</a>; required</p> Collection of all cc_toolchain artifacts required for objcopy actions. </td> </tr> <tr> <td id="cc_toolchain.output_licenses"> <code translate="no" dir="ltr">output_licenses</code> </td> <td> <p>List of strings; default is <code translate="no" dir="ltr">[]</code></p> </td> </tr> <tr> <td id="cc_toolchain.static_runtime_lib"> <code translate="no" dir="ltr">static_runtime_lib</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Static library artifact for the C++ runtime library (e.g. libstdc++.a). <p>This will be used when 'static_link_cpp_runtimes' feature is enabled, and we're linking dependencies statically.</p> </td> </tr> <tr> <td id="cc_toolchain.strip_files"> <code translate="no" dir="ltr">strip_files</code> </td> <td> <p><a href="/concepts/labels">Label</a>; required</p> Collection of all cc_toolchain artifacts required for strip actions. </td> </tr> <tr> <td id="cc_toolchain.supports_header_parsing"> <code translate="no" dir="ltr">supports_header_parsing</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">False</code></p> Set to True when cc_toolchain supports header parsing actions. </td> </tr> <tr> <td id="cc_toolchain.supports_param_files"> <code translate="no" dir="ltr">supports_param_files</code> </td> <td> <p>Boolean; default is <code translate="no" dir="ltr">True</code></p> Set to True when cc_toolchain supports using param files for linking actions. </td> </tr> <tr> <td id="cc_toolchain.toolchain_config"> <code translate="no" dir="ltr">toolchain_config</code> </td> <td> <p><a href="/concepts/labels">Label</a>; required</p> The label of the rule providing <code translate="no" dir="ltr">cc_toolchain_config_info</code>. </td> </tr> <tr> <td id="cc_toolchain.toolchain_identifier"> <code translate="no" dir="ltr">toolchain_identifier</code> </td> <td> <p>String; default is <code translate="no" dir="ltr">""</code></p> The identifier used to match this cc_toolchain with the corresponding crosstool_config.toolchain. <p> Until issue <a href="https://github.com/bazelbuild/bazel/issues/5380">#5380</a> is fixed this is the recommended way of associating <code translate="no" dir="ltr">cc_toolchain</code> with <code translate="no" dir="ltr">CROSSTOOL.toolchain</code>. It will be replaced by the <code translate="no" dir="ltr">toolchain_config</code> attribute (<a href="https://github.com/bazelbuild/bazel/issues/5380">#5380</a>).</p> </td> </tr> </tbody> </table> <h2 id="cc_toolchain_suite" data-text=" cc_toolchain_suite " tabindex="-1"> cc_toolchain_suite </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSuiteRule.java" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>cc_toolchain_suite(<a href="#cc_toolchain_suite.name">name</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.distribs">distribs</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="/reference/be/common-definitions#typical.licenses">licenses</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>)</pre></devsite-code> <p>Deprecated: the rule is a no-op and will be removed. <h3 id="cc_toolchain_suite_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="cc_toolchain_suite.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> </tbody> </table> <h2 id="fdo_prefetch_hints" data-text=" fdo_prefetch_hints " tabindex="-1"> fdo_prefetch_hints </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/blob/master/src/main/starlark/builtins_bzl/common/cc/fdo/fdo_prefetch_hints.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>fdo_prefetch_hints(<a href="#fdo_prefetch_hints.name">name</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.distribs">distribs</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="#fdo_prefetch_hints.profile">profile</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>)</pre></devsite-code> <p>Represents an FDO prefetch hints profile that is either in the workspace. Examples:</p> <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> fdo_prefetch_hints( name = "hints", profile = "//path/to/hints:profile.afdo", ) </code></pre></devsite-code> <h3 id="fdo_prefetch_hints_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="fdo_prefetch_hints.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="fdo_prefetch_hints.profile"> <code translate="no" dir="ltr">profile</code> </td> <td> <p><a href="/concepts/labels">Label</a>; required</p> Label of the hints profile. The hints file has the .afdo extension The label can also point to an fdo_absolute_path_profile rule. </td> </tr> </tbody> </table> <h2 id="fdo_profile" data-text=" fdo_profile " tabindex="-1"> fdo_profile </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/blob/master/src/main/starlark/builtins_bzl/common/cc/fdo/fdo_profile.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>fdo_profile(<a href="#fdo_profile.name">name</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.distribs">distribs</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="#fdo_profile.memprof_profile">memprof_profile</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="#fdo_profile.profile">profile</a>, <a href="#fdo_profile.proto_profile">proto_profile</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>)</pre></devsite-code> <p>Represents an FDO profile that is in the workspace. Example:</p> <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> fdo_profile( name = "fdo", profile = "//path/to/fdo:profile.zip", ) </code></pre></devsite-code> <h3 id="fdo_profile_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="fdo_profile.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="fdo_profile.memprof_profile"> <code translate="no" dir="ltr">memprof_profile</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Label of the MemProf profile. The profile is expected to have either a .profdata extension (for an indexed/symbolized memprof profile), or a .zip extension for a zipfile containing a memprof.profdata file. </td> </tr> <tr> <td id="fdo_profile.profile"> <code translate="no" dir="ltr">profile</code> </td> <td> <p><a href="/concepts/labels">Label</a>; required</p> Label of the FDO profile or a rule which generates it. The FDO file can have one of the following extensions: .profraw for unindexed LLVM profile, .profdata for indexed LLVM profile, .zip that holds an LLVM profraw profile, .afdo for AutoFDO profile, .xfdo for XBinary profile. The label can also point to an fdo_absolute_path_profile rule. </td> </tr> <tr> <td id="fdo_profile.proto_profile"> <code translate="no" dir="ltr">proto_profile</code> </td> <td> <p><a href="/concepts/labels">Label</a>; default is <code translate="no" dir="ltr">None</code></p> Label of the protobuf profile. </td> </tr> </tbody> </table> <h2 id="memprof_profile" data-text=" memprof_profile " tabindex="-1"> memprof_profile </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/blob/master/src/main/starlark/builtins_bzl/common/cc/fdo/memprof_profile.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>memprof_profile(<a href="#memprof_profile.name">name</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.distribs">distribs</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="#memprof_profile.profile">profile</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>)</pre></devsite-code> <p>Represents a MEMPROF profile that is in the workspace. Example:</p> <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> memprof_profile( name = "memprof", profile = "//path/to/memprof:profile.afdo", ) </code></pre></devsite-code> <h3 id="memprof_profile_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="memprof_profile.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="memprof_profile.profile"> <code translate="no" dir="ltr">profile</code> </td> <td> <p><a href="/concepts/labels">Label</a>; required</p> Label of the MEMPROF profile. The profile is expected to have either a .profdata extension (for an indexed/symbolized memprof profile), or a .zip extension for a zipfile containing a memprof.profdata file. The label can also point to an fdo_absolute_path_profile rule. </td> </tr> </tbody> </table> <h2 id="propeller_optimize" data-text=" propeller_optimize " tabindex="-1"> propeller_optimize </h2> <a class="button button-with-icon" href="https://github.com/bazelbuild/bazel/blob/master/src/main/starlark/builtins_bzl/common/cc/fdo/propeller_optimize.bzl" target="_blank"> View rule source<span class="material-icons icon-after" aria-hidden="true" translate="no">open_in_new</span> </a> <div></div><devsite-code><pre class="rule-signature" translate="no" dir="ltr" is-upgraded>propeller_optimize(<a href="#propeller_optimize.name">name</a>, <a href="#propeller_optimize.cc_profile">cc_profile</a>, <a href="/reference/be/common-definitions#common.compatible_with">compatible_with</a>, <a href="/reference/be/common-definitions#common.deprecation">deprecation</a>, <a href="/reference/be/common-definitions#common.distribs">distribs</a>, <a href="/reference/be/common-definitions#common.exec_compatible_with">exec_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_group_compatible_with">exec_group_compatible_with</a>, <a href="/reference/be/common-definitions#common.exec_properties">exec_properties</a>, <a href="/reference/be/common-definitions#common.features">features</a>, <a href="#propeller_optimize.ld_profile">ld_profile</a>, <a href="/reference/be/common-definitions#common.package_metadata">package_metadata</a>, <a href="/reference/be/common-definitions#common.restricted_to">restricted_to</a>, <a href="/reference/be/common-definitions#common.tags">tags</a>, <a href="/reference/be/common-definitions#common.target_compatible_with">target_compatible_with</a>, <a href="/reference/be/common-definitions#common.testonly">testonly</a>, <a href="/reference/be/common-definitions#common.toolchains">toolchains</a>, <a href="/reference/be/common-definitions#common.visibility">visibility</a>)</pre></devsite-code> <p>Represents a Propeller optimization profile in the workspace. Example:</p> <div></div><devsite-code><pre translate="no" dir="ltr" is-upgraded><code class="lang-starlark" translate="no" dir="ltr"> propeller_optimize( name = "layout", cc_profile = "//path:cc_profile.txt", ld_profile = "//path:ld_profile.txt" ) </code></pre></devsite-code> <h3 id="propeller_optimize_args" data-text="Arguments" tabindex="-1">Arguments</h3> <table class="table table-condensed table-bordered table-params"> <colgroup> <col class="col-param" /> <col class="param-description" /> </colgroup> <thead> <tr> <th colspan="2">Attributes</th> </tr> </thead> <tbody> <tr> <td id="propeller_optimize.name"><code translate="no" dir="ltr">name</code></td> <td> <p><a href="/concepts/labels#target-names">Name</a>; required</p> <p>A unique name for this target.</p> </td> </tr> <tr> <td id="propeller_optimize.cc_profile"> <code translate="no" dir="ltr">cc_profile</code> </td> <td> <p><a href="/concepts/labels">Label</a>; required</p> Label of the profile passed to the various compile actions. This file has the .txt extension. </td> </tr> <tr> <td id="propeller_optimize.ld_profile"> <code translate="no" dir="ltr">ld_profile</code> </td> <td> <p><a href="/concepts/labels">Label</a>; required</p> Label of the profile passed to the link action. This file has the .txt extension. </td> </tr> </tbody> </table> <!-- Generated footer --> </div> <devsite-thumb-rating position="footer"> </devsite-thumb-rating> <devsite-feedback position="footer" project-name="Bazel" product-id="5052038" bucket="https-bazel-build" context="" version="t-devsite-webserver-20250211-r00-rc00.466928218230179509" data-label="Send Feedback Button" track-type="feedback" track-name="sendFeedbackLink" track-metadata-position="footer" class="nocontent" project-icon="https://www.gstatic.com/devrel-devsite/prod/v38a693baeb774512feb42f10aac8f755d8791ed41119b5be7a531f8e16f8279f/bazel/images/touchicon-180.png" > <button> Send feedback </button> </devsite-feedback> <div class="devsite-floating-action-buttons"> </div> </article> <devsite-content-footer class="nocontent"> <p>Except as otherwise noted, the content of this page is licensed under the <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 License</a>, and code samples are licensed under the <a href="https://www.apache.org/licenses/LICENSE-2.0">Apache 2.0 License</a>. For details, see the <a href="https://developers.google.com/site-policies">Google Developers Site Policies</a>. Java is a registered trademark of Oracle and/or its affiliates.</p> <p>Last updated 2025-02-13 UTC.</p> </devsite-content-footer> <devsite-notification > </devsite-notification> <div class="devsite-content-data"> <template class="devsite-thumb-rating-feedback"> <devsite-feedback position="thumb-rating" project-name="Bazel" product-id="5052038" bucket="https-bazel-build" context="" version="t-devsite-webserver-20250211-r00-rc00.466928218230179509" data-label="Send Feedback Button" track-type="feedback" track-name="sendFeedbackLink" track-metadata-position="thumb-rating" class="nocontent" project-icon="https://www.gstatic.com/devrel-devsite/prod/v38a693baeb774512feb42f10aac8f755d8791ed41119b5be7a531f8e16f8279f/bazel/images/touchicon-180.png" > <button> Need to tell us more? </button> </devsite-feedback> </template> <template class="devsite-content-data-template"> [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-13 UTC."],[],[]] </template> </div> </devsite-content> </main> <devsite-footer-promos class="devsite-footer"> </devsite-footer-promos> <devsite-footer-linkboxes class="devsite-footer"> <nav class="devsite-footer-linkboxes nocontent" aria-label="Footer links"> <ul class="devsite-footer-linkboxes-list"> <li class="devsite-footer-linkbox "> <h3 class="devsite-footer-linkbox-heading no-link">About</h3> <ul class="devsite-footer-linkbox-list"> <li class="devsite-footer-linkbox-item"> <a href="/community/users" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 1)" > Who's using Bazel </a> </li> <li class="devsite-footer-linkbox-item"> <a href="/contribute/" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 2)" > Contribute </a> </li> <li class="devsite-footer-linkbox-item"> <a href="/contribute/contribution-policy" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 3)" > Governance model </a> </li> <li class="devsite-footer-linkbox-item"> <a href="/release" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 4)" > Release model </a> </li> <li class="devsite-footer-linkbox-item"> <a href="/brand" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 5)" > Brand guidelines </a> </li> </ul> </li> <li class="devsite-footer-linkbox "> <h3 class="devsite-footer-linkbox-heading no-link">Stay connected</h3> <ul class="devsite-footer-linkbox-list"> <li class="devsite-footer-linkbox-item"> <a href="//blog.bazel.build" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 1)" > Blog </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//github.com/bazelbuild/bazel" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 2)" > GitHub </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//twitter.com/bazelbuild" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 3)" > Twitter </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//youtube.com/user/googleOSPO" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 4)" > YouTube </a> </li> </ul> </li> <li class="devsite-footer-linkbox "> <h3 class="devsite-footer-linkbox-heading no-link">Support</h3> <ul class="devsite-footer-linkbox-list"> <li class="devsite-footer-linkbox-item"> <a href="/help" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 1)" > Support </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//github.com/bazelbuild/bazel/issues" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 2)" > Issue tracker </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//slack.bazel.build" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 3)" > Slack </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//stackoverflow.com/questions/tagged/bazel" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 4)" > Stack Overflow </a> </li> </ul> </li> </ul> </nav> </devsite-footer-linkboxes> <devsite-footer-utility class="devsite-footer"> <div class="devsite-footer-utility nocontent"> <nav class="devsite-footer-utility-links" aria-label="Utility links"> <ul class="devsite-footer-utility-list"> <li class="devsite-footer-utility-item "> <a class="devsite-footer-utility-link gc-analytics-event" href="//policies.google.com/terms" data-category="Site-Wide Custom Events" data-label="Footer Terms link" > Terms </a> </li> <li class="devsite-footer-utility-item "> <a class="devsite-footer-utility-link gc-analytics-event" href="//policies.google.com/privacy" data-category="Site-Wide Custom Events" data-label="Footer Privacy link" > Privacy </a> </li> <li class="devsite-footer-utility-item glue-cookie-notification-bar-control"> <a class="devsite-footer-utility-link gc-analytics-event" href="#" data-category="Site-Wide Custom Events" data-label="Footer Manage cookies link" aria-hidden="true" > Manage cookies </a> </li> </ul> <devsite-language-selector> <ul role="presentation"> <li role="presentation"> <a role="menuitem" lang="en" >English</a> </li> <li role="presentation"> <a role="menuitem" lang="es_419" >Español – América Latina</a> </li> <li role="presentation"> <a role="menuitem" lang="id" >Indonesia</a> </li> <li role="presentation"> <a role="menuitem" lang="pt_br" >Português – Brasil</a> </li> <li role="presentation"> <a role="menuitem" lang="vi" >Tiếng Việt</a> </li> <li role="presentation"> <a role="menuitem" lang="tr" >Türkçe</a> </li> <li role="presentation"> <a role="menuitem" lang="hi" >हिंदी</a> </li> <li role="presentation"> <a role="menuitem" lang="th" >ภาษาไทย</a> </li> <li role="presentation"> <a role="menuitem" lang="zh_cn" >中文 – 简体</a> </li> <li role="presentation"> <a role="menuitem" lang="zh_tw" >中文 – 繁體</a> </li> <li role="presentation"> <a role="menuitem" lang="ja" >日本語</a> </li> <li role="presentation"> <a role="menuitem" lang="ko" >한국어</a> </li> </ul> </devsite-language-selector> </nav> </div> </devsite-footer-utility> <devsite-panel></devsite-panel> </section></section> <devsite-sitemask></devsite-sitemask> <devsite-snackbar></devsite-snackbar> <devsite-tooltip ></devsite-tooltip> <devsite-heading-link></devsite-heading-link> <devsite-analytics> <script type="application/json" analytics>[{"dimensions": {"dimension3": "en", "dimension4": "en", "dimension1": "Signed out", "dimension2": false, "dimension5": false}, "gaid": "UA-61082125-3", "metrics": {}, "purpose": 0}]</script> <script type="application/json" tag-management>{"at": "True", "ga4": [{"id": "G-GBZW986TQ3", "purpose": 0}], "ga4p": [{"id": "G-GBZW986TQ3", "purpose": 0}], "gtm": [], "parameters": {"internalUser": "False", "language": {"machineTranslated": "False", "requested": "en", "served": "en"}, "pageType": "article", "projectName": "Bazel", "signedIn": "False", "tenant": "bazel", "recommendations": {"sourcePage": "", "sourceType": 0, "sourceRank": 0, "sourceIdenticalDescriptions": 0, "sourceTitleWords": 0, "sourceDescriptionWords": 0, "experiment": ""}, "experiment": {"ids": ""}}}</script> </devsite-analytics> <devsite-badger></devsite-badger> <script nonce="Ly7FzZxTP+eY4K1awambWjubQrvjA5"> (function(d,e,v,s,i,t,E){d['GoogleDevelopersObject']=i; t=e.createElement(v);t.async=1;t.src=s;E=e.getElementsByTagName(v)[0]; E.parentNode.insertBefore(t,E);})(window, document, 'script', 'https://www.gstatic.com/devrel-devsite/prod/v38a693baeb774512feb42f10aac8f755d8791ed41119b5be7a531f8e16f8279f/bazel/js/app_loader.js', '[40,"en",null,"/js/devsite_app_module.js","https://www.gstatic.com/devrel-devsite/prod/v38a693baeb774512feb42f10aac8f755d8791ed41119b5be7a531f8e16f8279f","https://www.gstatic.com/devrel-devsite/prod/v38a693baeb774512feb42f10aac8f755d8791ed41119b5be7a531f8e16f8279f/bazel","https://bazel-dot-devsite-v2-prod-3p.appspot.com",null,null,["/_pwa/bazel/manifest.json","https://www.gstatic.com/devrel-devsite/prod/v38a693baeb774512feb42f10aac8f755d8791ed41119b5be7a531f8e16f8279f/images/video-placeholder.svg","https://www.gstatic.com/devrel-devsite/prod/v38a693baeb774512feb42f10aac8f755d8791ed41119b5be7a531f8e16f8279f/bazel/images/favicon-prod.png","https://www.gstatic.com/devrel-devsite/prod/v38a693baeb774512feb42f10aac8f755d8791ed41119b5be7a531f8e16f8279f/bazel/images/lockup.svg","https://fonts.googleapis.com/css?family=Roboto:300,400,400italic,500,500italic,700,700italic|Roboto+Mono:400,500,700&display=swap"],1,null,[1,6,8,12,14,17,21,25,50,52,63,70,75,76,80,87,91,92,93,97,98,100,101,102,103,104,105,107,108,109,110,112,113,116,117,118,120,122,124,125,126,127,129,130,131,132,133,134,135,136,138,140,141,147,148,149,151,152,156,157,158,159,161,163,164,168,169,170,179,180,182,183,186,191,193,196],"AIzaSyCNm9YxQumEXwGJgTDjxoxXK6m1F-9720Q","AIzaSyCc76DZePGtoyUjqKrLdsMGk_ry7sljLbY","bazel.build","AIzaSyB9bqgQ2t11WJsOX8qNsCQ6U-w91mmqF-I","AIzaSyAdYnStPdzjcJJtQ0mvIaeaMKj7_t6J_Fg",null,null,null,["Analytics__enable_clearcut_logging","SignIn__enable_refresh_access_tokens","MiscFeatureFlags__enable_explain_this_code","Profiles__enable_completequiz_endpoint","Profiles__enable_stripe_subscription_management","Search__enable_dynamic_content_confidential_banner","DevPro__enable_cloud_innovators_plus","BookNav__enable_tenant_cache_key","Cloud__enable_llm_concierge_chat","Profiles__enable_completecodelab_endpoint","MiscFeatureFlags__developers_footer_dark_image","Cloud__enable_legacy_calculator_redirect","Search__enable_suggestions_from_borg","CloudShell__cloud_code_overflow_menu","Profiles__enable_page_saving","Concierge__enable_pushui","CloudShell__cloud_shell_button","DevPro__enable_developer_subscriptions","OnSwitch__enable","Cloud__enable_free_trial_server_call","Cloud__enable_cloudx_experiment_ids","Cloud__enable_cloudx_ping","MiscFeatureFlags__developers_footer_image","Profiles__enable_release_notes_notifications","Cloud__enable_cloud_shell","MiscFeatureFlags__enable_view_transitions","Profiles__enable_awarding_url","Profiles__enable_dashboard_curated_recommendations","Profiles__enable_developer_profiles_callout","TpcFeatures__enable_mirror_tenant_redirects","Cloud__enable_cloud_dlp_service","SignIn__enable_oauth_multi_account_support","Cloud__enable_cloud_shell_fte_user_flow","Profiles__require_profile_eligibility_for_signin","Profiles__enable_public_developer_profiles","Profiles__enable_join_program_group_endpoint","MiscFeatureFlags__enable_firebase_utm","Search__enable_page_map","Profiles__enable_complete_playlist_endpoint","MiscFeatureFlags__emergency_css","Profiles__enable_profile_collections","MiscFeatureFlags__enable_project_variables","Cloud__enable_cloud_facet_chat","SignIn__enable_auto_login_multi_account","Experiments__reqs_query_experiments","TpcFeatures__enable_unmirrored_page_left_nav","EngEduTelemetry__enable_engedu_telemetry","Search__enable_ai_eligibility_checks","Profiles__enable_recognition_badges","MiscFeatureFlags__enable_variable_operator"],null,null,"AIzaSyA58TaKli1DculwmAmbpzLVGuWc8eCQgQc","https://developerscontentserving-pa.googleapis.com","AIzaSyDWBU60w0P9hEkr29kkksYs8Z7gvZ8u_wc","https://developerscontentsearch-pa.googleapis.com",2,4,null,"https://developerprofiles-pa.googleapis.com",[40,"bazel","Bazel","bazel.build",null,"bazel-dot-devsite-v2-prod-3p.appspot.com",null,null,[null,1,null,null,null,null,null,null,null,null,null,[1],null,null,null,null,null,null,[1],null,null,null,null,[1,1,1],[1,1,null,1,1]],null,[56,null,null,null,null,null,"/images/lockup.svg",null,null,null,null,1,null,null,null,null,null,null,null,null,null,1,null,null,null,null,[]],[],null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[6,7,1,18,20,22,23,29,37,39,40,43],null,[[],[1,1]],[[["UA-61082125-3"],["UA-61082125-4"],null,null,["UA-61082125-5"],null,null,[["G-GBZW986TQ3"],null,null,[["G-GBZW986TQ3",1]]],[["UA-61082125-3",1]],null,[["UA-61082125-5",1]],null,1],[[3,4],[2,2],[4,5],[5,8],[1,1]]],null,4],null,null,1]') </script> <devsite-a11y-announce></devsite-a11y-announce> </body> </html>