使用 GCC MinGW 时我的代码不再编译

my code no longer compiles when using GCC MinGW

我使用 Visual Studio 2015 编写了一个小程序。它编译并 运行s 正确。我现在正尝试使用 GCC MinGW 编译器 运行 相同的程序,以便我可以将它移植到 Android。 但是编译器一直在抱怨。以下是它不断抛出的问题:

     inline auto currentTime()
     {
         return std::chrono::high_resolution_clock::now();
     }

编译器抱怨:

error: auto return without trailing return type; deduced return types are a C++14 extension.

编译器也抱怨这一行

      return std::chrono::high_resolution_clock::now();

error: no viable conversion from returned value of type time_point
(aka time_point < std::__ndk1::chrono::steady_clock, duration < long, long ratio < 1LL, 1000000000LL > > >) to function return type int

有什么方法可以解决这些问题而不必重写我的那部分代码?

你应该找出::now();的类型 然后将 auto 替换为您找到的类型,

inline int currentTime()
{
    return std::chrono::high_resolution_clock::now();
}

喜欢这样^^

在我的 Android.mk APP_STL := c++_shared.这意味着 NDK 设置为使用 LLVM C++ 运行时共享库​​。此运行时是 LLVM libc++ 的 Anroid 端口。默认情况下,此运行时使用 -std=c++11 进行编译。我设置了这个-> LOCAL_CPPFLAGS := -std=c++14。之后编译上面引用的代码。