Filesystem library problems

Hello,

This problem might be a little bit more software but I am not sure how to deal with it.

I want to configure my apalis imx6 to connect to a Filezilla server on a different device.
I am writing code one C++ with VS Code and ApolloX Torizon.

The problem is that I am trying to use the library. At first it gives no errors but when I press run and debug then I get the ‘filesystem’ has not been declared error.

From what I understood I have to configure something in tasks.json like the following:

"tasks": [
  {
    "label": "build",
    "type": "shell",
    "command": "g++",
    "args": [
      "-g",
      "${file}",
      "-o",
      "${fileDirname}/${fileBasenameNoExtension}",
      "-lstdc++fs"
    ],
    "group": {
      "kind": "build",
      "isDefault": true
    }
  }
]

But I don’t know where exactly to put it in the file and what parameters I need to put here: "${fileDirname}/${fileBasenameNoExtension.

Also this is my code:

void connectToFtpServer(const string& serverAddress, const string& username, const string& password) {
    filesystem::path ftpUrl = "ftp://" + username + ":" + password + "@" + serverAddress + "/";
    cout << "Connecting to FTP server " << serverAddress << " as user " << username << std::endl;

    cout << "Listing directory contents:" << std::endl;
    for (const auto& entry : filesystem::directory_iterator(ftpUrl)) {
        cout << entry.path() << endl;
    }
}

void uploadFileToFtpServer(const string& localFilePath, const string& remoteFilePath, const string& serverAddress, const string& username, const string& password) {
    filesystem::path remoteFileUrl = "ftp://" + username + ":" + password + "@" + serverAddress + "/" + remoteFilePath;
    cout << "Uploading file " << localFilePath << " to remote location " << remoteFileUrl << endl;
    filesystem::copy(localFilePath, remoteFileUrl, filesystem::copy_options::skip_existing);
    cout << "File uploaded succesfully" << endl;
}


I am not sure if this is because something is not configured in VS Code to use this library or something is not configured on my Torizon.
I checked the version of C++ in VS Code and it should be able to support the library.

Could you try to add add #include <filesystem> at the top of your code file, before any function declarations, to include the header file that declares the filesystem library?

I have done that already.

Hi @Svetoslav !

If I understood correctly, it is indeed related to software.

Therefore, I have a question:
If we for a moment forget about Apalis, Torizon, and ApolloX, are you able to create a program in your computer that successfully connects and communicates (file exchange) with the FTP server?

When I am developing something, I usually prefer to be sure that I am able to make it work without all the difficulties and specifics of the embedded system. Of course, it is not always possible to do this, but in your case, I think that it should be possible.

Best regards,

I can’t test the connection at the moment but my main problem is that the library is not recognized in the system I don’t know if the connection is even available since I can’t go pass the errors.

Hi @Svetoslav !

If the problem is with the usage of filesystem, you can try a simpler example, right?

Like creating a common file, moving, copying, etc.

Then you don’t even need the FTP.

It’s important to find ways to simplify the problem in order to solve it.

Best regards,

I already tried this.

Using filesystem for checking how much memory is used in a specific folder but it doesn’t work there either.
Is that wat you meant to try?

Dear @Svetoslav,

Using filesystem for checking how much memory is used in a specific folder but it doesn’t work there either.

Could you get this simple program running on your development machine without any errors?
Does it work if you access the filesystem functions like this example: std::filesystem::path
Please take a look at this: c++ - 'std::filesystem' has not been declared after including <experimental/filesystem> - Stack Overflow

Let me know if that helps :slight_smile:

Dear @Svetoslav,

Do you have any updates on this topic?