Skip to content

Conversation

@jklincn
Copy link
Contributor

@jklincn jklincn commented Mar 11, 2025

std::filesystem::current_path() returns path without '/', leading to path error when trying to load the base backend.

I provide a simple example to demonstrate.

lin@amx:~/bs$ touch test.txt
lin@amx:~/bs$ cat error.cpp
#include <filesystem>
#include <iostream>
namespace fs = std::filesystem;
 
int main()
{
    fs::path search_path = fs::current_path();
    fs::path filename = "test.txt";
    fs::path path = search_path.native() + filename.native();
    if (fs::exists(path)) {
        std::cout << "File exists." << std::endl;
    } else {
        std::cout << "File does not exist." << std::endl;
    }
}
lin@amx:~/bs$ g++ error.cpp --std=c++17
lin@amx:~/bs$ ./a.out 
File does not exist.
lin@amx:~/bs$ diff error.cpp correct.cpp 
7c7
<     fs::path search_path = fs::current_path();
---
>     fs::path search_path = fs::current_path() / "";
lin@amx:~/bs$ g++ correct.cpp --std=c++17
lin@amx:~/bs$ ./a.out 
File exists.

Refenence: https://en.cppreference.com/w/cpp/filesystem/current_path

@github-actions github-actions bot added the ggml changes relating to the ggml tensor library for machine learning label Mar 11, 2025
@slaren
Copy link
Member

slaren commented Mar 11, 2025

We should probably use the / operator to build the path instead:

fs::path path = search_path / filename;

@jklincn
Copy link
Contributor Author

jklincn commented Mar 11, 2025

Thank you! I have made the changes and also addressed a few other places where .native() was used.

@slaren slaren merged commit ba76543 into ggml-org:master Mar 11, 2025
47 checks passed
ishaangandhi pushed a commit to ishaangandhi/llama.cpp that referenced this pull request Mar 12, 2025
* Fix backend search path

* replace .native() with '/'

* reverted .native()
jpohhhh pushed a commit to Telosnex/llama.cpp that referenced this pull request Mar 14, 2025
* Fix backend search path

* replace .native() with '/'

* reverted .native()
arthw pushed a commit to arthw/llama.cpp that referenced this pull request Mar 19, 2025
* Fix backend search path

* replace .native() with '/'

* reverted .native()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants