Function 'sqrt' could not be resolved - Eclipse for Windows - c++

So it's my first question here, I'll try to explain correctly.
I am using Eclipse for Windows, and have installed the MinGW package, so I have an easy access to some basic includes.
The fact is, I included the cmath library, as follows:
#include <cmath>
Nothing exceptional, Eclipse doesn't give me any errors nor warnings. But there is a line in which I use sqrt(), as follows:
xone = (-b - sqrt(delta))/(2*a);
Of course, I defined xone, a, b, and delta previously. But the problem is Eclipse keeps giving me the error :
Description : Function 'sqrt' could not be resolved | Semantic Error
I researched for quite a while, but all the answers I could find were about checking whether or not cmath was included, which I did. if someone could help me... Thanks !

The functions in <cmath> reside in the std namespace. If you need to use it you can use std::sqrt or using std::sqrt;.

Related

typeinfo pragma visibility error

I'm trying to use shared_ptr from std:: in c++ 11 so I'm including which apparently uses typeinfo. The problem is that I'm getting the error bellow.
In file included from /usr/include/c++/4.8/memory:71:0,
from /home/dev/openclTest/modules/Quant.cpp:10:
/usr/include/c++/4.8/typeinfo:39:37: error: expected ‘}’ before end of line
#pragma GCC visibility push(default)
From what it sounds like, this is a known bug listed here:
https://lists.debian.org/debian-gcc/2007/09/msg00497.html
Anyway, I was hoping I didn't have to use boosts library, so if there's a quick fix anyone knows about, please let me know. I'm using cmake and g++ to build the project.
Thanks!
I just had a similar issue with GCC 4.9.2. It seems to be the common error message in case you forget some braces in a file included prior to typeinfo.
I did not find the code to exactly reproduce the message but got something very similar using this minimal test:
test.cpp:
{
#include <typeinfo>
int main() {}
I guess it is likely the same error as yours as it happens in very different GCC versions. In case it really is the same issue, check your other includes.

stoi() CodeBlocks not working

I am using codeblocks and i can't make stoi() function work. I read other questions regarding this issue but I couldn't solve it. I checked C+11, I am using namespace std and I have the string header. I don't know how can I solve this problem.
error: 'stoi' was not declared in this scope
found the answer on almost the same question here:
"It seems your MinGW needs a patch: Enabling string conversion functions in MinGW"
From this link you can download a .zip, than follow the instructions.
This patch enables the following list of C++11 functions and
templates in the std namespace:
stoi, stol, stoul, stoll, stof, stod, stold, to_string, to_wstring
Attention, maybe you will haver errors with later versions, after using the copy/paste:
As Conduit said here:
"People should note that direct replacement of the files is not guaranteed to be safe on versions later than MinGW GCC 4.7 - use the pastebin snippets, open the files, and comment/add to the existing files. Applied as such, this still works fine on MinGW GCC 4.8.1 afai"
I would use atoi on the str.data() returned value, since it is supported in all compiler versions.
Use
#include <string>
That should work. For reference: C++11 standard plus minor editorial changes.
Or perhaps you are forgetting to prefix with std::?
A workaround is calling .c_str() and using the <cstdlib> or <stdlib.h> functions.

What can cause ambiguous symbol errors on one computer and not another?

I'm using Visual Studio 2010 to work on C++ code. The project and all its contents have been written by someone else, and copied onto a shared drive. When the creator builds it on his computer, it works fine. When I try to build the solution, I get a whole bunch of these errors
error C2872: '<lambda0>' : ambiguous symbol could be
'[File].cpp(66) : anonymous-namespace'::<lambda0>' or
'[Different file].h(549) : `anonymous-namespace'::<lambda0>'.
Here's an example of a line which is said to be in error:
std::pair<int, std::pair<int, Point>> b) -> bool { return (a.second.second < b.second.second ); });
It seems like the error always occurs with a line which ends in '});'. The full code is rather enormous to show here, and it works on other computers, so presumably it's a problem with my settings or something. Can anybody hazard a guess as to what they may be?
Not sure if you've seen this or not but according to MSDN page for that compiler error:
C2872 can occur if a header file includes a using Directive (C++), and a subsequent header file is #include'd and contains a type that is also in the namespace specified in the using directive. Specify a using directive only after all your header files are specified with #include.
MSDN Page
I have had the same issue withe ambiguous symbol problem. For me, it turns out that I was using two namespaces which have the same function but obviously different definitions. I have to stop using one of the namespaces and this solve the issue.
As an example:
using namespace cv;
using namespace boost::accumulator;
accumulator_set<double, stats<tag::mean, tag::variance> > acc;
double meanval = mean (acc);
This will through a compilation error: error C2872: 'mean' : ambiguous symbol This is because both namespaces cv and boost::accumulator have the same function "mean"
I hope this helps
I have had the same issue
Installing VS2010 SP1 fixed the ambiguous anonymous-namespace'::<lambda0> issue for me. VS2010 without the SP1 has problems with lambdas.

How can I make Keil RealView ARM MDK (for Cortex-M3) work with BOTH retargeting(to USART) and STL?

I've been searching for a workaround for days. So far no luck.
What I use:
STM32F103VET6
J-Link
RealView MDK-ARM v4.12
Both C and C++ code in my program
Before I included STL in my code, everything works fine. I can retarget printf() and scanf() to USART without a problem. This is done by including Retarget.c that came with RV-MDK and writing my own sendchar() and getkey(). Retarget.c has a line that says #pragma import(__use_no_semihosting_swi) which demands the linker to use the retargeting version of <cstdio>, instead invoking the semihosting implementation.
But when I started to #include <deque> and deque<int> buffer;, it doesn't work anymore. It seems that the linker had decided that <deque> depends on the the semihosting <cstdio>, which conflicts with the retargeting code I wrote just now.
What I tried and failed:
Get rid of __no_semihosting_swi and instead try to override _sys_open(). It doesn't work because the semihosting <cstdio> depends on an object file which already exports this symbol.
Use $super$$ and $sub$$ syntax suggested here (I think I've tried everything they provided!)
Use "MicroLIB". It's EPIC FAIL.
Digging into the supplied STL headers. I found NO reference to any stdio. And, since I can #include <cstdio> and still have retargeting, I don't think even an reference would make any difference.
I suspect the solution has something to do with directing the linker, but so far I haven't figured out... This is getting so frustrating!

Unresolved externals error during compilation

I am getting two unresolved externals error while trying to compile the following c++ program in Visual Studio 2010-
http://codepad.org/5ZS4gtfP
I tried cross checking everything but cant seem to find the problem. Can someone plz compile it in VS 2010 and try to find out the solution?
For a start, conio.h is not standard C or C++ - it tends to be found in code written for the Turbo C/C++ products, a particular favourite of Indian universities.
And they invariably use it just so they can call getch when there's a perfectly adequate getchar in the standard :-)
As to the index variable, it's probably already defined in one of the headers.
Line 18: error: conio.h: No such file or directory:
Try to include <conio.h> instead of "conio.h".
Line 25: error: 'unsigned int index' redeclared as different kind of symbol:
It could be that one of the headers you're including already declares index. Try to rename it to see the difference - or better yet don't use a global variable at all.