chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.09k stars 450 forks source link

cef_string_wrappers.h includes <memory.h> when it should be including <cstring> for strlen #3665

Closed Lachcim closed 3 months ago

Lachcim commented 3 months ago

Describe the bug

When compiling libcef_dll_wrapper with g++ on MSYS2 (UCRT environment), the following error occurs:

cd C:/msys64/home/user/cef/build/libcef_dll_wrapper && C:/msys64/ucrt64/bin/c++.exe -DCEF_USE_SANDBOX -DNDEBUG -DPSAPI_VERSION=1 -DWRAPPING_CEF_SHARED -D_FILE_OFFSET_BITS=64 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS @CMakeFiles/libcef_dll_wrapper.dir/includes_CXX.rsp -O3 -DNDEBUG -fno-strict-aliasing -fPIC -fstack-protector -funwind-tables -fvisibility=hidden --param=ssp-buffer-size=4 -pipe -pthread -Wall -Werror -Wno-missing-field-initializers -Wno-unused-parameter -Wno-error=comment -Wno-comment -Wno-deprecated-declarations -m64 -march=x86-64 -fno-exceptions -fno-rtti -fno-threadsafe-statics -fvisibility-inlines-hidden -std=c++17 -Wsign-compare -Wno-undefined-var-template -Wno-literal-suffix -Wno-narrowing -Wno-attributes -O2 -fdata-sections -ffunction-sections -fno-ident -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -MD -MT libcef_dll_wrapper/CMakeFiles/libcef_dll_wrapper.dir/transfer_util.cc.obj -MF CMakeFiles/libcef_dll_wrapper.dir/transfer_util.cc.obj.d -o CMakeFiles/libcef_dll_wrapper.dir/transfer_util.cc.obj -c C:/msys64/home/user/cef/libcef_dll/transfer_util.cc
In file included from C:/msys64/home/user/cef/include/internal/cef_string.h:50,
                 from C:/msys64/home/user/cef/include/internal/cef_string_list.h:35,
                 from C:/msys64/home/user/cef/libcef_dll/transfer_util.h:12,
                 from C:/msys64/home/user/cef/libcef_dll/transfer_util.cc:5:
C:/msys64/home/user/cef/include/internal/cef_string_wrappers.h: In member function 'bool CefStringBase<traits>::FromASCII(const char*)':
C:/msys64/home/user/cef/include/internal/cef_string_wrappers.h:636:24: error: there are no arguments to 'strlen' that depend on a template parameter, so a declaration of 'strlen' must be available [-fpermissive]
  636 |     size_t len = str ? strlen(str) : 0;
      |                        ^~~~~~
C:/msys64/home/user/cef/include/internal/cef_string_wrappers.h:636:24: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)

The compiler doesn't see a declaration of strlen, which I assume it expects to reside in the memory.h header included at the top of the file. memory.h is not a standard C or C++ header file and therefore there are no guarantees on which declarations it contains. It appears that the UCRT implementation of memory.h does not include strlen. Replacing #include <memory.h> with #include <cstring> resolves the issue.

To Reproduce Steps to reproduce the behavior:

  1. Download a binary distribution of CEF for Windows
  2. Modify the cef_variables.cmake file so that it uses GCC command line options on Windows
  3. Compile libcef_dll_wrapper with cmake using the UCRT environment for MSYS2
  4. The build fails, giving the above error

Expected behavior

The build should succeed. Replacing #include <memory.h> with #include <cstring> allows the build to succeed:

[  1%] Building CXX object libcef_dll_wrapper/CMakeFiles/libcef_dll_wrapper.dir/transfer_util.cc.obj
cd C:/msys64/home/user/cef/build/libcef_dll_wrapper && C:/msys64/ucrt64/bin/c++.exe -DCEF_USE_SANDBOX -DNDEBUG -DPSAPI_VERSION=1 -DWRAPPING_CEF_SHARED -D_FILE_OFFSET_BITS=64 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS @CMakeFiles/libcef_dll_wrapper.dir/includes_CXX.rsp -O3 -DNDEBUG -fno-strict-aliasing -fPIC -fstack-protector -funwind-tables -fvisibility=hidden --param=ssp-buffer-size=4 -pipe -pthread -Wall -Werror -Wno-missing-field-initializers -Wno-unused-parameter -Wno-error=comment -Wno-comment -Wno-deprecated-declarations -m64 -march=x86-64 -fno-exceptions -fno-rtti -fno-threadsafe-statics -fvisibility-inlines-hidden -std=c++17 -Wsign-compare -Wno-undefined-var-template -Wno-literal-suffix -Wno-narrowing -Wno-attributes -O2 -fdata-sections -ffunction-sections -fno-ident -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -MD -MT libcef_dll_wrapper/CMakeFiles/libcef_dll_wrapper.dir/transfer_util.cc.obj -MF CMakeFiles/libcef_dll_wrapper.dir/transfer_util.cc.obj.d -o CMakeFiles/libcef_dll_wrapper.dir/transfer_util.cc.obj -c C:/msys64/home/mszopinski/cef_binary/libcef_dll/transfer_util.cc

[ 61%] Linking CXX static library libcef_dll_wrapper.a
[100%] Built target libcef_dll_wrapper

Versions (please complete the following information):

Additional context

I understand that exotic compiler configurations such as GCC on MSYS2 are not a priority for the CEF project. However, you are one line of code away from making it work. cef_string_wrappers.h appears to be the only header file in libcef_dll_wrapper that includes memory.h.

magreenblatt commented 3 months ago

Replacing #include with #include \ resolves the issue.

Sounds reasonable. Please submit a PR at https://bitbucket.org/chromiumembedded/cef/pull-requests/

Lachcim commented 3 months ago

I've submitted a pull request at https://bitbucket.org/chromiumembedded/cef/pull-requests/735

Lachcim commented 3 months ago

Thank you! Great success! 🥰