Opened 4 years ago

Closed 4 years ago

#17762 closed build error (fixed)

Build in MinGW fails: there is no wcsnlen function

Reported by: Tghawep Owned by: Vadim Zeitlin <vadim@…>
Priority: normal Milestone:
Component: build Version: 3.1.0
Keywords: Cc:
Blocked By: Blocking:
Patch: no

Description

include/wx/wxcrtbase.h:207-217

/*
    Only VC8 and later provide strnlen() and wcsnlen() functions under Windows.
 */
#if wxCHECK_VISUALC_VERSION(8)
    #ifndef HAVE_STRNLEN
        #define HAVE_STRNLEN
    #endif
    #ifndef HAVE_WCSNLEN
        #define HAVE_WCSNLEN
    #endif
#endif

Build fails on the MinGW (gcc 5.3.0) due to absence of wcsnlen in the standard library (yet strnlen is present).
Adding #undef HAVE_WCSNLEN after these lines solves the problem, but i'm not sure this is a proper solution.
Anyway, somebody should fix it.

Change History (11)

comment:1 Changed 4 years ago by Tghawep

  • Summary changed from There is no wcsnlen in MinGW to Build in MinGW fails: there is no wcsnlen function

comment:2 Changed 4 years ago by vadz

  • Status changed from new to infoneeded_new

Sorry, there really is not nearly enough information to do anything about this bug report here. Please answer at least the following questions:

  1. Which MinGW distribution do you use? MinGW-w64, TDM-GCC, something else?
  2. How do you build wxWidgets? Using makefiles, configure? Which options do you use?
  3. What is the error you're getting exactly? Please also show the full compiler command line resulting in it.

comment:3 Changed 4 years ago by izaya

  • Status changed from infoneeded_new to new

I also had this issue. #undef HAVE_WCSNLEN solved it for me.
I have mingw32.
I build wxWidgets using ./configure and after that make. I dont use any options.

In file included from ./include/wx/hashmap.h:15:0,
                 from ./include/wx/log.h:63,
                 from ./include/wx/msw/private.h:18,
                 from ./include/wx/wxprec.h:33:
./include/wx/wxcrt.h: In function 'size_t wxStrnlen(const wchar_t*, size_t)':
./include/wx/wxcrt.h:187:95: error: 'wcsnlen' was not declared in this scope
 inline size_t wxStrnlen(const wchar_t *str, size_t maxlen) { return wxCRT_StrnlenW(str, maxlen); }
                                                                                               ^
make: *** [.pch/wxprec_basedll/wx/wxprec.h.gch] Error 1

This is my error. I just type make and this is what I get.
Also in config.log I have this

configure:28621: checking for wcsdup
configure:28621: gcc -o conftest.exe    conftest.c  -lwinspool -lwinmm -lshell32 -lshlwapi -lcomctl32 -lcomdlg32 -ladvapi32 -lversion -lwsock32 -lgdi32 >&5
configure:28621: $? = 0
configure:28621: result: yes
configure:28621: checking for wcsnlen
configure:28621: gcc -o conftest.exe    conftest.c  -lwinspool -lwinmm -lshell32 -lshlwapi -lcomctl32 -lcomdlg32 -ladvapi32 -lversion -lwsock32 -lgdi32 >&5
configure:28621: $? = 0
configure:28621: result: yes
configure:28621: checking for wcscasecmp
Last edited 4 years ago by vadz (previous) (diff)

comment:4 Changed 4 years ago by Wabbina

  • Status changed from new to confirmed

Hi, I have similar issues. I use MinGW32 (GCC version 5.3.0) and I use the folowing command :

mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 USE_OPENGL=1 USE_GDIPLUS=1 BUILD=release CXXFLAGS="-std=gnu++11 -Wno-unused-value"

When I compile, I have the folowing errors :

g++ -c -o gcc_mswuddll\basedll_any.o -g -O0 -mthreads  -DHAVE_W32API_H -D__WXMSW
__       -D_UNICODE -I..\..\lib\gcc_dll\mswud -I..\..\include  -W -Wall -DWXBUIL
DING -I..\..\src\tiff\libtiff -I..\..\src\jpeg -I..\..\src\png -I..\..\src\zlib
-I..\..\src\regex -I..\..\src\expat\lib -DwxUSE_GUI=0 -DWXMAKINGDLL_BASE -DwxUSE
_BASE=1   -Wno-ctor-dtor-privacy   -MTgcc_mswuddll\basedll_any.o -MFgcc_mswuddll
\basedll_any.o.d -MD -MP ../../src/common/any.cpp
In file included from ..\..\include/wx/crt.h:19:0,
                 from ../../src/common/any.cpp:24:
..\..\include/wx/wxcrt.h: In function 'int wxStricmp(const char*, const char*)':

..\..\include/wx/wxcrt.h:324:47: error: '_stricmp' was not declared in this scop
e
 #define WX_STR_CALL(func, a1, a2)  func(a1, a2)
                                               ^
