Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"[file error] file <> could not be opened" (update) #11

Closed
gabrielgcma opened this issue Mar 29, 2023 · 7 comments
Closed

"[file error] file <> could not be opened" (update) #11

gabrielgcma opened this issue Mar 29, 2023 · 7 comments

Comments

@gabrielgcma
Copy link

Hi! It's me from my previous issue.

I changed Importer.cpp to print out the filepath it was receiving:

Engine* Importer::fromFile(const std::string& path) const {
        std::cout << "path: " << path << '\n';
        std::cout << "path.c_str(): " << path.c_str() << '\n';
        std::ifstream reader(path.c_str());
. . . 

And the ouptut is:

path:
path.c_str(): X÷ÿ↕]
[file error] file <> could not be opened
{at \src\imex\Importer.cpp::fl::Importer::fromFile() [line:33]}

I tried rebuilding the library using build.bat, and already tried fiddling with all of the build options (backtrace, float=on). It builds just fine, the linker on Visual Studio seems to be doing okay and etc, but nothing seems to fix the problem. I also tried using the 32bit version of the lib.

Here's my project setup on Visual Studio:

image
image
image
image

Am I missing a command line argument? A preprocessor parameter? Thanks for your time.

@jcrada
Copy link
Member

jcrada commented Mar 29, 2023

Hi Gabriel,

This is so odd. Have you tried changing the parameter you pass as path? Maybe even printing it before passing it to the method?

You should be using 64bit. Now, for the configuration, I think you only need to:

  1. Add the library directory as you do in first picture, but making sure that the directory at that level contains the fuzzylite binaries (dll and lib)
  2. In same picture as (1), add the fuzzylite headers, such that the directory you add at that level contains fl/Headers.h.

You probably can do (1) and (2) in the additional library and additional headers instead, but it is not necessary to add in both places. Also, the additional dependencies should not be needed because VS would find the dll and libraries from the library directory.

@gabrielgcma
Copy link
Author

This is so odd. Have you tried changing the parameter you pass as path? Maybe even printing it before passing it to the method?

I did, I also checked permissions. I think the problem isn't on the file or the filepath, given that I can access and get its content just fine using std::fstream. I tried printing the filepath before passing to the method, and it's ok.

  1. Add the library directory as you do in first picture, but making sure that the directory at that level contains the fuzzylite binaries (dll and lib)

That would be fuzzylite\release\bin, right?

  1. In same picture as (1), add the fuzzylite headers, such that the directory you add at that level contains fl/Headers.h.

That would be just fuzzylite, right?

Following these steps, my VC++ lib directories are:

image

Also, the additional dependencies should not be needed because VS would find the dll and libraries from the library directory.

If remove them, I get linker errors:

image


Also, I tried saving the file content to a string and importing the .fis via string using .fromString():

#include <iostream>
#include <fl/Headers.h>
#include <fstream>

int main()
{
    const std::string filePath = "C:\\Users\\amado\\logicaFuzzy\\regras.fis";

    //std::cout << filePath << std::endl;

    std::ifstream file(filePath);
    std::stringstream buffer;
    buffer << file.rdbuf();
    std::string fisString = buffer.str();

    //std::cout << fisString << std::endl;

    fl::Engine* engine = new fl::Engine;

    try
    {
        //engine = fl::FisImporter().fromFile(filePath);
        engine = fl::FisImporter().fromString(fisString);
    }
    catch (fl::Exception& e)
    {
        std::cerr << e.what() << std::endl; 
    }

    if (engine->isReady())
        std::cout << "Ready\n";
    else
        std::cout << "Error\n";

    return 0;
}

and it seems to run just fine since no exceptions are thrown, but engine->isReady() returns false. Do you have any idea why? I'll attach the .fis file I'm trying to import as .txt so you can have a look.

regras.txt

@jcrada
Copy link
Member

jcrada commented Mar 30, 2023

Good you found a workaround. It is an odd issue.

That would be fuzzylite\release\bin, right?

Yes, only that should be enough.

engine->isReady() returns false

std::string message;
engine->isReady(&message);
// now message contains the reason why is not ready

@gabrielgcma
Copy link
Author

gabrielgcma commented Mar 30, 2023

Oh yes, I forgot about the status string.

But take a look:

std::string status;
if (engine->isReady(&status))
    std::cout << "Ready\n";
else
    std::cout << status << std::endl;

Output:
fo╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠

This is exactly what the status string is printing to the console. I'm considering giving up :( your lib is amazing anyway.

@jcrada
Copy link
Member

jcrada commented Mar 30, 2023

When you compiled from console, did it work? #10 (comment)

@jcrada
Copy link
Member

jcrada commented Mar 30, 2023

Also, when you built the fuzzylite library, are you sure you are using the newly built binaries as opposed to the binaries provided in my distribution? Maybe make sure you first delete the binaries that you did not build, and then build the libraries.

There must be some issue with the binaries or a funny flag when you are building your application.

Check this:
https://stackoverflow.com/questions/54944874/stdstring-gets-corrupted-change-structure-when-passed-to-a-library

This problem generally occurs when library is compiled in "Release" mode and you are trying to run application in "Debug" mode.

@gabrielgcma
Copy link
Author

@jcrada thank you so much for the help! That was the problem: the project was in Debug mode and I compiled the lib using Release. Now everything is working properly when I make them compatible. Thanks!

@jcrada jcrada closed this as completed Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants