Can you use a later build of MinGW64 compiler for Blitzmax NG?

Started by SC-Dan37, July 26, 2017, 23:33:13

Previous topic - Next topic

xlsior

Seems to be able to compile almost everything with 7.10, except bah.freeimage it appears:

[ 13%] Compiling:Flip.cpp
[ 14%] Compiling:JPEGTransform.cpp
[ 14%] Compiling:MultigridPoissonSolver.cpp
[ 14%] Compiling:Rescale.cpp
In file included from c:/code/blitzmaxNG710/mod/bah.mod/freeimage.mod/src/LibTIFF4/tiffio.h:258:0,
                 from c:/code/blitzmaxNG710/mod/bah.mod/freeimage.mod/src/LibTIFF4/tiffiop.h:60,
                 from c:/code/blitzmaxNG710/mod/bah.mod/freeimage.mod/src/FreeImage/PluginG3.cpp:23:
c:/code/blitzmaxNG710/MinGW32x86/i686-w64-mingw32/include/stdio.h:541:23: error: conflicting declaration of 'int _snprintf(char*, size_t, const char*, ...)' with 'C' linkage
   _CRTIMP int __cdecl _snprintf(char * __restrict__ _Dest,size_t _Count,const char * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
                       ^~~~~~~~~
In file included from c:/code/blitzmaxNG710/mod/bah.mod/freeimage.mod/src/LibTIFF4/tiffiop.h:33:0,
                 from c:/code/blitzmaxNG710/mod/bah.mod/freeimage.mod/src/FreeImage/PluginG3.cpp:23:
c:/code/blitzmaxNG710/mod/bah.mod/freeimage.mod/src/LibTIFF4/tif_config.h:84:18: note: previous declaration with 'C++' linkage
#define snprintf _snprintf
                  ^
[ 14%] Compiling:Resize.cpp
Build Error: failed to compile (1) c:/code/blitzmaxNG710/mod/bah.mod/freeimage.mod/src/FreeImage/PluginG3.cpp


I did notice the same thing about required DLLs though, program (x86) won't run without a few additional DLLs present in the folder, which is hopefully something that can be fixed...

xlsior

After some googling, I did find people saying that adding:     -static-libgcc   to the MinGW command statically links the info and remove the dependency on the DLL, but I have no idea how to tell NG to do pass that info along and do that. :-?


TomToad

I am not using 7.10, so I can't test this.

In <path-to-ng>/bin, create a file called custom.bmk.  Edit the file with the line
addwin32ccopt staticlib -static-libgcc

and save.

When I compile a simple "Hello World" program with Verbose Build, I see bmk calling gcc with this line.
C:\TDM-GCC-64/bin/gcc.exe -I"C:/BlitzMaxNG/mod" -I"C:/BlitzMaxNG/mod/brl.mod/blitz.mod" -I"C:/BlitzMaxNG/mod/brl.mod/appstub.mod" -I"C:/BlitzMaxNG/mod/brl.mod/standardio.mod"   -w -DBMX_NG -m64 -ffast-math -fno-exceptions -c -O3 -msse3 -static-libgcc  -g -o "C:/BlitzMaxNG/tmp/.bmx/untitled1.bmx.gui.debug.win32.x64.o" "C:/BlitzMaxNG/tmp/.bmx/untitled1.bmx.gui.debug.win32.x64.c"

Note that -static-libgcc has been added to the command line.  Since I am using TDM-GCC, I can't test if this will add the necessary dlls to the file.
------------------------------------------------
8 rabbits equals 1 rabbyte.

xlsior

I see it added to the command line, but it appears to have no noticable effect -- the final .exe is the exact same size as before, and still asks for the DLLs...

Henri

TDM links to libgcc and libstd statically by default. When using different MinGW build, you could try renaming corresponding dll.a files in MinGW-folder to something else in order to force the linker to link statically.

-Henri
- Got 01100011 problems, but the bit ain't 00000001

markcwm

This seems similar to Blitzmax legacy upgrading from 4.6 to 4.7+ when you needed to link to libmsvcrt and libgcc with env var "BMK_LD_OPTS = -lmsvcrt -lgcc" so you should try adding to custom.bmk "-static-libmsvcrt".

xlsior

Quote from: markcwm on July 31, 2017, 01:01:12
This seems similar to Blitzmax legacy upgrading from 4.6 to 4.7+ when you needed to link to libmsvcrt and libgcc with env var "BMK_LD_OPTS = -lmsvcrt -lgcc" so you should try adding to custom.bmk "-static-libmsvcrt".

That didn't work: "gcc.exe: error: unrecognized command line option '-static-libmsvcrt'; did you mean '-static-libasan'?"
:(

markcwm

No I meant libmsvcrt.a but it must not be there now. The freeimage error looks to be about some deprecated code, searching for __MINGW_ATTRIB_DEPRECATED_SEC_WARN leads to "crt", so a better suggestion is to try adding "-static-libcrtdll".

xlsior

Quote from: markcwm on July 31, 2017, 02:53:35
No I meant libmsvcrt.a but it must not be there now. The freeimage error looks to be about some deprecated code, searching for __MINGW_ATTRIB_DEPRECATED_SEC_WARN leads to "crt", so a better suggestion is to try adding "-static-libcrtdll".

gcc.exe: error: unrecognized command line option '-static-libcrtdll'; did you mean '-static-libstdc++'?

Looks like there's still differences... Anyway, I skipped freeimage altogether for now, but even without that mod any compiled "hello world" still wants
the following three DLL's to be present:
libgcc_s_sjlj-1.dll
libstdc++-6.dll
libwinpthread-1.dll

SC-Dan37

Did some searching and found a -static flag that needs to be set on the linker g++. Currently the verbose output shows this as the g++ command:

g++ -Wl,--stack,4194304 -s  -Wl,--subsystem,windows -mwindows -mthreads -o "C:/path/to/created/executabe.debug.mt.exe" "C:/BmxNG/tmp/ld.tmp"

It needs to be:

g++ -Wl,--stack,4194304 -s -static -Wl,--subsystem,windows -mwindows -mthreads -o "C:/path/to/created/executable.debug.mt.exe" "C:/BmxNG/tmp/ld.tmp"

This worked for me if I run g++ as above in a command prompt.

I tried adding setwin32ccopt static -static to the custom.bmk file to no effect as it puts the -static in the gcc command. Not sure how to add something to the g++ linker command?


markcwm

Compiler commands take 2 arguments, the first is <name> and the second <value>

See https://github.com/bmx-ng/bmk/blob/master/readme.txt
See all NG compiler commands https://github.com/bmx-ng/bmk/blob/master/make.bmk
See "Options for linking" https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/#toc-GCC-Command-Options

I'm not sure if you can omit the <name> argument but try this:
addwin32ldopt -static


SC-Dan37

Thanks for the information!

I tried adding addwin32ldopt -static: no change.
I tried adding addwin32ldopt static -static. Errors with the following:

C:/BmxNG/MinGW32x64/bin/../lib/gcc/x86_64-w64-mingw32/6.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find static

It looks like its trying to feed static to ld.exe... ? I'm not real familiar with C / C++ compilers and linkers.

markcwm

I'm not so familiar with C++ compilers myself. :o Try for <name> either linker or staticlib, and cross fingers.

SC-Dan37

Neither of those worked for me, but I did find in the bmk_util.bmx file where to inject it and have successfully compiled the modified bmk and used it to successfully compile and link exe files for both 64bit and 32bit. I've commented on the issue in Brucey's github site.

xlsior

Quote from: SC-Dan37 on August 02, 2017, 17:30:19
Neither of those worked for me, but I did find in the bmk_util.bmx file where to inject it and have successfully compiled the modified bmk and used it to successfully compile and link exe files for both 64bit and 32bit. I've commented on the issue in Brucey's github site.

I'm not finding your comment on github -- would you mind either posting a link, or sharing here exactly what you changed to get it to work?