Lyricdev
GitHub

LYR-LNK0001

a C symbol nothing the link takes defines

error · spec 15-project

Reported by build, run, test and bench when the linker finds no definition of a symbol the program or a package's C calls. The finding stands at the extern declaration that names the symbol, where the program declares it; else it says what references it. Nothing is linked; the exit code is 2.

Explanation

An extern "C" fn declaration promises that some C defines the function. The compiler takes the promise; the linker checks it, against everything the link takes: the program, the packages' C sources and archives, the libraries their [native] parts and build scripts name, the runtime. When none of them defines the symbol, the link fails, and this finding points at the declaration.

Most often the library that defines it is not named. Name it where the package says what it links: libs for a library of the system by name, archives for one the package brings prebuilt, frameworks on macOS, pkgConfig for one pkg-config knows — or let the build script link it. A symbol spelled otherwise than the C header spells it, or a function the header declares only as a macro, is the other common cause: compare the declaration with the header, or have lyric bindgen write it.

Example

$ cat src/main.lyr
extern "C" fn sqlite3_libversion(): CStr;

fn main(): void {
    let _ = sqlite3_libversion();
}
$ lyric5 build
error[LYR-LNK0001]: nothing the link takes defines 'sqlite3_libversion'
 --> src/main.lyr:1:1
  |
1 | extern "C" fn sqlite3_libversion(): CStr;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ declared here, and defined nowhere the link looks
  |
  = help: name the library that defines it in the package's [native] — 'libs', 'archives', 'frameworks' or 'pkgConfig' — or link it from the build script