martinrotter/textosaurus

Build failure on windows

cdwijs opened this issue · 4 comments

Brief description of the issue.

I tried to compile the program on windows7, then i got the following error:
'clamp' is not a member of 'std'

How to reproduce the bug?

  1. Have Windows 7, Qt 5.10.1 and mingw53_32
  2. Clone the repository
  3. Double-click the .pro file
  4. Click Debug

What is the expected result?

A lot of compiling, and then a working program

What actually happened?

I got the following error, and compiling stops:
g++ -c -fno-keep-inline-dllexport -std=c++17 -g -Wall -std=gnu++1z -Wall -W -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DAPP_VERSION=""0.9.1"" -DAPP_NAME=""Textosaurus"" -DAPP_LOW_NAME=""textosaurus"" -DAPP_LONG_NAME=""Textosaurus 0.9.1"" -DAPP_AUTHOR=""Martin Rotter"" -DAPP_EMAIL=""rotter.martinos@gmail.com"" -DAPP_URL=""https://github.com/martinrotter/textosaurus\"" -DAPP_URL_ISSUES=""https://github.com/martinrotter/textosaurus/issues\"" -DAPP_URL_ISSUES_NEW=""https://github.com/martinrotter/textosaurus/issues/new\"" -DAPP_URL_WIKI=""https://github.com/martinrotter/textosaurus/wiki\"" -DAPP_USERAGENT=""Textosaurus/0.9.1 (io.github.martinrotter.textosaurus)"" -DAPP_DONATE_URL=""https://martinrotter.github.io/donate/\"" -DAPP_SYSTEM_NAME=""Windows"" -DAPP_SYSTEM_VERSION=""x86"" -DAPP_REVISION=""43d5130"" -DQT_USE_QSTRINGBUILDER -DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS -DDEBUG=1 -DSCINTILLA_QT=1 -DSCI_LEXER=1 -D_CRT_SECURE_NO_DEPRECATE=1 -DEXPORT_IMPORT_API= -DQT_QML_DEBUG -DQT_PRINTSUPPORT_LIB -DQT_SVG_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\textosaurus -I. -I..\textosaurus\src\3rd-party\scintilla\qt\ScintillaEditBase -I..\textosaurus\src\3rd-party\scintilla\include -I..\textosaurus\src\3rd-party\scintilla\src -I..\textosaurus\src\3rd-party\scintilla\lexlib -I..\textosaurus -I..\textosaurus\src -I..\textosaurus\src\common\gui -I..\textosaurus\src\saurus\gui -I..\textosaurus\src\saurus\gui\dialogs -I..\textosaurus\src\saurus\gui\sidebars -I..\textosaurus\src\saurus\gui\settings -I..\textosaurus\src\common\dynamic-shortcuts -I..\textosaurus\src\saurus\external-tools -I..\textosaurus\src\saurus\plugin-system -IC:\Qt\5.10.1\mingw53_32\include -IC:\Qt\5.10.1\mingw53_32\include\QtPrintSupport -IC:\Qt\5.10.1\mingw53_32\include\QtSvg -IC:\Qt\5.10.1\mingw53_32\include\QtWidgets -IC:\Qt\5.10.1\mingw53_32\include\QtGui -IC:\Qt\5.10.1\mingw53_32\include\QtANGLE -IC:\Qt\5.10.1\mingw53_32\include\QtNetwork -IC:\Qt\5.10.1\mingw53_32\include\QtCore -Imoc -Iui -IC:\Qt\5.10.1\mingw53_32\mkspecs\win32-g++ -o ViewStyle.o ..\textosaurus\src\3rd-party\scintilla\src\ViewStyle.cxx
..\textosaurus\src\3rd-party\scintilla\src\ViewStyle.cxx: In member function 'int Scintilla::ViewStyle::GetFrameWidth() const':
..\textosaurus\src\3rd-party\scintilla\src\ViewStyle.cxx:461:26: error: 'clamp' is not a member of 'std'
return static_cast(std::clamp(caretLineFrame, 1, lineHeight / 3));
^
Makefile:24369: recipe for target 'ViewStyle.o' failed
mingw32-make: *** [ViewStyle.o] Error 1
16:28:11: The process "C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project textosaurus (kit: Desktop Qt 5.10.1 MinGW 32bit)
When executing step "Make"

Other information (logs, see Wiki)

below patch fixes the compile error:
src/Document.cxx | 8 ++++++++
src/ViewStyle.h | 11 +++++++++++
2 files changed, 19 insertions(+)

diff --git a/src/Document.cxx b/src/Document.cxx
index a6f408f3..54576f02 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -19,6 +19,14 @@
#include
#include

+namespace std {

  • template
  • constexpr const T& clamp(const T& v, const T& lo, const T& hi)
  • {
  •    return std::min(std::max(v, lo), hi);
    
  • }
    +} // std

#define NOEXCEPT

#ifndef NO_CXX11_REGEX
diff --git a/src/ViewStyle.h b/src/ViewStyle.h
index 4348e3ea..b5d9dcd2 100644
--- a/src/ViewStyle.h
+++ b/src/ViewStyle.h
@@ -8,6 +8,17 @@
#ifndef VIEWSTYLE_H
#define VIEWSTYLE_H

+//http://en.cppreference.com/w/cpp/algorithm/clamp
+#include
+
+namespace std {

  •    template<class T>
    
  •    constexpr const T& clamp(const T& v, const T& lo, const T& hi)
    
  •    {
    
  •            return std::min(std::max(v, lo), hi);
    
  •    }
    

+} // std
+
namespace Scintilla {

/**

I cannot use the patch. Bundled component Scintilla requires compiler with C++ 17 support. MinGW 32 does not probably support std::clamp. To compile x86 version of Textosaurus, either use Qt MSVC2015 x86 from official installer or MinGW-W64 (do not get confused by name, they offer up-to-date x86 gcc compiler too).

https://sourceforge.net/projects/mingw-w64/

You will probably have to compile Qt yourself too in case of mingw-w64

Hi Martin,
The program compiles fine with the above patch. Therefore, I don't see the need to update my compiler, and hand-compile Qt.
Cheers,
Cedric

Yes, and I am completely fine with your solution. The thing is that I cannot merge your changes into textosarus repository because the changes are done in Scintilla library (https://github.com/martinrotter/scintilla/tree/ce4d5d3122668910e8c6a0ccadd84008b45a2d43) which is used by Textosaurus. The change will not probably be accepted by Scintilla devs upstream and I do not want to use tweaked Scintilla code.

So, for your usage, it will work, I just cannot merge it. Maybe you can open bug report in Scintilla bug tracker and request the change there. If they accept it, then it will over time get into Textosaurus as well.