Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reference to 'byte' is ambiguous #7035

Closed
vangola-silver opened this issue Sep 25, 2020 · 8 comments
Closed

reference to 'byte' is ambiguous #7035

vangola-silver opened this issue Sep 25, 2020 · 8 comments

Comments

@vangola-silver
Copy link

Versions:

Hi guys,
I currently trying to port one of my Linux programs to Windows/MinGW. During the compilation I see some “strange” errors regarding a redefinition of ‘byte’.
This is the full error output:

C:/msys64/mingw32/i686-w64-mingw32/include/rpcndr.h:63:25: note: 'typedef unsigned char byte'
   63 |   typedef unsigned char byte;
      |                         ^~~~ 
In file included from C:/msys64/mingw32/i686-w64-mingw32/include/msxml.h:25,
                 from C:/msys64/mingw32/i686-w64-mingw32/include/urlmon.h:450,
                 from C:/msys64/mingw32/i686-w64-mingw32/include/objbase.h:163,
                 from C:/msys64/mingw32/i686-w64-mingw32/include/ole2.h:17,
                 from C:/msys64/mingw32/i686-w64-mingw32/include/naptypes.h:13,
                 from C:/msys64/mingw32/i686-w64-mingw32/include/ras.h:17,
                 from C:/msys64/mingw32/i686-w64-mingw32/include/mprapi.h:14,
                 from C:/msys64/mingw32/i686-w64-mingw32/include/iprtrmib.h:12,
                 from C:/msys64/mingw32/i686-w64-mingw32/include/Iphlpapi.h:15,
                 from C:/msys64/mingw32/include/Poco/UnWindows.h:33,
                 from C:/msys64/mingw32/include/Poco/Platform_WIN32.h:22,
                 from C:/msys64/mingw32/include/Poco/Foundation.h:100,
                 from C:/msys64/mingw32/include/Poco/XML/XML.h:23,
                 from C:/msys64/mingw32/include/Poco/SAX/ContentHandler.h:21,
C:/msys64/mingw32/i686-w64-mingw32/include/oaidl.h:579:5: error: reference to 'byte' is ambiguous
  579 |     byte *pRecord;
      |     ^~~~
In file included from C:/msys64/mingw32/include/c++/10.2.0/bits/stl_algobase.h:61,
                 from C:/msys64/mingw32/include/c++/10.2.0/bits/stl_tree.h:63,
                 from C:/msys64/mingw32/include/c++/10.2.0/map:60,
C:/msys64/mingw32/include/c++/10.2.0/bits/cpp_type_traits.h:404:30: note: candidates are: 'enum class std::byte'
  404 |   enum class byte : unsigned char;
      |                              ^~~~
In file included from C:/msys64/mingw32/i686-w64-mingw32/include/naptypes.h:8,
                 from C:/msys64/mingw32/i686-w64-mingw32/include/ras.h:17,
                 from C:/msys64/mingw32/i686-w64-mingw32/include/mprapi.h:14,
                 from C:/msys64/mingw32/i686-w64-mingw32/include/iprtrmib.h:12,
                 from C:/msys64/mingw32/i686-w64-mingw32/include/Iphlpapi.h:15,
                 from C:/msys64/mingw32/include/Poco/UnWindows.h:33,
                 from C:/msys64/mingw32/include/Poco/Platform_WIN32.h:22,
                 from C:/msys64/mingw32/include/Poco/Foundation.h:100,
                 from C:/msys64/mingw32/include/Poco/XML/XML.h:23,
                 from C:/msys64/mingw32/include/Poco/SAX/ContentHandler.h:21

Do you know a way how to fix this?
Any help will be appreciated.

@Biswa96
Copy link
Member

Biswa96 commented Sep 25, 2020

This issue seems to be related to mingw-w64 headers. A minimal, simple, hello world like example would be helpful to identify the issue faster 😊

@vangola-silver
Copy link
Author

vangola-silver commented Sep 25, 2020

Trying to reproduce the error using a simple example I was able to reduce it to a few lines of code and was able to find the solution (or at least a workaround).

Steps to reproduce:

  1. Create source file with following content
#include <map>
using namespace std;
#include <Poco/SAX/ContentHandler.h>
  1. Try to compile it with following (or similar) line
g++ -c -MMD -MP -std=gnu++17 -Wall -DPOCO_STATIC -DMINGW32 -D_WIN32 -O2 -I.  -ID:\sergej-work\ProSystems-git/INCLUDE -IC:\msys64\mingw32\include\Poco/Net/include -IC:\msys64\mingw32\include\Poco/Util/include -IC:\msys64\mingw32\include\Poco/JSON/include -IC:\msys64\mingw32\include\Poco/JWT/include -IC:\msys64\mingw32\include\Poco/XML/include -IC:\msys64\mingw32\include\Poco/Foundation/include  -o ../GnuDev/mingw32/rel/Test.o Test.cpp
  1. Observe the error message as shown in my first post.

Steps to fix the issue:

  1. Delete the line using namespace std;

  2. Compile it again and observe that the issue is gone.

@Biswa96
Copy link
Member

Biswa96 commented Sep 25, 2020

I can not reproduce the issue with your sample source code. Some suggestions:

  1. Maybe there is something wrong with your code or building environment.
  2. Place using namespace after all the includes.
  3. Try not to use using namespace std;, at least not with STL. Instead use std:: like notation.
  4. In the command, try not to add include /mingw64 directories. Those will be automatically included by compiler.

@vangola-silver
Copy link
Author

To clarify the sample code was not take from my project as is, but was a result of including several headers. One of the header happend to have the using namespace std; line in it, which I did not see before combining the files by hand.
Your suggestion to use std:: like notation did the trick.
Now I know why the CppCoreGuideline says "Don’t write using namespace at global scope in a header file".

@Biswa96
Copy link
Member

Biswa96 commented Sep 25, 2020

So, is this case closed? 🕵️

@vangola-silver
Copy link
Author

Yeah, thanks for helping!

@ingvart
Copy link

ingvart commented Feb 9, 2023

I ran into the same issue. For me this means that in a project one can never "using namespace std" anywhere in the entire application/code if windows.h is included, which is a headache.

@Biswa96
Copy link
Member

Biswa96 commented Feb 9, 2023

one can never "using namespace std" anywhere

One should not use "using namespace std" anywhere. See this little explanation https://isocpp.org/wiki/faq/coding-standards#using-namespace-std

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants