I am using third party code(openssl) from our product code. While compiling the code, I am getting the errors which can be suppressed as warnings using -fpermissive flag in Linux (gcc/g++). In windows, I am getting the same compilation errors in visual studio (2005). Would like to know the alternative of -fpermissive flag that can be used in visual studio to suppress the errors.
I tried adding the flags such as '/fpermissive' , '/Ze' in module properties->C/C++->command Line->Additional options. But it did not resolve the problem.
Getting the errors like below.
ssl/packet_locl.h(429) : error C2440: '=' : cannot convert from 'void *' to 'unsigned char 'Conversion from 'void' to pointer to non-'void' requires an explicit cast
Since it is giving error in third party code, we can not make any code changes there.
Expected results: We need to suppress this error as warning and then proceed with compilation successfully.
>>I tried adding the flags such as '/fpermissive' , '/Ze' in module properties->C/C++->command Line->Additional options.
That is define on gcc, you cannot use on VS. This is not suitable for VS.
>>cannot convert from 'void *' to 'unsigned char 'Conversion from 'void' to pointer to non-'void' requires an explicit cast
These are errors defined by the language. You can't ignore these errors and run the program directly. They cannot be compiled.
>>Since it is giving error in third party code, we can not make any code changes there.
If you strictly abide by the method to use the interfaces of these third party libraries, There will be no such errors. What your need is modifying your own code, not changing the third party library code.
Related
I had a task of removing all warnings in one of the project.
At one place in code I had following line.
dims[0] = children.size();
Where dims is 'int' array and children is a 'vector', so size_t is assigned to int. I am compiling this code on VS2015.
Ideally the above assignment should generate a warning
"C4267: '=': conversion from 'size_t' to 'int', possible loss of data"
But I don't get any such warning. So there are zero warnings in the code.
Now I convert warning 4267 into an error using '/we4267' and then start getting error for above lines.
I am confuse why compile didn't showed any warning in first place.
Thanking you all for your help.
I found that when /WX compiler option is added then some warnings, in my case C4267, are suppressed. Either adding compiler option /WX /Wall or removing them all together shows error/warning C4267. In my case I was getting error in other modules as there was no warning related compiler option add but the module where I didn't got C4267 warning, had compiler option /WX.
Its just that there is no documentation regarding this(or may be I was not able to find one).
I'm receiving the following warning in my project:
warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied while calling the constructor 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(const _Elem *)'
with
[
_Elem=char
]
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xstring(778) : see declaration of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string'
I understand why it's happening, I'm just unable to suppress it. I've tried adding it to the Disable Specific Warnings list in my project settings, and I've also set my warning level to Turn Off All Warnings (/W0), yet the warning persists. Does anyone have any recommendations on how to hide the message?
You can control Visual Studio warnings directly in code using #pragma warning (https://msdn.microsoft.com/en-us/library/2c8f766e.aspx). If you'd like to silence the warning for a single line, you can put the following immediately before the line:
#pragma warning (suppress: 4927)
line-that-causes-warning-4927
You can also disable it from any point past the #pragma, by using 'disable' instead of 'suppress'. However, as the comments suggest, it's better to actually fix the warning, because it could be causing issues in your program.
What to do when I cant compile my project after making it x64 compatible in msvc2010?
I recently had a hard time adding a x64 platform to msvc2010 and now when I want to compile, I get these error messages:
1>src\CarClass.cpp(130): error C2220: warning treated as error - no 'object' file generated
1>src\CarClass.cpp(130): warning C4267: 'return' : conversion from 'size_t' to 'int', possible loss of data
P.S. I will look deeper into the code and try to google the best out of what I have right now.
The issue is that your warnings are treated as errors. If you want to change this, do this:
Project -> Properties -> C/C++ -> General
and make sure that Treat Warnings as Errors is set to No.
If you want to go further and address the warning, you should post the line of code that produces the warning and then further help can be given.
I encounter the invalid conversion from 'const char*' to 'char* while compiling some code on a newer RHEL host.
The error I encounter comes from an external library that I'm including that ideally I'd not like to change and I'm aware that ideally the correct solution is to fix the error in the .h file in the external project which throws this error.
However, I was wondering if there's a compiler flag that I can pass in to ignore this error or convert it to a warning for a period of time until this error is fixed by the owner of the library?
Thank you
You could consider using -isystem /path/to/your/libs/headers to suppress all warnings from all include files in the given directory (unless you then use -Wsystem-headers to show them anyways).
And then you would use :
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-fpermissive"
#include <yourlibrary>
#pragma GCC diagnostic pop
To turn that error into a warning, however this is a bit of a hack and may hide or introduce bugs.
The clean solution would be to actually fix the warning of course, but that doesn't seem to be possible.
Trying to compile this old VC++ 6.0 program in VC++ 2010. This ATL/WTL stuff is giving me lots of problems. I downloaded and have linked to the latest WTL (as far as I know) wtl71.
I am getting compile errors in atlmisc.h:
atlmisc.h(1159): error C2440: 'return' : cannot convert from 'const char *' to 'TCHAR *'
I've searched the 'net, and the answers that come up call for modifying the stock MS atlmisc.h file!
Am I missing something here? What do I need to do to get this to compile?
Most of the time I've seen that error, it's because I've been trying to build a Unicode application. In a Unicode application, the TCHAR* is a short* or wchar_t* rather than a char*.
I'd suggest checking your project settings and making sure that in the project properties, General > Character Set is set to Use Multi-Byte Character Set.