Skip to content

[Linting Rule] Compiled Code

github-actions[bot] edited this page Oct 27, 2026 · 1 revision

Generated from 'wiki-linter.ts' on 2026-10-25, 09:29:25 UTC (v2.16.6), do not edit directly.

Compiled Code [overview]

cmd-check 20, 65–78

This rule ports the following steps of R CMD check (see the conformance table for the legend):

# Step Coverage Note
20 line endings in shell scripts (book) 🟩
65 compilation flags in Makevars (book) 🟩
66 use of PKG_*FLAGS in Makefiles (book) 🟩
67 use of SHLIB_OPENMP_*FLAGS in Makefiles (book) 🟩⭐ ⭐ also runs without setting an environment variable
68 for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) (book) 🟩
69 for GNU extensions in Makefiles (book) 🟩
70 include directives in Makefiles (book) 🟩
71 line endings in Makefiles (book) 🟩
72 line endings in C/C++/Fortran sources/headers (book) 🟩
73 pragmas in C/C++ headers and code (book) 🟩⭐ ⭐ also runs without setting an environment variable
74 usage of KIND in Fortran files (book) 🟩⭐ ⭐ also byte count declarations like real*8
75 C++ specification (book) 🟩
76 compiled code (book) 🔷 the calls the shared object would import, read off the sources
77 whether package can be installed (book) 🔷⭐ ⭐ also compiled code never loaded for lack of useDynLib
useDynLib and src/ in agreement, headers from LinkingTo, undefined exports
78 compilation flags used (book) 🔷 the flags the Makevars state, not the ones the toolchain was called with

This rule is a best-effort rule.

Finds problems in src/ and the build files: non-portable Makevars flags, BLAS/LAPACK and OpenMP flag use, GNU make extensions, pragmas, line endings, Fortran KIND, the C++ standard, calls to non-API or non-portable entry points, and useDynLib against src/.
This linting rule is implemented in src/linter/rules/cmd-check/compiled-code.ts.

Configuration

Linting rules can be configured by passing a configuration object to the linter query as shown in the example below. The compiled-code rule accepts the following configuration options:

  • allowedFlags
    flags (with the dash) that are fine even though they match nonPortableFlags
    R CMD check #65, #78
  • checkNonApi
    also look for calls of the non-API entry points of R (default true)
    R CMD check #76
  • checkRegistration
    also look for the missing registration of native routines (default true)
    R CMD check #76
  • extraNonApiEntryPoints
    further non-API entry points to flag besides the ones R lists
    R CMD check #76
  • flagStarKinds
    also flag Fortran type declarations like real*8, which are no standard Fortran (default true)
    R CMD check #74
  • headerPackages
    the header (a file name, or a directory prefix ending in /) to the package that has to be in LinkingTo for it
    R CMD check #77
  • knownCxxStandards
    the C++ standards R still honors; others requested through CXX_STD are unknown
    R CMD check #75
  • nonPortableFlags
    regular expressions (anchored by flowR, without the leading dash) for the compiler flags R CMD check calls non-portable
    R CMD check #65, #78
  • obsoleteCxxStandards
    the C++ standards R ignores as obsolete
    R CMD check #75
  • skip
    checks (by their R CMD check title) to skip
  • unportableCalls
    the functions compiled code must not call because they might terminate R, write to stdout, use system RNGs or [v]sprintf
    R CMD check #76
  • unportableFortran
    the Fortran statements compiled code must not use (I/O, stop, system RNGs)
    R CMD check #76
  • unportableObjects
    the objects (and C++ streams) compiled code must not use for the same reason
    R CMD check #76

Examples

A project with the code R/code.R:

f <- function(x) .Call("C_f", x)

and the files

DESCRIPTION:

Package: pkg
Version: 1.0
Title: A Package
License: MIT

NAMESPACE:

useDynLib(pkg)
export(f)

src/Makevars:

PKG_CXXFLAGS = -O3 -Wall -fPIC

The linting query can be used to run this rule on the above example:

[ { "type": "linter",   "rules": [ { "name": "compiled-code",     "config": {} } ] } ]

Results (prettified and summarized):

Query: linter (3 ms)
   ╰ Compiled Code (compiled-code):
       ╰ certain:
           ╰ Non-portable flags in variable 'PKG_CXXFLAGS': -O3 -Wall -fPIC at /pkg/src/Makevars:1.1
           ╰ PKG_CXXFLAGS set in 'src/Makevars' without any corresponding files at /pkg/src/Makevars:1.1

More examples are the test cases in test/functionality/linter/cmd-check/lint-compiled-code.test.ts.

Clone this wiki locally