"undefined reference" in exported function

I compiled a Zig project using -Doptimize=ReleaseSmall to a library file. When I link against this file using gcc I get an error message from my linker saying undefined reference to '\__zig_probe_stack’

However, when I compile with any other optimize mode, I don’t receive this error. Moreover, when I compile with zig cc, I also don’t receive it.

How can I make this symbol “available” (forgive me, linkers aren’t my forte so I don’t know the correct term) to my linker?

Notes:

  • my zig version is “0.15.2”
  • my OS is “Linux Mint 22.2 x86_64”
  • The library file is compiled with this command: zig build install -Dtarget=x86_64-linux-gnu -Doptimize=ReleaseSafe
  • The source code is linked with this command: gcc demo-anyline.c -o demo-anyline libanyline.a
  • The library code can be found here.
  • The source code being linked:
//demo-anyline.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "anyline.h"

int main(void)
{
    using_history();

    char *filename = "/home/theshinx317/Coding/C/anyline-export/.demo_history";
    read_history(filename);

    for (;;) {
        char *line = readline(">> ");

        if(strcmp(line, ".exit") == 0) {
            break;
        }

        add_history(line);
    }

    write_history(filename);

    return 0;
}

//anyline.h
extern char *readline (const char *prompt);
extern void add_history (const char *line);
extern int read_history (const char *filename);
extern int write_history (const char *filename);
extern void using_history(void);
1 Like

__zig_probe_stack is part of the compiler_rt library.
In your build.zig try exe.bundle_compiler_rt = true;

3 Likes

You were 99% of the way there! Since I’m compiling to a library, I needed to change my lib instead of my exe. They are both std/Build/Step/Compile.zig structs, so easy mistake to make.

Either way, thanks for the help!