Skip to content

[Bug] MacOS issues #17

@BlueFalconHD

Description

@BlueFalconHD

On my macOS system, I have included mate.h and the base example mate.c in my example hello world program:

#define MATE_IMPLEMENTATION // Adds function implementations
#include "mate.h"

i32 main() {
  StartBuild();
  {
    Executable executable = CreateExecutable((ExecutableOptions){
        .output = "main",   // output name, in windows this becomes `main.exe`
                            // automatically
        .flags = "-Wall -g" // adds warnings and debug symbols
    });

    // Files to compile
    AddFile(executable, "./Sources/main.c");

    // Compiles all files parallely with samurai
    InstallExecutable(executable);

    // Runs `./build/main` or `./build/main.exe` depending on the platform
    RunCommand(executable.outputPath);
  }
  EndBuild();
}

Upon attempting to build, I get the following errors:

hayes@fortis cvm main % clang ./mate.c -o ./mate && ./mate
In file included from ./mate.c:2:
./mate.h:1797:27: error: use of undeclared identifier 'PATH_MAX'
 1797 |   static char currentPath[PATH_MAX];
      |                           ^
./mate.h:1798:27: error: use of undeclared identifier 'PATH_MAX'
 1798 |   if (getcwd(currentPath, PATH_MAX) == NULL) {
      |                           ^
./mate.c:20:5: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]
   20 |     RunCommand(executable.outputPath);
      |     ^~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~
1 warning and 2 errors generated.

I am assuming PATH_MAX has to do with file paths, given the context provided by the error message, so at the top of mate.c I included the following block:

#ifdef __APPLE__
#define PATH_MAX 1024
#elif defined(__linux__) || defined(__unix__) || defined(__unix)
#define PATH_MAX 4096
#elif defined(_WIN32) || defined(_WIN64)
#define PATH_MAX 260
#else
#define PATH_MAX 1024 // fallback
#endif

Which contains the maximum filesystem path lengths for anything I know of plus a fall back. After solving that issue, another arises:

hayes@fortis cvm main % clang ./mate.c -o ./mate && ./mate
./mate.c:36:5: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]
   36 |     RunCommand(executable.outputPath);
      |     ^~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
[WARN]: IniParse: /Users/hayes/Stores/repos/bluefalconhd/cvm/build/mate-cache.ini does not exist, creating...
ld: library 'rt' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Assertion failed: err == SUCCESS, file ./mate.h, line 5483
[ERROR]: MateReadCache: Error meanwhile compiling samurai at /Users/hayes/Stores/repos/bluefalconhd/cvm/build/samurai.c, if you are seeing this please make an issue at github.com/TomasBorquez/mate.h
fish: Job 1, './mate' terminated by signal SIGABRT (Abort)

librt (based on testing outside a mate project) seems to be included by default on macOS (while using Clang at least). A separate library doesn't even exist for it. To solve this, I simply removed the dependency from mate.h:

diff --git a/mate.h b/mate.h
index f0dd486..00f3b7f 100644
--- a/mate.h
+++ b/mate.h
@@ -5477,7 +5477,7 @@ static void mateReadCache(void) {
     Assert(errFileWrite == SUCCESS, "MateReadCache: failed writing samurai source code to path %s", sourcePath.data);
 
     String outputPath = F(mateState.arena, "%s/samurai", mateState.buildDirectory.data);
-    String compileCommand = F(mateState.arena, "%s \"%s\" -o \"%s\" -lrt -std=c99", CompilerToStr(mateState.compiler).data, sourcePath.data, outputPath.data);
+    String compileCommand = F(mateState.arena, "%s \"%s\" -o \"%s\" -std=c99", CompilerToStr(mateState.compiler).data, sourcePath.data, outputPath.data);
 
     errno_t err = RunCommand(compileCommand);
     Assert(err == SUCCESS, "MateReadCache: Error meanwhile compiling samurai at %s, if you are seeing this please make an issue at github.com/TomasBorquez/mate.h", sourcePath.data);

I'm not entirely sure what causes these issues, but I figured since the current state of testing for macOS is limited, I'd jump in and try to contribute. My fix is a band-aid solution, but if anyone else is having similar issues on macOS you might want to try it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions