Compiling Error of ExternalCodeEditor_WIN32.cxx on Windows 10 (Cygwin): '_snprintf' was not declared in this scope

288 views
Skip to first unread message

sebastian

unread,
Mar 28, 2018, 2:10:24 PM3/28/18
to fltk.general
Hello,

I am compiling the FLTK 1.3.4 on Windows 10 using the Cygwin environment.
When making fluid, errors occurred when trying to compiling 'ExternalCodeEditor_WIN32.cxx':

  '_snprintf' was not declared in this scope

What might be the problems here?
The complete error messages are attached below.

Thank you.

Compiling ExternalCodeEditor_WIN32.cxx...
ExternalCodeEditor_WIN32.cxx: In function ‘const char* get_ms_errmsg()’:
ExternalCodeEditor_WIN32.cxx:37:66: error: ‘_snprintf’ was not declared in this scope
     _snprintf(emsg, sizeof(emsg), "Error Code %ld", long(lastErr));
                                                                  ^
ExternalCodeEditor_WIN32.cxx: In function ‘int terminate_app(DWORD, DWORD)’:
ExternalCodeEditor_WIN32.cxx:117:54: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘DWORD {aka unsigned int}’ [-Wformat=]
              "trying TerminateProcess\n", msecTimeout);
                                                      ^
ExternalCodeEditor_WIN32.cxx: In static member function ‘static const char* ExternalCodeEditor::tmpdir_name()’:
ExternalCodeEditor_WIN32.cxx:300:41: error: ‘_snprintf’ was not declared in this scope
     tempdir, (long)GetCurrentProcessId());
                                         ^
ExternalCodeEditor_WIN32.cxx: In member function ‘const char* ExternalCodeEditor::tmp_filename()’:
ExternalCodeEditor_WIN32.cxx:343:69: error: ‘_snprintf’ was not declared in this scope
   _snprintf(path, sizeof(path), "%s\\%p%s", tmpdir, (void*)this, ext);
                                                                     ^
ExternalCodeEditor_WIN32.cxx: In member function ‘int ExternalCodeEditor::start_editor(const char*, const char*)’:
ExternalCodeEditor_WIN32.cxx:422:60: error: ‘_snprintf’ was not declared in this scope
   _snprintf(cmd, sizeof(cmd), "%s %s", editor_cmd, filename);
                                                            ^
make[1]: *** [../makeinclude:162: ExternalCodeEditor_WIN32.o] Error 1
make: *** [Makefile:24: all] Error 1


Ian MacArthur

unread,
Mar 28, 2018, 2:58:46 PM3/28/18
to fltkg...@googlegroups.com


> On 28 Mar 2018, at 18:56, sebastian wrote:
>
> Hello,
>
> I am compiling the FLTK 1.3.4 on Windows 10 using the Cygwin environment.
> When making fluid, errors occurred when trying to compiling 'ExternalCodeEditor_WIN32.cxx':
>
> '_snprintf' was not declared in this scope
>
> What might be the problems here?
> The complete error messages are attached below.


I don’t know - it looks like cygwin is not exposing _snprintf() which seems very odd for a tool that runs on Windows.

I haven’t used cygwin in quite a while now - I generally use the mingw32 / mingw64 toolchains instead for Windows builds, and they are fine. They do expose both _snprintf() and snprintf() on Windows, and I would imagine that cygwin did the same... but apparently not.

Do other things build OK though, it is just this one file?


Can you try one of the mingw toolchains, or even the community edition VS, and see if that works on your machine (they should, of course!)


FWIW, you could try temporarily replacing all 4 occurrences of _snprintf() with snprintf() and see if that helps, but TBH I think it ought to work, so I’m a bit surprised that it doesn’t...






Greg Ercolano

unread,
Mar 28, 2018, 3:37:58 PM3/28/18
to fltkg...@googlegroups.com
On 03/28/18 10:56, sebastian wrote:
> '_snprintf' was not declared in this scope

Try editing the fluid/ExternalCodeEditor_WIN32.cxx file
and make these changes:

1) Add at the top of the file:

#include "../src/flstring.h"

2) Change all the _snprintf() calls to fl_snprintf() instead.
I think there's 4 instances in that file

Save, rebuild.


Albrecht Schlosser

unread,
Mar 30, 2018, 5:48:27 AM3/30/18
to fltkg...@googlegroups.com
On 28.03.2018 19:56 schrieb sebastian:

> I am compiling the FLTK 1.3.4 on Windows 10 using the Cygwin environment.
> When making fluid, errors occurred when trying to compiling
> 'ExternalCodeEditor_WIN32.cxx':
>
>   '_snprintf' was not declared in this scope
>
> What might be the problems here?

As others wrote already, editing the source and replacing _snprintf with
snprintf or fl_snprintf *might* help to get you further. However, the
"standard" build under Cygwin with ./configure + make will likely not work.

As Ian said, MinGW is more appropriate to build Windows applications
under Windows.

However, if you want to use Cygwin as your build environment, then there
are several options:

(1) To build "Cygwin" applications that depend on Cygwin1.dll and use
X11 as the GUI (you need a running X server) you must configure FLTK with

./configure --enable-x11 --enable-cygwin

This works and builds programs that will only run under Cygwin and to
distribute them you need a commercial Cygwin license.


(2) If you want to use Cygwin to build native, freely distributable
Windows applications that don't depend on Cygwin, then you must install
the MinGW-w64 cross compiler packages for 32-bit and/or 64-bit. The
configuration is a little more complicated but works for me:

(2a) To build 32-bit programs use:

LDFLAGS="-static-libgcc -static-libstdc++" ./configure
--host=i686-w64-mingw32

(2b) To build 64-bit programs use:

LDFLAGS="-static-libgcc -static-libstdc++" ./configure
--host=x86_64-w64-mingw32

Note the LDFLAGS definition: this is necessary. You may also want to
define CXXFLAGS and CFLAGS.

Kevin Stevens

unread,
May 14, 2018, 4:13:22 AM5/14/18
to fltk.general
What worked for me was adding the line

#define _snprintf(...) snprintf(__VA_ARGS__)

to the top of the file (below the #includes) to 'ExternalCodeEditor_WIN32.cxx' which replaces the underscore version of the function for the standard library function at compile time.
I'm not sure why the underscore version was specified, but I can confirm I am now able to compile, link and run fluid on Windows 10 Pro
Reply all
Reply to author
Forward
0 new messages