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

Not compiling on Win10 with MSYS #1581

Closed
s7726 opened this issue Jun 4, 2020 · 7 comments
Closed

Not compiling on Win10 with MSYS #1581

s7726 opened this issue Jun 4, 2020 · 7 comments

Comments

@s7726
Copy link

s7726 commented Jun 4, 2020

Looks like this needs a similar fix as #1347

 g++ -g -std=c++11 -pedantic -Wall -Wextra -Werror -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Weffc++ -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wreorder -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef -Wuninitialized -Wno-unused -Wno-unknown-warning-option -Wno-effc++ -isystem include -I src -MMD -c -o build/temp.o test/temp.cpp
In file included from include/spdlog/details/os.h:110,
                 from include/spdlog/details/log_msg-inl.h:10,
                 from include/spdlog/details/log_msg.h:35,
                 from include/spdlog/logger.h:18,
                 from include/spdlog/details/registry-inl.h:12,
                 from include/spdlog/details/registry.h:111,
                 from include/spdlog/spdlog.h:13,
                 from test/temp.cpp:7:
include/spdlog/details/os-inl.h: In function ‘size_t spdlog::details::os::filesize(FILE*)’:
include/spdlog/details/os-inl.h:231:16: error: ‘::fileno’ has not been declared
  231 |     int fd = ::fileno(f);
      |                ^~~~~~
include/spdlog/details/os-inl.h: In function ‘bool spdlog::details::os::in_terminal(FILE*)’:
include/spdlog/details/os-inl.h:423:21: error: ‘fileno’ was not declared in this scope; did you mean ‘file’?
  423 |     return ::isatty(fileno(file)) != 0;
      |                     ^~~~~~
      |                     file
At global scope:
cc1plus: error: unrecognized command line option ‘-Wno-unknown-warning-option’ [-Werror]
cc1plus: all warnings being treated as errors

Preprocessor has a few defines that could be helpful in deterimining the right path.

#define __CYGWIN__ 1
#define __MSYS__ 1
#define __x86_64 1
#define __x86_64__ 1

It also does not define any of the win32/win64 defnes

gcc version
#define __VERSION__ "9.3.0"

It does compile if I use -std=gnu++11, but there are other reasons I would prefer not to in the project.

@tt4g
Copy link
Contributor

tt4g commented Jun 5, 2020

Unfortunately, MSYS (MinGW) doesn't provide a declaration for fileno() unless it is -std=gnu***.

If you can't specify --std=gnu*** in your project, try building a static library spdlog and linking it to your project as a workaround, it should work with ABI compatibility.

@gabime
Copy link
Owner

gabime commented Jun 5, 2020

@s7726 I dont have readily available msys env right now so could you try if the following helps (replace line #43 in cmake)

if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES “MSYS”) ?

or maybe even better

if(CYGWIN OR MINGW OR MSYS) .. ?

@s7726
Copy link
Author

s7726 commented Jun 5, 2020

Any idea what that translates to directly into the source? I don't have things in a position to setup cmake.

@gabime
Copy link
Owner

gabime commented Jun 5, 2020

No. The whole point is the cmake build, right?

@tt4g
Copy link
Contributor

tt4g commented Jun 5, 2020

The spdlog/details/os-inl.h is included only at build time.
If you build spdlog as a static library, you can include it in your project as When linking the spdlog, you can use #include spdlog/details/os- inl.h will no longer be done.

I found another way, #define _fileno(__F) ((__F)->_file) and #define fileno(__F) ((__F)->_file) before #include spdlog/details/os- inl.h, It may work.
See MinGw mailing list: https://osdn.net/projects/mingw/lists/archive/users/2020-January/000430.html
and StackOverFlow: c++ - no `fileno()` function in nuwen.net MinGW Distro? - Stack Overflow

@s7726
Copy link
Author

s7726 commented Jun 26, 2020

Ok, sorry for the delay... The following leads to compiling and running code. I am not sure that what I'm doing exercises this functionality though. From the different checks it looks like there are a couple spots that

Prior to including spdlog

#if defined __MSYS__ && __STRICT_ANSI__
int _fileno( FILE * );
#define fileno(__F) _fileno(__F)
#define _fileno(__F) _fileno(reinterpret_cast<FILE*>((__F)->_file))
#endif

kind of pulled some from here:
https://osdn.net/projects/mingw/lists/archive/users/2020-January/000430.html

@gabime gabime closed this as completed in 63b5a1a Aug 30, 2020
gabime pushed a commit that referenced this issue Aug 30, 2020
@gabime
Copy link
Owner

gabime commented Aug 30, 2020

@s7726 Fixed. Please try latest commit and see if the fix works for you.

bachittle pushed a commit to bachittle/spdlog that referenced this issue Dec 22, 2022
NU-LL added a commit to NU-LL/spdlog that referenced this issue Feb 24, 2024
Under Windows 10, compiling with MINGW64 will report an error similar to gabime#1581
gabime pushed a commit that referenced this issue Feb 25, 2024
Under Windows 10, compiling with MINGW64 will report an error similar to #1581
gabime pushed a commit that referenced this issue Mar 16, 2024
Under Windows 10, compiling with MINGW64 will report an error similar to #1581
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

3 participants