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

MSVC 2022: C++ library build broken with UNICODE #29

Closed
gpascualg opened this issue Nov 19, 2021 · 5 comments
Closed

MSVC 2022: C++ library build broken with UNICODE #29

gpascualg opened this issue Nov 19, 2021 · 5 comments
Labels
bug Something isn't working C++ instrumentation Related to the C++ instrumentation library question Further information is requested

Comments

@gpascualg
Copy link

When trying to build the c++ library while having UNICODE declared, the following error occurs:

palanteer-src\c++\palanteer.h(4346,53): error C2440: '=': cannot convert from 'const wchar_t [17]' to 'LPWSTR'

Basically, in that line, LogFile.LoggerName = KERNEL_LOGGER_NAME; the structure field expects a non-const value, while KERNEL_LOGGER_NAME is const. I have worked around it by casting it to (LPWSTR). I don't know the API exactly, so it feels like a hack to cast it to non-constness.

- LogFile.LoggerName          = KERNEL_LOGGER_NAME;
+ #if defined(_UNICODE) || defined(UNICODE)
+ LogFile.LoggerName          = (LPWSTR)KERNEL_LOGGER_NAME;
+ #else
+ LogFile.LoggerName          = KERNEL_LOGGER_NAME;
+ #endif
@dfeneyrou dfeneyrou added bug Something isn't working C++ instrumentation Related to the C++ instrumentation library labels Nov 20, 2021
@dfeneyrou
Copy link
Owner

I was unable to reproduce this compilation issue with MSVC 2019 nor MSVC 2022 (installed it on purpose, only the "Build Tools"), when trying to build the test program.

In ./c++/testprogram/CMakeList.txt, the -DUNICODE is added by default, so I thought that it was linked to MSVC 2022.
With or without the addition of -DUNICODE , the type of the system constant KERNEL_LOGGER_NAME changes (LPSTR or LPWSTR) but is always consistent with the LoggerName type and I never got the const issue that you faced.

In short, in my case, both the actual code and your patch are working, also both for MSVC 2019 or 2022.
I used the command line nmake testprogram for all tests.

Can you give more details on your build setup and/or reproduce the issue with the provided test program (so with nmake testprogram)?

@dfeneyrou dfeneyrou added the question Further information is requested label Nov 20, 2021
@gpascualg
Copy link
Author

I'm currently away from home, but this Monday when I get back I'll build it and send you the outputs.
Thank you!

@BrodyHiggerson
Copy link
Contributor

BrodyHiggerson commented Nov 22, 2021

I've had the same issue in VS2019 v16.8.3 alongside a slew of warnings (will dig those out and open a separate issue listing them / a PR fixing them).

I'm using these flags:

/W4 /WX /std:c++latest /permissive- /D WIN32_LEAN_AND_MEAN /D NOMINMAX

Wonder if it's the permissive- (i.e. strict mode) flag.

My local fix was

LogFile.LoggerName = (char*)KERNEL_LOGGER_NAME;

@gpascualg
Copy link
Author

gpascualg commented Nov 22, 2021

Running nmake testprogram as is does, indeed, work. I have however isolated two instances that cause the error I was getting.

  1. As @BrodyHiggerson says, adding /permissive- will trigger the error. I suspect the error is always there, just that without permissive the cast is being done implicitely.

add_compile_options(/permissive-)

  1. Adding /std:c++20, which is my case. It seems enabling c++20 automatically enables strict conformance (permissive-).
    https://devblogs.microsoft.com/cppblog/msvc-cpp20-and-the-std-cpp20-switch/

add_compile_options(/std:c++20)

It definitely seems to be caused by strict mode.

Edit: I have not found any warning, though. So I don't know about them.

@dfeneyrou
Copy link
Owner

Thanks, I was able to reproduce it with /W4 /permissive- indeed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working C++ instrumentation Related to the C++ instrumentation library question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants