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" when trying to import .fis #10

Closed
gabrielgcma opened this issue Mar 24, 2023 · 5 comments
Closed

Comments

@gabrielgcma
Copy link

gabrielgcma commented Mar 24, 2023

I'm trying to import a .fis file:

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

int main()
{
    std::string filePath = "C:\\Users\\me\\fuzzyLogic\\rules.fis";

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

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

Which is outputting to the console:

[file error] file <> could not be opened
{at \src\imex\Importer.cpp::fl::Importer::fromFile() [line:31]}

Line 31 from Importer.cpp checks whether or not the reader is open:

if (not reader.is_open()) {
            throw Exception("[file error] file <" + path + "> could not be opened", FL_AT);
}

So it seems the file path is blank when it's passed to the reader at line 29:

std::ifstream reader(path.c_str());

I'm currently using Visual Studio Community 2022 17.5.0 with Visual C++ 2022, on Windows 11.

@jcrada
Copy link
Member

jcrada commented Mar 24, 2023

That's a bit odd. Some thoughts to experiment:

  1. Delete the path and write it again manually. Just thinking of a null character passed inadvertently before "C:" and hence the empty path.
  2. Try putting the fis file where you are running your code so instead of a full path you just have "rules.fis". Thinking of issues escaping path separators.
  3. Make sure the file exists and you can edit it with your text editor. Thinking of a different reason why the file could not be opened.
  4. Long shot, set the file path to const string and print it before passing it to the method. Also print c_str().

If nothing works, create a simple file where you try using the same tools in FuzzyLite to open the file and debug it to see why the file cannot be opened.

Let me know if any works. Cheers.

@gabrielgcma
Copy link
Author

That's a bit odd. Some thoughts to experiment:

  1. Delete the path and write it again manually. Just thinking of a null character passed inadvertently before "C:" and hence the empty path.
  2. Try putting the fis file where you are running your code so instead of a full path you just have "rules.fis". Thinking of issues escaping path separators.
  3. Make sure the file exists and you can edit it with your text editor. Thinking of a different reason why the file could not be opened.
  4. Long shot, set the file path to const string and print it before passing it to the method. Also print c_str().

If nothing works, create a simple file where you try using the same tools in FuzzyLite to open the file and debug it to see why the file cannot be opened.

Let me know if any works. Cheers.

Thanks for replying! Also (as I forgot to say earlier), amazing library!

Did step 1, nothing. I'm able to read the file's content using std::fstream and it's working properly.

Did step 2, now it's not even catching the exception, it's just throwing this again and again:

image

It's curious, given that I can access the file's content just fine using std::fstream

Step 3: it exists and I can open it.

Step 4: Using const did not work. Printing before the method prints the right path. Printing filePath.c_str() also prints the right path.

If nothing works, create a simple file where you try using the same tools in FuzzyLite to open the file and debug it to see why the file cannot be opened.

I tried saving a simple ftest.cpp file and doing this inside Developer Powershell for VS :

cl.exe ftest.cpp fuzzylite-static.lib C:\fuzzylite-6.0-Win64\fuzzylite-6.0\fuzzylite\release\bin\fuzzylite.lib /EHsc /MD

but got:

ftest.cpp
ftest.cpp(2): fatal error C1083: Cannot open include file: 'fl/Headers.h': No such file or directory

@jcrada
Copy link
Member

jcrada commented Mar 24, 2023

Thanks for your kind words.

Did you compile the library? Maybe the issue is in the compiled libraries and your version of C++ libraries. If you have not compiled the libraries, please do so following instructions from GitHub. I built those libraries about 6 years ago.

@gabrielgcma
Copy link
Author

gabrielgcma commented Mar 27, 2023

Prior to your reply I had not compiled the library, so I followed the instructions and ran build.bat for both release and debug builds, but I'm still getting the same error when running that simple file:

 cl.exe ftest.cpp fuzzylite-static.lib C:\fuzzylite-6.0-Win64\fuzzylite-6.0\fuzzylite\release\bin\fuzzylite.lib /EHsc /MD
ftest.cpp
ftest.cpp(2): fatal error C1083: Cannot open include file: 'fl/Headers.h': No such file or directory

I get the sense that I'm doing something very wrong so I'm grateful for the patience anyways.

EDIT: sorry for the slowness, I didn't realize the source code wasn't in the same folder as the fl folder (which is the fuzzylite folder). I managed to make it work and it is compiling just fine using:

 cl.exe ftest.cpp C:\fuzzylite-6.0-Win64\fuzzylite-6.0\fuzzylite\release\bin\fuzzylite-static.lib /EHsc /MD

Now I just need to figure out how to make it work in Visual Studio. Thanks.

@jcrada
Copy link
Member

jcrada commented Mar 27, 2023

Nice. Well done.

You can find more information about setting up a project using CMake here: https://github.com/fuzzylite/fuzzylite/tree/release/examples/application

You could probably copy the application CMake file, adapt it to your needs, and then export the cmake project to Visual Studio.

Although perhaps simpler would be to manually configure:

  1. the location of the library (.lib or .dll)
  2. the location of the fuzzylite headers

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