Closed camcc591 closed 7 months ago
@camcc591, thanks for posting this issue, please provide steps to reproduce your error, and provide a detailed error log.
To reproduce the errors
make the following corrections to vcpkg\installed\x64-windows\include\gmp.h Line 1785: error: 'return': conversion from 'mp_limb_t' to 'unsigned long', possible loss of data change from: return (gmp_n != 0 ? __gmp_l : 0); change to: return (unsigned long)(gmp_n != 0 ? gmp_l : 0); Line 2230: error: unary minus operator applied to unsigned type, result still unsigned change from: __gmp_rp = (- gmp_up) & GMP_NUMB_MASK; change to: __gmp_rp = (-1) (*__gmp_up) & GMP_NUMB_MASK;
make the following corrections to vcpkg\installed\x64-windows\include\gmpxx.h
Lines 101, 155, 206, 278, 322, 330, 372, 407, 414, 442, 525, 570, 599, 667, 720, 764, 774, 1292, 1593, 1617:
error: unary minus operator applied to unsigned type, result still unsigned
example correction:
o change from: -static_cast
build the test program again. Note that the test program now compiles successfully.
If the errors listed are not noted with other build engines they must be a compatibility issue with Visual Studio 2022. Question 1: Are the corrections listed above correct? Question 2: How can these compatibility issues be corrected in the vcpkg distribution so I don't have to re-correct the files every time I build the gmp library?
@camcc591, thanks for the steps, I'll try to reproduce your error as soon as possible.
Thank you. I appreciate that.
I'm still working on a concise program that demonstrates the nullptr_t issue.
From: JonLiu1993 @.> Sent: Tuesday, June 27, 2023 2:23 AM To: microsoft/vcpkg @.> Cc: csstu @.>; Mention @.> Subject: Re: [microsoft/vcpkg] Visual Studio compatibility (Issue #32193)
@camcc591 https://github.com/camcc591 , thanks for the steps, I'll try to reproduce your error as soon as possible.
— Reply to this email directly, view it on GitHub https://github.com/microsoft/vcpkg/issues/32193#issuecomment-1609028473 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABY5WTRSZJYXEBO3EE3CDQ3XNKJ7TANCNFSM6AAAAAAZSHGVFU . You are receiving this because you were mentioned. https://github.com/notifications/beacon/ABY5WTRKCWOGUIFR64LYLTLXNKJ7TA5CNFSM6AAAAAAZSHGVFWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTS747JXS.gif Message ID: @.***>
@camcc591, I use vcpkg 2023-06-15-8c254a5fb6c503615834fc66bd0717664a339a2e locally and VS2022 17.6.2 version
did not reproduce your problem, I can successfully use gmp:x64-windows
:
CMakeLists:
cmake_minimum_required(VERSION 3.16)
project(test)
find_package(PkgConfig REQUIRED)
pkg_check_modules(gmp REQUIRED IMPORTED_TARGET gmp)
add_executable(main usageTest.cpp)
target_link_libraries(main PkgConfig::gmp)
usageTest.cpp:
#include <stdio.h>
#include <gmpxx.h>
int main() {
mpz_class mpzA, mpzB, mpzC;
mpzA = 5;
mpzB = 7;
mpzC = mpzA + mpzB;
gmp_fprintf(stdout, "%Zd\t%Zd\t%Zd", mpzA, mpzB, mpzC);
return 0;
}
1> CMake generation started for configuration: 'x64-Debug'.
1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Visual Studio 17 2022" -A x64 -DCMAKE_CONFIGURATION_TYPES:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\test\source\repos\usageTest\out\install\x64-Debug" -DCMAKE_TOOLCHAIN_FILE=F:/test/vcpkg/scripts/buildsystems/vcpkg.cmake "C:\Users\test\source\repos\usageTest" 2>&1"
1> Working directory: C:\Users\test\source\repos\usageTest\out\build\x64-Debug
1> [CMake] -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
1> [CMake] -- The C compiler identification is MSVC 19.36.32532.0
1> [CMake] -- The CXX compiler identification is MSVC 19.36.32532.0
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - done
1> [CMake] -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- Detecting CXX compiler ABI info
1> [CMake] -- Detecting CXX compiler ABI info - done
1> [CMake] -- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting CXX compile features
1> [CMake] -- Detecting CXX compile features - done
1> [CMake] -- Found PkgConfig: F:/test/vcpkg/installed/x64-windows/tools/pkgconf/pkgconf.exe (found version "1.8.0")
1> [CMake] -- Checking for module 'gmp'
1> [CMake] -- Found gmp, version 6.2.1
1> [CMake] -- Configuring done (8.3s)
1> [CMake] -- Generating done (0.0s)
1> [CMake] -- Build files have been written to: C:/Users/test/source/repos/usageTest/out/build/x64-debug
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted toolchain configurations.
1> Extracted includes paths.
1> CMake generation finished.
>------ Build All started: Project: usageTest, Configuration: x64-Debug ------
MSBuild version 17.6.3+07e294721 for .NET Framework
Checking Build System
Building Custom Rule C:/Users/test/source/repos/usageTest/usageTest/CMakeLists.txt
usageTest.cpp
main.vcxproj -> C:\Users\test\source\repos\usageTest\out\build\x64-debug\usageTest\Debug\main.exe
Building Custom Rule C:/Users/test/source/repos/usageTest/CMakeLists.txt
Build All succeeded.
Regarding your question, because I have not reproduced this issue, I have no way to judge whether your modification is right or wrong. Your modification involves the upstream code. I suggest that you submit an issue upstream.
E2020 the managed nullptr type cannot be used here
AFAIU this shouldn't occur for regular C++. I would assume some unusual flags are added on the user side.
I don't use CMake. I use VS 2022 to build the executable.
Start with an empty VS project.
Add the test file (I called it) GMPtest.cpp
In the Solution Explorer, right click on the project and select build.
Or, from the top menu select Build > Build Solution.
Without the corrections I get the errors described.
With the corrections the errors are not identified.
From: JonLiu1993 @.> Sent: Wednesday, June 28, 2023 1:13 AM To: microsoft/vcpkg @.> Cc: csstu @.>; Mention @.> Subject: Re: [microsoft/vcpkg] Visual Studio compatibility (Issue #32193)
@camcc591 https://github.com/camcc591 , I use vcpkg 2023-06-15-8c254a5fb6c503615834fc66bd0717664a339a2e locally and VS2022 17.6.2 version did not reproduce your problem, I can successfully use gmp:x64-windows: CMakeLists:
cmake_minimum_required(VERSION 3.16)
project(test)
find_package(PkgConfig REQUIRED)
pkg_check_modules(gmp REQUIRED IMPORTED_TARGET gmp)
add_executable(main usageTest.cpp)
target_link_libraries(main PkgConfig::gmp)
usageTest.cpp:
int main() { mpz_class mpzA, mpzB, mpzC;
mpzA = 5;
mpzB = 7;
mpzC = mpzA + mpzB;
gmp_fprintf(stdout, "%Zd\t%Zd\t%Zd", mpzA, mpzB, mpzC);
return 0;
} 1> CMake generation started for configuration: 'x64-Debug'. 1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Visual Studio 17 2022" -A x64 -DCMAKE_CONFIGURATION_TYPES:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\test\source\repos\usageTest\out\install\x64-Debug" -DCMAKE_TOOLCHAIN_FILE=F:/test/vcpkg/scripts/buildsystems/vcpkg.cmake "C:\Users\test\source\repos\usageTest" 2>&1" 1> Working directory: C:\Users\test\source\repos\usageTest\out\build\x64-Debug 1> [CMake] -- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045. 1> [CMake] -- The C compiler identification is MSVC 19.36.32532.0 1> [CMake] -- The CXX compiler identification is MSVC 19.36.32532.0 1> [CMake] -- Detecting C compiler ABI info 1> [CMake] -- Detecting C compiler ABI info - done 1> [CMake] -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped 1> [CMake] -- Detecting C compile features 1> [CMake] -- Detecting C compile features - done 1> [CMake] -- Detecting CXX compiler ABI info 1> [CMake] -- Detecting CXX compiler ABI info - done 1> [CMake] -- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped 1> [CMake] -- Detecting CXX compile features 1> [CMake] -- Detecting CXX compile features - done 1> [CMake] -- Found PkgConfig: F:/test/vcpkg/installed/x64-windows/tools/pkgconf/pkgconf.exe (found version "1.8.0") 1> [CMake] -- Checking for module 'gmp' 1> [CMake] -- Found gmp, version 6.2.1 1> [CMake] -- Configuring done (8.3s) 1> [CMake] -- Generating done (0.0s) 1> [CMake] -- Build files have been written to: C:/Users/test/source/repos/usageTest/out/build/x64-debug 1> Extracted CMake variables. 1> Extracted source files and headers. 1> Extracted code model. 1> Extracted toolchain configurations. 1> Extracted includes paths. 1> CMake generation finished.
------ Build All started: Project: usageTest, Configuration: x64-Debug ------ MSBuild version 17.6.3+07e294721 for .NET Framework
Checking Build System
Building Custom Rule C:/Users/test/source/repos/usageTest/usageTest/CMakeLists.txt
usageTest.cpp
main.vcxproj -> C:\Users\test\source\repos\usageTest\out\build\x64-debug\usageTest\Debug\main.exe
Building Custom Rule C:/Users/test/source/repos/usageTest/CMakeLists.txt
Build All succeeded.
— Reply to this email directly, view it on GitHub https://github.com/microsoft/vcpkg/issues/32193#issuecomment-1610891814 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABY5WTS4JHNWVA2GFPTQKQDXNPKRNANCNFSM6AAAAAAZSHGVFU . You are receiving this because you were mentioned. https://github.com/notifications/beacon/ABY5WTRN5IJHD3JEHIL2O33XNPKRNA5CNFSM6AAAAAAZSHGVFWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTAARBCM.gif Message ID: @.***>
Regarding nullptr type, "AFAIU this shouldn't occur for regular C++. I would assume some unusual flags are added on the user side."
Please excuse the sarcasm, but none of these errors should occur. Yet they do. :-) Any idea what functions invoke the exceptions in File: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\exception Lines: 227, 244, 278, 283, 291, 295
Regarding nullptr type, "AFAIU this shouldn't occur for regular C++. I would assume some unusual flags are added on the user side."
Please excuse the sarcasm, but none of these errors should occur. Yet they do. :-) Any idea what functions invoke the exceptions in File: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\exception Lines: 227, 244, 278, 283, 291, 295
Instead of pointless sarcastic loops, any chance to provide log files which show the actual flags used?
I tracked the nullptr issue to the use of Common Language Runtime Support - the /clr switch. In Visual Studio, open a new project, include a main file which includes gmpxx.h and a main program.
int main() { return 0; } In the solution properties, turn on Common Language Runtime Support. I get the following errors: Severity Code Description Project File Line Suppression State Error (active) E2020 the managed nullptr type cannot be used here NulPtrCLRS C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\exception 283 Error (active) E2020 the managed nullptr type cannot be used here NulPtrCLRS C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\exception 278 Error (active) E2020 the managed nullptr type cannot be used here NulPtrCLRS C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\exception 291 Error (active) E2020 the managed nullptr type cannot be used here NulPtrCLRS C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\exception 295
Delete the line #include
It would seem that any program that requires gmplib and Common Language Runtime support will generate these errors. For example
//message indicator constants enum MSG_INDI { msgNo, //no error msgAccErr, //bad accumulator string msgUnknown, //unknown error };
//convert a system string to a multi-precision-float //msgRtn == error if any mpf_class SysString2mpf(System::String^ strA, MSG_INDI *msgRtn) { mpf_class mpfRtn = 0.0;
using namespace System::Runtime::InteropServices;
//get sys string to char array
char *chrS = (char*)(Marshal::StringToHGlobalAnsi(strA)).ToPointer();
//transfer value to mpfRtn and check for error
if (mpf_set_str(mpfRtn.get_mpf_t(), chrS, 10) == 0) {
*msgRtn = msgNo; //good conversion
}
else {
*msgRtn = msgAccErr; //bad conversion
}
//free chrS memory
Marshal::FreeHGlobal(System::IntPtr((void*)chrS));
return mpfRtn;
} //SysString2mpf
int main() { mpf_class mpfPi; System::String ^Str; MSG_INDI rtn;
//assign an mpf from System String
Str = L"3.14159265358979323808";
mpfPi = SysString2mpf(Str, &rtn);
//print mpf
if (rtn == msgNo) {
gmp_printf("%0.20Ff", mpfPi);
}
else {
printf("error");
}
return 0;
}
/clr
. This is the information I wanted to see spelled out. AFAIU you are not using regular C++ with /clr
. I wouldn't consider this a port bug. But maybe you get a more specific answer from MSVC expert now.
@camcc591, does this problem still exist?
I just checked for updates to vcpkg. I am current. Thus, if no updates have been posted, the problems still exist.
The issues with gmp.h and gmpxx.h are a matter of type casting. That the Microsoft compiler in Visual Studio is more stringent regarding type casting than other compilers should not be the issue. The errors are easily corrected as explained in previous posts.
Common Language Runtime is a public standard. I don't know which functions make use of the exceptions indicated by the errors. I don't know how to further troubleshoot these errors. If the librarians of gmp choose to not properly implement managed null pointers, that is not something I can fix.
From: JonLiu1993 @.> Sent: Friday, July 21, 2023 1:33 AM To: microsoft/vcpkg @.> Cc: csstu @.>; Mention @.> Subject: Re: [microsoft/vcpkg] Visual Studio compatibility (Issue #32193)
@camcc591 https://github.com/camcc591 , does this problem still exist?
— Reply to this email directly, view it on GitHub https://github.com/microsoft/vcpkg/issues/32193#issuecomment-1645117928 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABY5WTVDDN22U2CW7NYH4XDXRIWCPANCNFSM6AAAAAAZSHGVFU . You are receiving this because you were mentioned. https://github.com/notifications/beacon/ABY5WTWTZSPDY5XMIZUMSFTXRIWCPA5CNFSM6AAAAAAZSHGVFWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTCB2A6Q.gif Message ID: @.***>
I think this issue is not related to vcpkg? Maybe you should report this to vs feedback or gmp instead?
Maybe you should report this to ... gmp instead?
I don't think gmp cares about CLR.
I think this issue is not related to vcpkg?
No, it isn't.
Isn't there markup for wrapping #include <gmpxx.h>
so that it is recognized as unmanaged code?
Such as #pragma unmanaged
?
This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 28 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.
I have the same problem, in exception file: E2020 the managed nullptr type cannot be used here There are 6 of them; exception file lines 230, 247, 281, 286, 294, 298
Interestingly, while trying to solve the LNK2001 problem, I solved the E2020 problem by doing: Project->Properties->Configuration Properties->General->Configuration Type: Dynamic Library Although the 6 E2020 error messages disappeared, they are still present inside the exception file. Being new to VS, now hassling with the LNK2001 problem.....
@aacsus I still think "unmanaged" (i.e. normal) C++ headers might work with some wrapping in "managed" (i.e. non-standard) C++. But it must be done in your project, not in vcpkg. If you want to use CLR, you must probably learn this anyways.
This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 28 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.
This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 28 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.
Twice I tried to report this information to gmplib.org. All the website information tells me to send an email to gmp-bugs@gmplib.org. I did that and received an undeliverable message. The target computer actively refused it. Is the gmplib organization still listening to their bug email?
Maybe you should report this to ... gmp instead?
I don't think gmp cares about CLR.
This seems to hold.
I think this issue is not related to vcpkg?
No, it isn't.
Isn't there markup for wrapping
#include <gmpxx.h>
so that it is recognized as unmanaged code? Such as#pragma unmanaged
?
Did you ever try to wrap you include statements?
I built gmp library using vcpkg. Reference https://vcpkg.io/en/getting-started.html https://learn.microsoft.com/en-us/vcpkg/commands/update
Using Visual Studio 2022 I wrote a simple test program
include
include
int main() { mpz_class mpzA, mpzB, mpzC;
}
I had to fix several errors identified in gmp.h and gmpxx.h.
File gmp.h warnings and errors: Line 1785: • 'return': conversion from 'mp_limb_t' to 'unsigned long', possible loss of data o change from: return (gmp_n != 0 ? __gmp_l : 0); o change to: return (unsigned long)(gmp_n != 0 ? gmp_l : 0); Line 2230: • unary minus operator applied to unsigned type, result still unsigned o change from: __gmp_rp = (- gmp_up) & GMP_NUMB_MASK; o change to: __gmp_rp = (-1) (*__gmp_up) & GMP_NUMB_MASK;
File gmpxx.h errors: Lines 101, 155, 206, 278, 322, 330, 372, 407, 414, 442, 525, 570, 599, 667, 720, 764, 774, 1292, 1593, 1617: • unary minus operator applied to unsigned type, result still unsigned • example: o change from: -static_cast(l)
o change to: static_cast(-l)
When compiling more complex programs Error: E2020 the managed nullptr type cannot be used here File: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include\exception Lines: 278, 283, 291, 295
Even though these are errors, they do not preclude successful compilation. I do not know how these errors affect the program functioning. Looking at the target file, nullptr_t appears on additional lines: 227, 244
How can these compatibility issues be address in the gmp release?