MinGW GCC 编译Glog0.6.0

 GCC版本: gcc version 5.3.0 (i686-posix-dwarf-rev0, Built by MinGW-W64 project)

glog 0.6.0地址: https://github.com/google/glog/tree/v0.6.0

 编译很顺利,直接

 然后进入C:/tmp/glog-0.6.0/Build2目录,执行命令:

 编译完成后,在目录下存在libglog.dll和libglog.dll.a:

 已编译好的glog0.6.0 32位:

https://wwp.lanzoue.com/imurS23obnxc
密码:6v53

 

最新是0.7.1,发现编译0.7.1报错::error: enclosing class of constexpr non-static member function 'google::glog_internal_namespace_::FileDescriptor::operator bool() const' is not a literal type

完整报错:

C:\tmp\glog-0.7.1\Build>mingw32-make
[  3%] Building CXX object CMakeFiles/glog_internal.dir/src/demangle.cc.obj
In file included from C:\tmp\glog-0.7.1\glog-0.7.1\src\demangle.cc:43:0:
C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h:210:22: error: enclosing class of constexpr non-static member function 'google::glog_internal_namespace_::FileDescriptor::operator bool() const' is not a literal type
   constexpr explicit operator bool() const noexcept {
                      ^
C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h:190:22: note: 'google::glog_internal_namespace_::FileDescriptor' is not literal because:
 class GLOG_NO_EXPORT FileDescriptor final {
                      ^
C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h:190:22: note:   'google::glog_internal_namespace_::FileDescriptor' has a non-trivial destructor
C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h:214:17: error: enclosing class of constexpr non-static member function 'int google::glog_internal_namespace_::FileDescriptor::get() const' is not a literal type
   constexpr int get() const noexcept { return fd_; }
                 ^
C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h: In function 'constexpr bool google::glog_internal_namespace_::operator==(const google::glog_internal_namespace_::FileDescriptor&, int)':
C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h:243:17: error: call to non-constexpr function 'int google::glog_internal_namespace_::FileDescriptor::get() const'
   return lhs.get() == rhs;
                 ^
C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h: In function 'constexpr bool google::glog_internal_namespace_::operator==(const google::glog_internal_namespace_::FileDescriptor&, std::nullptr_t)':
C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h:259:11: error: call to non-constexpr function 'google::glog_internal_namespace_::FileDescriptor::operator bool() const'
   return !lhs;
           ^
C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h: In function 'constexpr bool google::glog_internal_namespace_::operator==(std::nullptr_t, const google::glog_internal_namespace_::FileDescriptor&)':
C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h:263:11: error: call to non-constexpr function 'google::glog_internal_namespace_::FileDescriptor::operator bool() const'
   return !rhs;
           ^
C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h: In function 'constexpr bool google::glog_internal_namespace_::operator!=(const google::glog_internal_namespace_::FileDescriptor&, std::nullptr_t)':
C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h:267:31: error: call to non-constexpr function 'google::glog_internal_namespace_::FileDescriptor::operator bool() const'
   return static_cast<bool>(lhs);
                               ^
C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h: In function 'constexpr bool google::glog_internal_namespace_::operator!=(std::nullptr_t, const google::glog_internal_namespace_::FileDescriptor&)':
C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h:271:31: error: call to non-constexpr function 'google::glog_internal_namespace_::FileDescriptor::operator bool() const'
   return static_cast<bool>(rhs);
                               ^
C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h: At global scope:
C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h:279:13: error: specialization of 'template<class _Tp> struct std::default_delete' in different namespace [-fpermissive]
 struct std::default_delete<std::FILE> {
             ^
In file included from C:/Develop/i686-5.3.0-release-posix-dwarf-rt_v4-rev0/mingw32/i686-w64-mingw32/include/c++/memory:81:0,
                 from C:\tmp\glog-0.7.1\glog-0.7.1\src\utilities.h:40,
                 from C:\tmp\glog-0.7.1\glog-0.7.1\src\demangle.cc:43:
C:/Develop/i686-5.3.0-release-posix-dwarf-rt_v4-rev0/mingw32/i686-w64-mingw32/include/c++/bits/unique_ptr.h:54:12: error:   from definition of 'template<class _Tp> struct std::default_delete' [-fpermissive]
     struct default_delete
            ^
mingw32-make[2]: *** [CMakeFiles\glog_internal.dir\build.make:76: CMakeFiles/glog_internal.dir/src/demangle.cc.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:860: CMakeFiles/glog_internal.dir/all] Error 2
mingw32-make: *** [Makefile:165: all] Error 2

 使用GCC 7.4以上进行编译,亲测使用8.1.0编译通过.

参考: https://stackoverflow.com/questions/36489369/constexpr-non-static-member-function-with-non-constexpr-constructor-gcc-clang-d# 

 

注意CMake执行时第一句是否是GCC 7.4以上,我就犯了这个错误,CMake默认读取的是系统环境变量GCC,系统环境变量配置的GCC使用的是GCC 5.3.0,如果此处 显示GCC 5.3.0, 即使生成Makefile后在执行mingw32-make编译使用的GCC 8.1.0的mingw32-make,也是会报错!!。

 所以解决这个问题,首先需要下载>GCC 7.4的版本,并且在CMake中正确配置GCC 新版本,并且在执行mingw32-make时要保证最终的mingw32-make是新版本中的MinGW(>7.4 GCC版本中),而不是旧版本MinGW

可以通过在CMake界面中点击Environment修改PATH环境变量,并把新GCC版本bin路径添加到最前:

 并且在生成Makefile,执行mingw32-make时,也可以通过set 命令临时修改PATH环境变量,让执行mingw32-make时指向最新的GCC编译器:

 C:\Develop\i686-8.1.0-release-posix-dwarf-rt_v6-rev0\mingw32\bin; 就是我下载的新编译器路径。注意后边要有;分号!

 最后在执行mingew32-make前,可以通过GCC -V验证当前版本是否路径配置成功:

 

然后大胆执行mingw32-make,祝一切顺利.

 

已编译好的glog0.7.1 32位:

https://wwp.lanzoue.com/imurS23obnxc
密码:6v53

 

时间原因随笔比较乱,但愿对你有帮助.

 

posted @ 2024-07-06 15:55  耿明岩  阅读(101)  评论(0编辑  收藏  举报
希望能帮助到你,顺利解决问题! ...G(^_−)☆