WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

NOB_GO_REBUILD_URSELF fails if not run from the same folder where its source code is located #156

@rexim

Description

@rexim

Repro

$ cat nob.c
#define NOB_IMPLEMENTATION
#define NOB_STRIP_PREFIX
#include "nob.h"

int main(int argc, char **argv)
{
    NOB_GO_REBUILD_URSELF(argc, argv);
    return 0;
}
$ cc -o nob nob.c
$ mkdir foo && cd foo
$ ../nob
[ERROR] could not stat nob.c: No such file or directory

Workaround

--- nob.c	2025-10-30 08:20:33.984305999 +0700
+++ nob.fixed.c	2025-10-30 08:20:59.128496254 +0700
@@ -4,6 +4,7 @@

 int main(int argc, char **argv)
 {
+    if (!set_current_dir(temp_dir_name(temp_running_executable_path()))) return 1;
+    argv[0] = temp_sprintf("./%s", temp_file_name(argv[0]));
     NOB_GO_REBUILD_URSELF(argc, argv);
     return 0;
 }

Potential solution

Maybe NOB_GO_REBUILD_URSELF() should imply the above Workaround (that is should be just included in nob__go_rebuild_urself). But I'm not sure about any potential pitfalls of this solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions