3

I am running Cygwin on windows 8, attempting to compile the source code for a game I would like to mod. Unfortunately I am running into some errors while building involving the fileno function. After doing some googling It seems like the problem might have to do with c++11 support (I'm not really sure what this means). Most of the solutions people have found involve adding some option like -std=c++0x or -std=c++11 when compiling, but my attempts to add the options into the makefile have been unsuccessful, and I don't know if that's whats causing the problem anyways. I'll include the code snippet that's throwing the error and a link to the makefile as it is quite large. Any advice you could give me would be great.

code that throws error:

    time_t file_modtime(FILE *f)
    {
        struct stat filestat;
        if (fstat(fileno(f), &filestat))
            return 0;

        return filestat.st_mtime;
    }

Link to Makefile

it is being hosted on github

EDIT: After getting some advice I poked around the makefile and found five instances where the -std option was used, playing around with them hasn't changed anything. Is the problem with my Cygwin configuration? I installed the packages I was told I would need in the installation guide for the game I am building.

XNoize
  • 33
  • 1
  • 1
  • 4
  • Have you `#include `? – trojanfoe Apr 17 '15 at 06:47
  • yes is included – XNoize Apr 17 '15 at 06:53
  • 1
    possible duplicate of [GoogleTest 1.6 with Cygwin 1.7 compile error: 'fileno' was not declared in this scope](http://stackoverflow.com/questions/18784112/googletest-1-6-with-cygwin-1-7-compile-error-fileno-was-not-declared-in-this) – Caduchon Apr 17 '15 at 08:08
  • I looked at that one before posting, and tried adding the options it suggested, but was unsuccessful. I was hoping for some advice on how to either work around it or where in the makefile the option needs to go. – XNoize Apr 17 '15 at 08:25
  • Most probably it is being set in lines 1563/1565 in your makefile. Hard to say for sure without being able to fetch all requirements. – keltar Apr 17 '15 at 09:07
  • 1
    Have you tried setting the standards to -std=gnu++0x ? – marco Apr 17 '15 at 09:15

2 Answers2

12

Changing the -std=c*** in your makefile to -std=gnu++0x should fix your problem.

If you don't know what c++11 is you're most likely not using it anyway.

Also if you need c++11 support you can also do: -std=gnu++11 instead of -std=gnu++0x

deW1
  • 5,562
  • 10
  • 38
  • 54
1

For windows...

fileno() is deprecated: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-fileno?view=vs-2017

use _fileno() instead: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fileno?view=vs-2017

claytonjwong
  • 814
  • 1
  • 7
  • 13
  • 2
    No, `fileno()` is **not** "deprecated". It is [a standard POSIX function - and isn't going away any time soon](http://pubs.opengroup.org/onlinepubs/9699919799/functions/fileno.html). Microsoft "deprecates" all kinds of standard functions, [even including many like `fopen()` that are required to be available by the C standard itself](https://stackoverflow.com/questions/14386/fopen-deprecated-warning). The cynic in me says Microsoft created all these fake "deprecations" to fool people into writing non-portable code. – Andrew Henle Jan 19 '19 at 00:18
  • The first URL from Microsoft states: "This POSIX function is deprecated. Use the ISO C++ conformant _fileno instead.", and that is why I stated "For windows..." at the beginning of this answer, because this information is provided in the windows context and should not be taken out of context. I suppose we can edit or delete this answer if its confusing and unhelpful? – claytonjwong Jan 19 '19 at 01:18
  • 1
    In the case of `fileno()`, Microsoft can't claim POSIX compliance and then state `fileno()` is "deprecated" as `fileno()` hasn't been deprecated by POSIX. Furthermore, Microsoft's "deprecation" of other functions violates the very ISO C++ they're trying to claim supports "deprecation" of `fileno()`. `fopen()`, for example, is listed as a required C++ function under table 134 of the [C++ standard](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf). – Andrew Henle Jan 19 '19 at 02:35
  • 2
    (cont) What's even worse about Microsoft's "deprecations" is that they offer alternative functions that are ["incomplete and conforms neither to C11 nor to the original TR 24731-1."](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm) Microsoft uses those "deprecations" to push functions that "... cannot be considered conforming or portable." Now you have more of the full context of Microsoft's "deprecations". – Andrew Henle Jan 19 '19 at 02:39