My program compiles fine, but Netbeans tells me "Unable to resolve identifier to_string."
I tried everything in "Netbeans 7.2 shows "Unable to resolve identifier" , although build is successful" and I set the "C++ standard" to "C++11" in the code assistance options.
This is the only function giving this problem so far. It is however also the first C++11 feature I am using, which leads me to believe it has something to do with Netbeans not understanding that I am using C++11, although I specify it explicitly in the code assistance menu.
Minimal example:
#include <string>
int main() {
std::to_string(1);
}
EDIT: the same problem arises where using nullptr
EDIT2: I suddenly realized it might be important to mention that I do not use a generated Makefile, but SCons.
I know this question is seven months old but since it came up as the second result to a google search I'll tell the answer I came up with. For Netbeans at least. Go to your project properties and make sure you have you "C Compiler"->"C Standard" set to C11, and your "C++ compiler"->"C++ Standard" set to C++11. You have to set BOTH or it will still give false errors!
This will solve the problem:
Right click on "Project".
Select "Code Assistance".
Clean C/C++ cache.
Restart IDE.
Autocomplete and sometimes even syntax highlighting are always faulty with C++. The more you go in depth with C++ and C++11, the more Eclipse and Netbeans will start underlining everything with a red wavy line. Some of my (correct and perfectly compiling) programs are a huge red wavy line. I suggest you disable error markers altogether and you keep autocomplete, but in many cases it just won't work and you have to make the best of it.
I had the same situation. This was occurred because I used .c file instead of .cpp
for Netbeans 8.2 (on Linux) only the following worked for me: Tools -> Options -> Code Assistance -> Macro Definitions:
change:__cplusplus=199711L
to:__cplusplus=201402L
for C++14
or to __cplusplus=201103L
for C++11
I did all the above but what did the trick for me was recognizing that the Makefile had g++ rather than g++ -std=c++11.
To resolve c++17 related 'Unable to resolve identifier' in latest netbeans 8.2 or 9 version, one may need to set the macro definition __cplusplus=201703L as the default C++14 standard macro definition unable to resolve those unexpected error messages appeared in the editor.
Related
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/
I am running Cygwin on windows 8, attempting to compile the source code for a game I would like to mod. Unfortunately I am running into some errors while building involving the fileno function. After doing some googling It seems like the problem might have to do with c++11 support (I'm not really sure what this means). Most of the solutions people have found involve adding some option like -std=c++0x or -std=c++11 when compiling, but my attempts to add the options into the makefile have been unsuccessful, and I don't know if that's whats causing the problem anyways. I'll include the code snippet that's throwing the error and a link to the makefile as it is quite large. Any advice you could give me would be great.
code that throws error:
time_t file_modtime(FILE *f)
{
struct stat filestat;
if (fstat(fileno(f), &filestat))
return 0;
return filestat.st_mtime;
}
Link to Makefile
it is being hosted on github
EDIT: After getting some advice I poked around the makefile and found five instances where the -std option was used, playing around with them hasn't changed anything. Is the problem with my Cygwin configuration? I installed the packages I was told I would need in the installation guide for the game I am building.
Changing the -std=c*** in your makefile to -std=gnu++0x should fix your problem.
If you don't know what c++11 is you're most likely not using it anyway.
Also if you need c++11 support you can also do: -std=gnu++11 instead of -std=gnu++0x
For windows...
fileno() is deprecated: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-fileno?view=vs-2017
use _fileno() instead: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fileno?view=vs-2017
I am trying to run an old project in Xcode, which is written in C++, but I get several errors with boost library.
The first was this issue, but the second comment provided a nice workaround and it worked.
Then I did a clean build again and now I am getting the error, which is in the title, namely:
Unknown type name 'reference_type_of_temporary_wrapper'
I can't find any solution for this issue. Anybody has any suggestions?
I am using:
Mac OSX 10.10
Xcode Version 6.1 (in the project C++ language dialect and C++ standard library are set to Compiler default)
Boost 1.56
There is already an accepted answer but it bypasses the issue, doesn't really fix it so I thought I would respond with a more up-to-date answer for those searching.
In more recent versions of Boost, there are preprocessor definitions that you can pass to your app that will disable certain C++11 features. For the particular error in this post, passing this to the compiler fixes the issue (GCC here):
-DBOOST_NO_CXX11_REF_QUALIFIERS
There is a nice long list on this SO question of all the C++11-related Boost preprocessor definitions that can be set.
I managed to pass through this error, with a temporary workaround. It is not the nicest solution probably, but works...
What I did is just simply commented out these lines from boost/optional.hpp:
// reference_type_of_temporary_wrapper operator *() && { return boost::move(this->get()) ; }
// reference_type_of_temporary_wrapper value() &&
// {
// if (this->is_initialized())
// return boost::move(this->get()) ;
// else
// throw_exception(bad_optional_access());
// }
How can my program compile successfully but eclipse shows me "Semantic Errors" and how could I get rid of those errors?
The error messages I have are the following
Method 'c_str' could not be resolved (this happens also for compare and size on strings)
Here an example:
std::string someotherstring = "test";
std::string name = someotherstring.c_str();
The problem here is that it also creates follow up errors which seem all to be not true, my software compiles and runs as intended and even uses the "c_str()" returns to process messages. It seems only to be a display issue in Eclipse.
I have searched now for hours, tried to use a custom indexer but for some reason it won't go away. Maybe someone else has a good idea what to do here as Google spits out nothing about this specific problem. (I have even tried to use different C++11 standard flags as I thought it might had an impact)
I had the same problem. Solved by simply run a index -> rebuild. You can find that by clicking on the project main folder with the right button.
Cheers
If you're building your projects using mingw and using C++11, you can not use the default dialect option of -std=c++0x.
Click on 'GCC C++ Compiler' and in the Command: textbox, enter -std=gnu++0x after the g++
I can get rid of the warnings in the build log by adding -std=c++0x to "other c++ flags", but they still show up in the side pane. I'm guessing that the other flags are not being passed to clang or whatever is responsible for parsing code for the gui...
Any ideas?
Update:
The warnings have mostly disappeared, but I'm not sure why. And every time I think they're gone, I get a few again. I suspect that forcing a build of every project in the workspace has some effect, but I'm really at a loss.
In any case, modifying "other c++ flags" does seem to affect the GUI warnings, contrary to my assumption when I asked this question. But it takes time. Ahh, Xcode.
Use a pragma instead of a command line switch, as described in the answer to "Is there a way to suppress warnings in Xcode?"