alandefreitas / matplotplusplus

Matplot++: A C++ Graphics Library for Data Visualization 📊🗾
https://alandefreitas.github.io/matplotplusplus/
MIT License
4.32k stars 333 forks source link

std::system_error on Windows #427

Closed bitsbakery closed 1 month ago

bitsbakery commented 1 month ago

Bug category

Describe the bug Cannot launch any example, I get the following std::system_error:

struct pipe_deleter {
        int operator()(FILE* pipe) const {
            if (int status = PCLOSE(pipe); status != -1)
                return status;
            //throw std::system_error{errno, std::system_category(), "pclose"};
        }
    };

After commenting out "throw std::system_error", the examples start working.

Steps to Reproduce

  1. Build matplotplusplus in Development Mode
  2. Install gnuplot v6
  3. Try to launch any example

Platform

alandefreitas commented 1 month ago

I don't know. Maybe a different status code is not that bad.

@mikucionisaau ?

mikucionisaau commented 1 month ago

Oh well, non-POSIX OS does not behave like POSIX says :-(

I see that there is a nice popen and pclose wrapper in popen.cpp for _WIN32, but it is not setting the errno like POSIX pclose does, so the error gets lost (I get system_error with "Success" with mingw64 and wine setup on Linux).

I do not see any other signs of cross-compilation attempts in this repo, so I was wondering how do you compile? What OS/toolchain/compiler do you use?

bitsbakery commented 1 month ago

What OS/toolchain/compiler do you use?

No cross-compilation, I compile natively on Windows 10, using

Microsoft (R) C/C++ Optimizing Compiler Version 19.39.33523 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

Adjusted CMAKE_CXX_COMPILER in cmake presets to "cl" (this is MSVC).

mikucionisaau commented 1 month ago

Good news: I found _popen in Windows, which works, so popen.cpp is overly complicated and can be retired, unless there is some old Windows that needs it. I'll make a PR for this.

mikucionisaau commented 1 month ago

Bad news: popen.cpp was created to hide console window to fix https://github.com/alandefreitas/matplotplusplus/issues/376

alandefreitas commented 1 month ago

popen is always causing minor issues over the years 🤣

mikucionisaau commented 1 month ago

The fix is almost ready (needs testing and review): https://github.com/alandefreitas/matplotplusplus/pull/428

I would appreciate if @bitsbakery gave it a spin.

bitsbakery commented 1 month ago

It works. Also terminal window no longer appears, as it did with "throw std::system_error" commented out.