GoogleTest 1.6 with Cygwin 1.7 compile error: 'fileno' was not declared in this scope

前端 未结 2 573
北荒
北荒 2020-12-15 21:05

GoogleTest 1.6 with Cygwin 1.7: \'fileno\' was not declared in this scope

Error message when building a simple test on Factorial() function in Eclipse CDT:



        
2条回答
  •  眼角桃花
    2020-12-15 21:28

    Some functions go beyond the ANSI standard. These are disabled when you use std=c++11 (or std=c++0x).

    Among them are fdopen, fileno and strdup. There are two possibilities to use them:

    • Use the GNU dialect (std=gnu++11).
    • If you want to compile without dialect and make a local exception, you can include stdio.h with the __STRICT_ANSI__ undefined. (see: Error "'fdopen' was not declared" found with g++ 4 that compiled with g++3)

    I have tested both on Suse Linux Enterprise 11, MinGW and Cygwin.


    Addition: Another (possibly better) way to access non-ANSI symbols would be to add

    #define _POSIX_C_SOURCE 200809L
    

    before the first #include in your file. This will give you access to most of the non-standard routines.

    Some functions (e.g. realpath(...)) require

    #define _BSD_SOURCE
    

    to be inserted on top of your file.

提交回复
热议问题