I have an old code, but using Visual Studio Community 2017 had no problem to compile it. Yesterday, I updated to Visual Studio Community 2019 and I opened the old .vxproj file, but I got tens of errors like this while compiling include file limits:
limits(900,39): error C3615: constexpr function 'std::numeric_limits::quiet_NaN' cannot result in a constant expression
limits(901,30): message : failure was caused by call of undefined function or one not declared 'constexpr'
I guess the problem may be with the old .vxproj file, but I have no idea how can I fix it without creating a new project form scatch. Any help would be appreciated.
I have found the problem. There was a few preprocessor directives which caused the problem. After removig them I was able to compile:
__builtin_huge_val()=HUGE_VAL
__builtin_huge_valf()=HUGE_VALF
__builtin_nan=nan
__builtin_nanf=nanf
__builtin_nans=nan
__builtin_nansf=nanf
__is_assignable=__is_trivially_assignable
Once I have tried the Intel compiler in Visual Studio, it required these settings, but it seems I forgot to remove them.
I have decided not to delete this post, but answer my own question. It may be useful for someone with a similar problem, or if you want to make fun of your colleague :-) It took me a very long time to find out what the problem was.
Related
I know a fair amount of Java and Eclipse IDE, but am new to Visual Studio and C++. In Eclipse/Java, if you use a predefined class, Eclipse helpfully suggests the appropriate header file to include for the code to compile. Wondering if Visual Studio has similar functionality.
For example every time I use a code sample from the web, I spend a lot of time Googling which header files to include so the code will compile. My current challenge: I'm writing a small utility that reads filenames in a directory into an array for batch renaming. For this, I'm using following code fragment:
DIR* dir;
struct dirent* dirEntry;
dirEntry = readdir(dir);
Visual Studio is giving the error message: "DIR" is unidentified. "readdir" is unidentified.Is there an efficient way to locate the appropriate header files for C++ code fragments to resolve error messages like these? Thanks.
I tested this feature in vs2019 community 16.3.6 and it works. When you hover the mouse at the location of an error, you can see an error light bulb. And click the drop-down arrow next to the error bulb to add missing #include.
You can also press Alt+Enter.
As mentioned in some answers above, Visual Studio has started offering some suggestions for header files. But as of this writing, some VS suggestions lead to other error messages. E.g. I just used getline(). VS gave error message: Identifier "getline" is unidentified. It suggested I add using namespace std::basic_istream; to my code. But this was not applicable to my code and produced additional error messages.
After stumbling around, I found a very simple solution: Visit the C++ reference website. There I searched for getline and found the header information at the following link: getline(). To fix the error, I needed to #include <string>.
I'm a total newbie when it comes to Boost Asio. I've played around with callbacks and everything worked well. However, now I'm trying to switch to coroutines and I'm facing a problem with co_await. Visual Studio 2017 Community edition says "this co_await expression requires a suitable "await_ready" function and none was found".
The code I'm using is the author's examples on Boost Asio website. Link:
https://www.boost.org/doc/libs/1_69_0/doc/html/boost_asio/example/cpp17/coroutines_ts/echo_server.cpp
The only modification I made to the code is #define BOOST_ASIO_HAS_CO_AWAIT at the very first line of the file.
Why am I getting this error "this co_await expression requires a suitable "await_ready" function and none was found" on every occurrence of co_await? The author's examples should work without any problems, right? Am I missing an #include or something?
Any help greatly appreciated.
Thank you Lightness Races in Orbit for suggesting to try a compiler switch, that was the main problem, although I had a few others. If anyone encounters a similar problem, these are the steps I took:
Move #define BOOST_ASIO_HAS_CO_AWAIT to the header file, in my case pch.h (dumb mistake)
Add /await switch to Project Properties > C/C++ > Command Line > Additional Options.
At this point, everything compiled without errors. However, the co_await remains underlined in red because:
Intellisense compiler has not caught up with MSVC compiler yet.
Source: https://blogs.msdn.microsoft.com/vcblog/2017/05/19/using-c-coroutines-with-boost-c-libraries/
While compiling on x64 plattform I am getting following error:
c:\codavs05\hpsw-sc\ovpacc\tools\codaaccesstest\coda_access.cpp(1572): fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'f:\dd\vctools\compiler\utc\src\p2\sizeopt.c', line 55)
To work around this problem, try simplifying or changing the program near the locations listed above.
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
------ Build started: Project: asyncexample, Configuration: Release Win32 ------
If I change settings to preprocessor file (Yes) i am not getting any error.
About my environment: Upgrading Microsoft Visual Studio 2005 to 2010
Please help.
I have had this problem with VS2015 while building locally in Windows.
In order to solve it, I deleted my build folder (Output Directory as seen in Properties/General) and rebuilt the project.
This always seems to help when strange things happen during the build.
I’ve encountered this error many times in VC++. Do the following steps. They’ve sometimes helped me with this issue:
Take a look at the exact location, pointed out by compiler error.
Find any external types or classes used there at that location.
Change the order of “include path” of those files found in step 2 and rebuild the solution.
I hope that help !!!!
I am getting same error with VC2012. Setting up the project properties Optimization to Disabled (/Od) resolved the issue.
In my solution, i've removed output dll file of the project, and I've made project rebuild.
I encountered the same error and spent quite a bit of time hunting for the problem. Finally I discovered that function that the error was pointing to had an infinite while loop. Fixed that and the error went away.
In my case was the use of a static lambda function with a QStringList argument. If I commented the regions where the QStringList was used the file compiled, otherwise the compiler reported the C1001 error. Changing the lambda function to non-static solved the problem (obviously other options could have been to use a global function within an anonymous namespace or a static private method of the class).
I got this error using boost library with VS2017. Cleaning the solution and rebuilding it, solved the problem.
I also had this problem while upgrading from VS2008 to VS2010.
To fix, I have to install a VS2008 patch (KB976656).
Maybe there is a similar patch for VS2005 ?
I got the same error, but with a different file referenced in the error message, on a VS 2015 / x64 / Win7 build. In my case the file was main.cpp. Fixing it for me was as easy as doing a rebuild all (and finding something else to do while the million plus lines of code got processed).
Update: it turns out the root cause is my hard drive is failing. After other symptoms prompted me to run chkdsk, I discovered that most of the bad sectors that were replaced were in .obj, .pdb, and other compiler-generated files.
I got this one with code during refactoring with a lack of care (and with templates, it case that was what made an ICE rather than a normal compile time error)
Simplified code:
void myFunction() {
using std::is_same_v;
for (auto i ...) {
myOtherFunction(..., i);
}
}
void myOtherFunction(..., size_t idx) {
// no statement using std::is_same_v;
if constexpr (is_same_v<T, char>) {
...
}
}
I had this error when I was compiling to a x64 target.
Changing to x86 let me compile the program.
Sometimes helps reordering the code. I had once this error in Visual Studio 2013 and this was only solved by reordering the members of the class (I had an enum member, few strings members and some more enum members of the same enum class. It only compiled after I've put the enum members first).
In my case, this was causing the problem:
std::count_if(data.cbegin(), data.cend(), [](const auto& el) { return el.t == t; });
Changing auto to the explicit type fixed the problem.
Had similar problem with Visual Studio 2017 after switching to C++17:
boost/mpl/aux_/preprocessed/plain/full_lambda.hpp(203): fatal error C1001: An internal error has occurred in the compiler.
1>(compiler file 'msc1.cpp', line 1518)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
Solved by using Visual Studio 2019.
I first encountered this problem when i was trying to allocate memory to a char* using new char['size']{'text'}, but removing the braces and the text between them solved my problem (just new char['size'];)
Another fix on Windows 10 if you have WSL installed is to disable LxssManager service and reboot the PC.
I just started programming, but I keep on getting problems with headers and stuff.
So, whenever I try and run the code
// ConsoleApplication4.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include "std_lib_facilities.h"
int main()
{
return 0;
}
I get this warning saying
Unable to start program 'C:\Users\Gebruiker\documents\visual studio 2015\Projects\ConsoleApplication4\Debug\ConsoleApplication4.exe'.
The system cannot find file specified.
Additionally, the Build outputs:
1>------ Build started: Project: ConsoleApplication4, Configuration: Debug Win32 ------
1>ConsoleApplication4.cpp
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\hash_map(17): error C2338: <hash_map> is deprecated and will be REMOVED. Please use <unordered_map>. You can define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS to acknowledge that you have received this warning.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========_
As you might've noticed, I'm following Bjarne Stroustrup's book on this, and he doesn't specify how to deal with this at all.
Anyways, the std_lib_facilities.h header is in the same folder as ConsoleApplication.cpp, just as he tells me to do.
I don't actually think this has anything to do with this program in particular, since I face this problem with all the projects I make.
Oh yes, I have to say that I've checked multiple related questions to this, but the questions didn't match mine.
I also tried to #include "../std_lib_facilities.h" and #include "../../std_lib_facilities.h", with no results.(Same with stdafx.h) I've tried "building" the program, but I don't actually know what that does, and if I should build the solution or the cpp, and when to debug....
The answer surely isn't in the book, since I've continued on to chapter 8, not doing the exercises because I cannot get the thing to work.
(Please also tell me if I messed something up in this question, i.e. that I need to talk less, give more details or something)
Here is how to remove a deprecation error:
How to fix "<hash_map> is deprecated and will be REMOVED. Please use <unordered_map>"?
If it still does not run, just go to the project directory and remove all Debug\Release folders Visual Studio creates after you run with Debug\Release configuration. Usually works for me.
Try creating "new project" / C++ console application; with your code and without any include statements. - Peter K
This fixed the problem for me, and I basically just copy-pasted the code and it worked.
I also had the hash_map error, because it is no longer supported in MSVS 2017.
This especially happens since one often still finds the old header off of Bjarne Stroustrup's website. Here is the link to the new header provided by Baum Mit Augen (Stroustrup's updated version)
If you're not using the header provided by Bjarne Stroustrup but one you made yourself, one you found on the internet or also one provided by a book, follow this tutorial from a previous answer by WindyFields. (Thanks a lot for that) (Be sure to check their answer out if this doesn't fix it)
If you encountered this problem, you probably messed with the settings when making a new project (like me).
This is a condensation of the comments provided by the community, none of these answers are mine.
This is a strange error. When I run my code, I had to update the location of ulldiv.asm via
implementation of unsigned long long division
the line in question matched exactly the one used in the link:http://objectmix.com/c/68732-dynamic-memory-allocation-c.html
tim = (__time64_t)((nt_time.ft_scalar - EPOCH_BIAS) / 10000000i64);
Anyways, the first link gave me the right answer and I relocated ulldiv.asm to C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\crt\src\intel\ulldiv.asm.
Now when I run my code this line gives me trouble
double NOISE_SIGMA = NOISE_DENSITY*sqrt(SYS_CLK_FREQ);
the sqrt function becomes undefined (?). The debugger stops and asks me for the location of sqrt.asm.
You need to find sqrt.asm to view the source for the current call stack frame
This is a similar error that I found in a German website: http://www.c-plusplus.de/forum/324725-full
but it doesn't seem to get resolved there.
I don't understand what's going on. If you need more information regarding the code, let me know. Thank you in advance.
If it makes any difference I step through my code using F11.
While most of the source files for the Visual C++ libraries are included with the Visual Studio installation, some files are not included. Notably, the sources for the math library are not included.
The fact that the debugger cannot automatically find ulldiv.asm is a bug; this has been fixed in Visual Studio "14" (I think the fix was present in CTP1; I know for sure the fix is present in CTP3 which was released today).