I've been running the fltk-1.5 code thorugh some of my older compilers...
First off I did a 64-bit build with an older TDM-gcc: gcc version 5.1.0 (tdm64-1)That went pretty well and the code seems to be working fine.
Then I tried a 32-bit build, using an older Msys/mingw32 build: gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)
That did *not* go so well:
[ 34%] Building CXX object src/CMakeFiles/fltk.dir/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx.obj
In file included from d:/Support/fltk-1.5/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx:19:0:
d:/Support/fltk-1.5/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H: In member function 'virtual char* Fl_WinAPI_System_Driver::strdup (const char*)':
d:/Support/fltk-1.5/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H:116:52: error: '::_strdup' has not been declared
char* strdup(const char *s) FL_OVERRIDE { return ::_strdup(s); }
^~
[... more errors elided ...]
d:/Support/fltk-1.5/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx: In member function 'virtual const char* Fl_WinAPI_System_Driver ::home_directory_name()':
d:/Support/fltk-1.5/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx:1007:14: error: '::strdup' has not been declared
home = ::strdup(h);
^~
And so forth...
$ gcc --version gcc.exe (MinGW.org GCC Build-2) 9.2.0 $ mingw-get ... package list ... shows mingw32-w32api-dev 5.4.2 The MinGW API for 32-Bit MS-Windows $ grep -1 '__W32API_.*VERSION' /mingw/include/w32api.h * * __W32API_VERSION = 1,000,000 * major + 1,000 * minor + patch * -- */ #define __W32API_VERSION 5004002L #define __W32API_MAJOR_VERSION 5 #define __W32API_MINOR_VERSION 4 #define __W32API_PATCHLEVEL 2
As an aside, I looked at the fltk-config that is made (since I use it a lot) and I note that, even though I had the build set to RELEASE, the optim flags are not set (I expected something like -O3 -DNDEBUG for example) and I'm not all that sure the lib was actually built with the release settings either...
Then I tried a 32-bit build, using an older Msys/mingw32 build: gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)
That did *not* go so well:
[ 34%] Building CXX object src/CMakeFiles/fltk.dir/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx.obj
In file included from d:/Support/fltk-1.5/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx:19:0:
d:/Support/fltk-1.5/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H: In member function 'virtual char* Fl_WinAPI_System_Driver::strdup (const char*)':
d:/Support/fltk-1.5/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H:116:52: error: '::_strdup' has not been declared
char* strdup(const char *s) FL_OVERRIDE { return ::_strdup(s); }
^~
I see the same here.
$ gcc --version gcc.exe (MinGW.org GCC Build-2) 9.2.0
#define __W32API_VERSION 5004002L #define __W32API_MAJOR_VERSION 5 #define __W32API_MINOR_VERSION 4 #define __W32API_PATCHLEVEL 2
The only obvious change I'm aware of in the new master branch (1.5) is that CMake automatically adds '-std=c++11'. I'm not sure what the compiler and/or the MinGW headers do with this setting...
I have no idea whether setting '-std=c++11' might be asserting __STRICT_ANSI__ but that may be so?
And apparently if we go for "-std=gnu++11" instead, it will work, because that sets c++11 syntax but allows the gnu extensions.
I have not tried this!
On Tuesday, 11 March 2025 at 15:40:12 UTC imacarthur wrote:
And apparently if we go for "-std=gnu++11" instead, it will work, because that sets c++11 syntax but allows the gnu extensions.
I've tried it now.Didn't work...
BUT: setting -U__STRICT_ANSI__ on the CFLAGS and CXXFLAGS does appear to work.
So, in may last build, I added "-std=gnu++11" only to the CXXFLGS (which did not work) then I ALSO added "-U__STRICT_ANSI__" to the CXXFLAGS and to the CFLAGS and the build seems to have worked.
Not pretty, but at least I have a working build now!
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
if(NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 11) endif() if(NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED) set(CMAKE_CXX_STANDARD_REQUIRED TRUE) endif() if(NOT DEFINED CMAKE_CXX_EXTENSIONS) set(CMAKE_CXX_EXTENSIONS OFF) endif()The intention was (and still is):
cd /path/to/fltk-root cmake . -B temp -G "Unix Makefiles" \ -D CMAKE_BUILD_TYPE=Release \ -D CMAKE_CXX_EXTENSIONS=ON \ # THIS is needed ! -D CMAKE_EXE_LINKER_FLAGS_INIT='-static-libgcc -static-libstdc++' cd temp make -j4 # modify this as you like/need```
Can you please test whether this works for you as well?
```
cd /path/to/fltk-root cmake . -B temp -G "Unix Makefiles" \ -D CMAKE_BUILD_TYPE=Release \ -D CMAKE_CXX_EXTENSIONS=ON \ # THIS is needed ! -D CMAKE_EXE_LINKER_FLAGS_INIT='-static-libgcc -static-libstdc++' cd temp make -j4 # modify this as you like/need ```
So, what did we learn? Using MinGW we may need to use GNU extensions but that's not the case when using MSYS2/MinGW-w64. This needs further investigation...
BTW: optimization options are included for this "Release" build:
[100%] Building CXX object test/CMakeFiles/hello.dir/hello.cxx.obj
cd C:/git/fltk/master/build/temp/test && C:/MinGW/bin/c++.exe -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -Dhello_EXPORTS @CMakeFiles/hello.dir/includes_CXX.rsp -O3 -DNDEBUG -std=gnu++11 -MD -MT test/CMakeFiles/hello.dir/hello.cxx.obj -MF CMakeFiles/hello.dir/hello.cxx.obj.d -o CMakeFiles/hello.dir/hello.cxx.obj -c C:/git/fltk/master/test/hello.cxx
On Tuesday, 11 March 2025 at 19:28:39 UTC Albrecht-S wrote:
Can you please test whether this works for you as well?
```
cd /path/to/fltk-root cmake . -B temp -G "Unix Makefiles" \ -D CMAKE_BUILD_TYPE=Release \ -D CMAKE_CXX_EXTENSIONS=ON \ # THIS is needed ! -D CMAKE_EXE_LINKER_FLAGS_INIT='-static-libgcc -static-libstdc++' cd temp make -j4 # modify this as you like/need ```
OK, so I tested with:
cmake -G "MSYS Makefiles" -D CMAKE_BUILD_TYPE=Release -D CMAKE_CXX_EXTENSIONS=ON -D CMAKE_EXE_LINKER_FLAGS_INIT='-static-libgcc -static-libstdc++' ..
And that created a build that works OK.The CMAKE_CXX_EXTENSIONS=ON must be working, as I see in the compiler command I get (amongst others!) -O3 -DNDEBUG -std=gnu++11Whereas before I was getting -std=c++11
I note that neither CMAKE_CXX_EXTENSIONS nor CMAKE_EXE_LINKER_FLAGS_INIT seem to be settable from the cmake-gui, which is a nuisance since I use that quite a lot... Oh well.
So, what did we learn? Using MinGW we may need to use GNU extensions but that's not the case when using MSYS2/MinGW-w64. This needs further investigation...
As far as I can tell, this is because the mingw32 folks and the mingw64 folks use different win32api header files. The mingw32 ones seem to be making some effort to be std compliant, the mingw64 versions perhaps less so.
BTW: optimization options are included for this "Release" build:
[100%] Building CXX object test/CMakeFiles/hello.dir/hello.cxx.obj
cd C:/git/fltk/master/build/temp/test && C:/MinGW/bin/c++.exe -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -Dhello_EXPORTS @CMakeFiles/hello.dir/includes_CXX.rsp -O3 -DNDEBUG -std=gnu++11 -MD -MT test/CMakeFiles/hello.dir/hello.cxx.obj -MF CMakeFiles/hello.dir/hello.cxx.obj.d -o CMakeFiles/hello.dir/hello.cxx.obj -c C:/git/fltk/master/test/hello.cxx
Yes, OK I see that too.
What I really meant was that fltk-config is maybe awry?e.g.:$ fltk-config --help:[--optim] return compiler optimization used to compile FLTK
:
Then if I do fltk-config --optim it returns empty...
But that is perhaps because I was setting the build type to release in the cmake-gui.Turns out that if I set the mode to release from the command line, I get:
$ fltk-config --optim
-O3 -Wall -Wunused -Wno-format-y2k -fno-exceptions -fno-strict-aliasing -ffunction-sections -fdata-sections
Which IS what I wanted!
FLTK_OPTION_OPTIM - default EMPTY Extra optimization flags for the C and C++ compilers, for instance "-Wall -Wno-deprecated-declarations". Example: cmake -D FLTK_BUILD_EXAMPLES=on -D FLTK_OPTION_OPTIM="-Wall -Wextra -pedantic" ..```
# *FIXME* add_definitions() add_definitions(${FLTK_OPTION_OPTIM})```
(2) CMAKE_EXE_LINKER_FLAGS_INIT: the suffix '_INIT' is a CMake convention that this particular parameter (cache variable) without '_CACHE' will be set only in the very first run of CMake, before CMake applies compiler or platform related additional settings.
On 3/12/25 18:02 imacarthur wrote:
... I tested with:
cmake -G "MSYS Makefiles" -D CMAKE_BUILD_TYPE=Release -D CMAKE_CXX_EXTENSIONS=ON -D CMAKE_EXE_LINKER_FLAGS_INIT='-static-libgcc -static-libstdc++' ..
...
I note that neither CMAKE_CXX_EXTENSIONS nor CMAKE_EXE_LINKER_FLAGS_INIT seem to be settable from the cmake-gui, which is a nuisance since I use that quite a lot... Oh well.
(1) CMAKE_CXX_EXTENSIONS: I did not yet find out how this is set/implemented within CMake. I don't see it as a CMake cache variable and wonder how this can be changed. This is true for all CMAKE_CXX_STANDARD related settings as well, it's not obvious how they can be changed after the initial configure pass. In this point I agree with your statement above.
-- Use std:: Yes - obsolete: always enabled since FLTK 1.5.0 -- CMAKE_CXX_STANDARD 11 -- CMAKE_CXX_STANDARD_REQUIRED Yes -- CMAKE_CXX_EXTENSIONS NoI decided to use the raw CMake variable names so users can easily find them in the cache and change them.
commit c18c39071a4dc0ace4fc5e23c61f3aa7ddd8c679 Author: Albrecht Schlosser Date: Thu Mar 13 17:58:26 2025 +0100 CMake: improve setting C++ standard and configuration summary CMake/fl_add_library.cmake: set target_compile_features(.. cxx_std_NN) which is inherited by consumers of the library. This prevents CMake user projects from failing if they would otherwise compile with an older C++ standard. ...```
I investigated how to set CMAKE_CXX_EXTENSIONS, and the result is that it seems to be handled internally by CMake as a non-cache variable by default. But this doesn't mean that you can't set and change it by using cmake-gui. You can always define your own variable and set its value in the GUI, and it will be used throughout the configure, generate, and finally the build process.
To simplify this for the "standard user" I decided to set these C++ standard related variables in the cache, but beware: it *may* be possible that this must be reverted for better interoperation if FLTK is included as a subproject.
No matter if these variables are cached or not, I also added their values to the configuration summary at the end of the CMake configure pass:
-- Use std:: Yes - obsolete: always enabled since FLTK 1.5.0 -- CMAKE_CXX_STANDARD 11 -- CMAKE_CXX_STANDARD_REQUIRED Yes -- CMAKE_CXX_EXTENSIONS No I decided to use the raw CMake variable names so users can easily find them in the cache and change them.
Note: I did not change the default value for MinGW because I can't distinguish MinGW and MSYS2/MinGW-w64 builds (unfortunately both set `MINGW` and `MSYS`). Otherwise I could have set a different default value - I left it `OFF` for better portability, as written before.
On Thursday, 13 March 2025 at 18:11:46 UTC Albrecht-S wrote:
No matter if these variables are cached or not, I also added their values to the configuration summary at the end of the CMake configure pass:
-- Use std:: Yes - obsolete: always enabled since FLTK 1.5.0 -- CMAKE_CXX_STANDARD 11 -- CMAKE_CXX_STANDARD_REQUIRED Yes -- CMAKE_CXX_EXTENSIONS No I decided to use the raw CMake variable names so users can easily find them in the cache and change them.
This seems reasonable to me.It's a pity we'll have to set CMAKE_CXX_EXTENSIONS "manually" each time, but so long as we know, all is fine!Note: I did not change the default value for MinGW because I can't distinguish MinGW and MSYS2/MinGW-w64 builds (unfortunately both set `MINGW` and `MSYS`). Otherwise I could have set a different default value - I left it `OFF` for better portability, as written before.
FWIW, at least in the Msys / Msys2 shells I can test the value of MSYSTEM and I see either of :
$ echo $MSYSTEM
MINGW32
vs:
$ echo $MSYSTEM
MINGW64
So that might be a way to tell? I'm not sure how widely supported that flag is, and presumably only works in an Msys-based shell anyway...
As regards what fltk-config ought to return for the "--optim" flags, I'd imagine that (for non-multi-config cases) it might just return whatever the current target settings are.That would at least be (somewhat) consistent with what the fltk-config --help says:[--optim] return compiler optimization used to compile FLTK
For the multi-config cases... maybe the "release" mode flags?Not sure. I _imagine_ that's what folks would want if they were just using the lib, and if they were doing some debug or etc. they'd likely be overriding the defaults anyway?