..\..\include/wx/wxcrt.h:338:18: note: in expansion of macro 'WX_STR_CALL'
         { return WX_STR_CALL(crtA, s1, s2); }                                 \

                  ^
..\..\include/wx/wxcrt.h:402:5: note: in expansion of macro 'WX_STR_FUNC_NO_INVE
RT'
     WX_STR_FUNC_NO_INVERT(int, name, crtA, crtW, forString)                   \

     ^
..\..\include/wx/wxcrt.h:459:1: note: in expansion of macro 'WX_STRCMP_FUNC'
 WX_STRCMP_FUNC(wxStricmp, wxCRT_StricmpA, wxCRT_StricmpW, wxStricmp_String)
 ^
..\..\include/wx/wxcrt.h: In function 'int wxStricmp(const char*, const wxScoped
CharBuffer&)':
..\..\include/wx/wxcrt.h:324:47: error: '_stricmp' was not declared in this scop
e
 #define WX_STR_CALL(func, a1, a2)  func(a1, a2)
                                               ^
..\..\include/wx/wxcrt.h:342:18: note: in expansion of macro 'WX_STR_CALL'
         { return WX_STR_CALL(crtA, s1, s2.data()); }  

comment:5 Changed 4 years ago by vadz

  • Status changed from confirmed to infoneeded_new

I can see wcsnlen() declaration in string.h of all MinGW versions I have. If it's not present in some of them, we need to know how to detect them/distinguish them from the known one. I'd really love to have complete answers to the questions in the comment:2, notably about which distribution of MinGW are you using. Please give at least the download link, surely you must know where did it come from?

The last question is completely unrelated as it's about _stricmp() and not wcsnlen() at all, I have no idea why would anybody consider it to be "similar". Please open a separate ticket for it and please also mention which MinGW distribution do you use. All I can say is that neither of these problems happens with the latest (or any other) versions of MinGW-w64 nor TDM-GCC distributions.

comment:6 Changed 4 years ago by izaya

  • Status changed from infoneeded_new to new

I have mingw downloaded from here https://vorboss.dl.sourceforge.net/project/mingw/Installer/mingw-get-setup.exe
It's mingw and msys. The link leads to installer from sourceforge.

comment:7 Changed 4 years ago by pb101

I cannot confirm any issue with string functions for MinGW/GCC 5.3.0, as I was able to successfully build wxWidgets with it just now.

My procedure (Windows 7 64-bit):

  1. I updated wxWidgets source from the GIT master branch head (with last commit being 0649b0d).
  2. I downloaded mingw-get-setup.exe from https://sourceforge.net/projects/mingw/
  3. 2. I made sure I have no other MinGW/GCC toolchains available (i.e., in %PATH%) that could conflict with MinGW/GCC I was going to install.
  4. Using the setup tool, I installed two packages: mingw32-base (reported in the setup tool as version 2013072200) and mingw32-gcc-g++ (reported in the setup tool as version 5.3.0-3), I did not install MSYS.
  5. I built wxWidgets (on Windows 7 64-bit) with command line from comment:4, except I had to work around the "AttachConsole not declared" bug by adding -D_WIN32_WINNT=0x0501 to CXXFLAGS so the actual command line was
    mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 USE_OPENGL=1 USE_GDIPLUS=1 BUILD=release CXXFLAGS="-std=gnu++11 -Wno-unused-value -D_WIN32_WINNT=0x0501"
    
  6. There was no error when building the library and I was able to successfully build the minimal sample as well, using the command line from above.


comment:8 Changed 4 years ago by vadz

Thanks a lot for testing! I didn't realize that you did see the bug with AttachConsole(), at least this is encouraging. I still have no idea what to do about the problem reported here though, other than ask the original reporter and/or izaya to try to debug it, it shouldn't be difficult to understand what goes on if you can see it, while it is very difficult to do it from here where everything works.

comment:9 Changed 4 years ago by vadz

More info: the bug with _stricmp (see comment:4) is a MinGW bug and only appears in debug builds, when inlining is disabled, which is why pb101 didn't see it (remove BUILD=release and it appears). I still have no idea about wcsnlen() problem though and can't reproduce it, after installing MinGW 5.3.0 myself.

comment:10 Changed 4 years ago by Vadim Zeitlin <vadim@…>

In 7c22e4257b1c1bc01094ee39d45bc824f6aea239/git-wxWidgets:

Fix build with MinGW 5.3 in debug mode

Due to a bug in MinGW (see https://sourceforge.net/p/mingw/bugs/2322/),
_stricmp() and _strnicmp() declarations are not visible when compiling without
optimizations. Work around this by declaring them ourselves.

See #17762.

comment:11 Changed 4 years ago by Vadim Zeitlin <vadim@…>

  • Owner set to Vadim Zeitlin <vadim@…>
  • Resolution set to fixed
  • Status changed from new to closed

In 22406c7d862c1a5e48d32d711a4488669596f7e2/git-wxWidgets:

Fix configure build with MinGW 5.3.0

Provide our own wcsnlen() declaration as the function is detected by configure
but is not declared in MinGW headers.

Closes #17762.

Note: See TracTickets for help on using tickets.