Unresolved externals error during compilation - c++

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.

Related

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

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;.

Linker error when declaring a function just before calling it

I've got an update function in my game that contains the following code:
void DrawMiniFPSCounter();
DrawMiniFPSCounter();
The DrawMiniFPSCounter() function is declared in a file called miniFPSCounter.cpp, which is part of the build target (I'm using Xcode). When building, I get a linker error saying that the DrawMiniFPSCounter symbol cannot be found. I've tried removing the declaration above and just calling DrawMiniFPSCounter() but that results in a 'symbol not found' error during compilation. Why would the linker have trouble finding this symbol? Is it something to do with the order in which symbols are resolved in the project?
EDIT: I ran the command nm hrMiniFPSCounter.o | grep Draw in my build directory, and got the following output:
00000000 T __Z15DrawMiniCounteriiiii
0002d040 S __Z15DrawMiniCounteriiiii.eh
00000a00 T __Z18DrawMiniFPSCounterv
0002d148 S __Z18DrawMiniFPSCounterv.eh
00000560 t __ZL9DrawDigitiiib
0002d128 s __ZL9DrawDigitiiib.eh
is this normal? Why the extra characters on the end of the function names?
In my experience most common "errors":
Was the file (really) compiled?
Was it (really) linked correctly?
Did you give the function the name you thought you did?
new Namespace issues :)
Are you sure that the miniFPSCounter.cpp file is compiled (/have been incouded in the project in the right way)? I guess what you are experiencing could be caused by a few different things,but in lack of more information I would say: Try to make sure that the cpp file is being compiled (maybe introduce a few syntax errors which would give rise to a compilation error if it is indeed compiled) and when you are sure about that, you can start checking for other stuff (suchas that it is being linked correctly, etc)
Edit: Putting checklist on top.

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.

OpenCV 2.3 with Qt 4.3.7

I have successfully build and ran both Qt 4.3.7 and OpenCV 2.3 with Qt enabled. When I start a window using:
cvNamedWindow( "video", 0 );
I successfully load a full Qt interface! wonderful :)
However!! when I use the command
void callbackButton(int state, void* userdata){
int x;
x=3;
}
cvCreateButton(nameb2,callbackButton,nameb2,CV_CHECKBOX,0);
I get the error message
error LNK2001: unresolved external symbol _cvCreateButton
I don't understand as the Qt interface already has lots of buttons on it? could someone please explain what I am missing from the include that could cause this?
Thanks!
You use the wrong parameters for to call to cvCreateButton. According to the documentation here the signature of the function is
cvCreateButton(const char* button_name CV_DEFAULT(NULL), CvButtonCallback on_change CV_DEFAULT(NULL), void* userdata CV_DEFAULT(NULL), int button_type CV_DEFAULT(CV_PUSH_BUTTON), int initial_button_state CV_DEFAULT(0)
and sample calls are:
cvCreateButton(NULL,callbackButton);
cvCreateButton("button2",callbackButton,NULL,CV_CHECKBOX,0);
cvCreateButton("button3",callbackButton,&value);
cvCreateButton("button5",callbackButton1,NULL,CV_RADIOBOX);
cvCreateButton("button6",callbackButton2,NULL,CV_PUSH_BUTTON,1);
and the declaration of the callback function has to be:
CV_EXTERN_C_FUNCPTR( *CvButtonCallback)(int state, void* userdata));
You get a linking error and not a compiler error because cvCreateButton has extern "C" linkage - which means that parameters cannot be checked at compile time.
I solved this issue by calling the function cv::createButton instead of cvCreateButton (which is if I am correct the way to call methods in OpenCV2).
The third argument must be a void*. Change to:
cvCreateButton(nameb2,callbackButton,NULL,CV_CHECKBOX,0);
and it will work.
Edit
The statement above was given an error.
The third needed argument is a "void *" - this is compatible with anything and thus neither C nor C++ should have a problem with what you were providing. You can not raise a linker error with that.
The only reason a linker error can be raised by coding is when you don't use prototypes (forgot to use the header file) in C++ and then C++ creates a mangled name on its own that wont be part of any library. In such a case the compiler will first tell you with a warning at compile time that you are missing the prototype (for C and C++) - and then the linker will probably raise an error (for c++ only).
If you don't see a prototype warning from the compiler then that is not your problem.
This is a linking error.
Try to add the opencv .lib file (or files) to the project libraries path.
This may help : VS2010 OpenCV.
Edit
Refined problem: Even if adding any OpenCV libary to your project the linking will fail.
Reason: The symbol is often simply not there in the libraries.
Solution: You have to change a few settings and compile them on your own.
See also: openCV 2.2 createButton LNK 2019 error in Visual Studio 2010

Very Mysterious/Random C++ WDK STL 7 Error: iosfwd(202): error C2144: syntax error

I have the following trivial file named Temp.cpp:
#include <string>
int main() { return 0; }
and I'm trying to compile it with the following command-line in the Windows XP Free Build Environment, using WDK 7.1:
cl.exe /Iinc\api\crt\stl70 /Iinc\crt C:\Temp.cpp
and I'm getting really random errors like:
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.207 for 80x86
C:\WinDDK\7600.16385.1\inc\api\crt\stl70\iosfwd(202) :
error C2144: syntax error : 'int' should be preceded by ';'
The error goes away if I use stl60 instead of stl70, but that doesn't solve the problem.
What's the cause of the problem?
Update: I tried uninstalling and installing the WDK again, but nothing changed. :(
Update 2: Okay, apparently the error is screaming out at the header file itself: _SCL_INSECURE_DEPRECATE is the cause. Does anybody know how to turn it off correctly? (If I just comment out the lines, I get a ton more errors regarding a bunch of other macros.)
Found the answer myself, through modifying the headers and guess'n'checking:
I need to have _STL70_ defined.
Which cl.exe are you picking up? If your path happens to have an older (VC6) compiler before the WDK one, you'd expect these errors. VC6 can't compile the STL as shipped with VC7
apparently the error is screaming out at the header file itself: _SCL_INSECURE_DEPRECATE is the cause. Does anybody know how to turn it off correctly?
If you're having problems with _SCL_INSECURE_DEPRECATE, try setting:
/D_SCL_SECURE_NO_DEPRECATE
But given the error message you're seeing it sounds like you're the compiling headers with a a compiler that's older than the headers support (so this might not get you very far anyway).