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

Project builds with visual studio but not ninja and MinGW : error: 'ERROR_INVALID_HANDLE' undeclared (first use in this function) #103

Closed
BillyTheSquid21 opened this issue Jan 1, 2024 · 4 comments

Comments

@BillyTheSquid21
Copy link

After cloning the repo, I call the following commands in windows from the repo directory:

  1. mkdir build && cd build
  2. cmake .. -DCMAKE_CXX_COMPILER=gcc -G "Ninja"
  3. cmake --build . -j10

The first two steps work fine, however the build step produces this error:

[1/137] Building C object src/CMakeFiles/plibsys.dir/perror.c.obj
FAILED: src/CMakeFiles/plibsys.dir/perror.c.obj
C:\MinGW\bin\gcc.exe -DPLIBSYS_COMPILATION -DPLIBSYS_HAS_LLDIV -DPLIBSYS_HAS_SOCKADDR_STORAGE -DPLIBSYS_HAS_SOCKLEN_T -DPLIBSYS_SOCKADDR_IN6_HAS_FLOWINFO -DPLIBSYS_SOCKADDR_IN6_HAS_SCOPEID -Dplibsys_EXPORTS -ID:/Repositories/plibsys/src -ID:/Repositories/plibsys/build/src -g -MD -MT src/CMakeFiles/plibsys.dir/perror.c.obj -MF src\CMakeFiles\plibsys.dir\perror.c.obj.d -o src/CMakeFiles/plibsys.dir/perror.c.obj -c D:/Repositories/plibsys/src/perror.c
In file included from D:/Repositories/plibsys/build/src/plibsysconfig.h:29:0,
                 from D:/Repositories/plibsys/src/ptypes.h:67,
                 from D:/Repositories/plibsys/src/perror.h:62,
                 from D:/Repositories/plibsys/src/perror.c:26:
D:/Repositories/plibsys/src/perror.c: In function 'p_error_get_io_from_system':
D:/Repositories/plibsys/src/perror.c:66:7: error: 'ERROR_INVALID_HANDLE' undeclared (first use in this function)
  case WSA_INVALID_HANDLE:
       ^
D:/Repositories/plibsys/src/perror.c:66:7: note: each undeclared identifier is reported only once for each function it appears in
D:/Repositories/plibsys/src/perror.c:70:7: error: 'ERROR_INVALID_PARAMETER' undeclared (first use in this function)
  case WSA_INVALID_PARAMETER:
       ^
[10/137] Generating API documentation with Doxygen
ninja: build stopped: subcommand failed.

I haven't had a problem building in visual studio, so I'm unsure as to what is wrong here.

@saprykin
Copy link
Owner

saprykin commented Jan 1, 2024

Can you please provide full output from Step 2? You can paste it through GitHub Gist. As building on Windows with GCC/Clang, in general, is a bit tricky, the following info would be helpful:

  • Which GCC packaging are you using: MinGW or MSYS.
  • Which CMake are you invoking? In general, you should use one coming with MinGW/MSYS.
  • Don you invoke commands from the corresponding environment shell of MinGW/MSYS?

@BillyTheSquid21
Copy link
Author

Here is the output to step 2

  • I am using MinGW
  • I am using just the default CMake from the installer on their website
  • I am invoking the commands from a default windows cmd terminal

@saprykin
Copy link
Owner

saprykin commented Jan 2, 2024

Okay, based on the info I assume that you are using MinGW (32-bit), which was installed probably using mingw-get tool. Is this correct? At least with this version I was able to reproduce the problem. However, this version of MinGW is 10 years old, and, moreover, MinGW project is not in development anymore. Basically, the project is dead and outdated. The reason the compilation fails is due to the bugs in the header files supplied by MinGW. You can read a detailed problem explanation here. In short, the compiler does not properly include definitions of Windows error codes. You can potentially hack the headers, but there is no guarantee that you would not break something else.

I cannot fix this broken version of the compiler, but I can recommend you to switch to MinGW-w64 project which provides old and modern versions of GCC for Windows, both 32-bit and 64-bit builds. For example, if you still need GCC 6.3.0 (32-bit build), you can download a precompiled package here. This version works without any issues for me using the steps you have provided.

Another way to obtain a modern GCC (basically, MinGW-w64 builds) version on Windows is to use MSYS2 distribution which comes with a nice package manager. You can read about it also at the local Wiki.

@BillyTheSquid21
Copy link
Author

Thank you! Switching to MinGW-w64 fixed the issue, I hadn't realised how old that MinGW version was

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