Unresolved external symbol __report_rangecheckfailure - c++

I have this simple program which creates a prompt for password. I have both Visual Studio 2012 and 2010 installed. It works on 2010, but on 2012 I get this error: unresolved external symbol __report_rangecheckfailure referenced in function main. Also, I modified the code by moving everything from main to another function. That works on both versions.
There must be some problems with some library, but which one and how do I solve it? Thanks.
#include <conio.h>
#include <iostream>
using namespace std;
int main()
{
int key, i;
char pwd[64];
printf("Enter passphrase: ");
key=getch();
i=0;
while (key!=13)
{
cout<<"*";
pwd[i++]=key;
key=getch();
}
pwd[i++]='\0';
cout<<strlen(pwd)<<endl;
for (i=0; i<strlen(pwd); i++)
cout<<pwd[i]<<endl;
getch();
}

If the project was started in VS 2010, then VS will use MS VS 10.0 C libs. If you start it with 2012, it will use vers. 11.0 libs. VS 2012 will call __report_rangecheckfailure when compiling, but it is not in the same place in version 10 as it is in 11. You can update your project to VS 2012 in the main project menu, or disable the buffer security check.
Further Reading on VS /gs compiler option

Related

Simple Visual Studio console application does not start

I installed Visual Studio 2013 on my Windows 10 machine. To test the installation I wrote a simple program in C++:
#include <iostream>
using namespace std;
int main(){
cout << "Size of char is: " << sizeof(char);
cin.get();
return 0;
}
It's embarrassing to post such a simple code here but the problem is as follows. The build process runs without errors or warnings. But when I start the program via Debug-Button, Visual Studio freezes. I also tried starting the .exe in cmd. The result is a blinking cursor in an empty line with no further reaction from the console.
Can somebody tell me what's wrong? The Project Type in Visual Studio is empty visual c++ project.
Finally it works. As Peter M mentioned in his comment, the VS/Avast issue was the problem.

how to make armadillo-5.200.1 (+openblas or lapacke) work with visual studio 2010?

I have been trying to make armadillo-5.200.1 and openblas (or lapacke) work with visual studio 2010 since a week now and I still have several unresolved external symbols errors with functions from the blas and lapack libraries.
First, I tried to install openblas from pre-built binaries for windows and set up a new project and test it with the sample code below:
#include <cblas.h>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
blasint n = 10;
blasint in_x =1;
blasint in_y =1;
std::vector<double> x(n);
std::vector<double> y(n);
double alpha = 10;
std::fill(x.begin(),x.end(),1.0);
std::fill(y.begin(),y.end(),2.0);
cblas_daxpy( n, alpha, &x[0], in_x, &y[0], in_y);
//Print y
for(int j=0;j<n;j++)
std::cout << y[j] << "\t";
std::cout << std::endl;
}
I got an unresolved external symbol « cblas_daxpy » error. I tried to build the same project with code::blocks and got the same error.
I downloaded and set up msys to be able to compile the source I downloaded on github (https://github.com/xianyi/Openblas) and tried to make it work both on code::blocks and visual studio, but I still got the same errors.
Then I tried on my own laptop, because it has Linux ubuntu 14.04 LTS. So, I cloned the github and compiled the sources and tried to set it up in another code::blocks project and I test it using the same sample code and got undefined reference errors concerning functions such as pthread_create and pthread_join.
I also tried to compile lapacke sources with cmake, following the instructions of the following page : https://icl.cs.utk.edu/lapack-for-windows/lapack/. I used the example, to test, the project built correctly, but when I execute the programm I have an pop-up window message saying that the liblapacke.dll can't be find.
To use openblas with visual studio, I followed the instructions about third-party library:
add the location of the header files to "C/C++->Additional Include Directories"
add the .lib files to the "Linker->Input->Additional Dependencies"
add the location of the .lib files to "Linker->General->Additional Library Directories"
I need to make this work at least with windows 7 and better with visual studio 2010, because we use it at work.
you should copy dll file to system32 direction or Debug or Release folder of y

function cannot access 'xxx::xxx::operator <<'

I have some code like:
namespace xxx {
namespace xxx {
struct local {
static void xxxxx(....) {
std::cout << "prints..........." <<std::endl;
}
}
}}
And I get errors as the title stated: "function cannot access 'xxx::xxx::operator <<'"
I created the MSVC project with visual studio 2005. While when I open the project in visual studio 2010, everyting works fine. But I need it working visual studio 2005, what might be the reason for it?
When I open it from Visual Studio 2010, I didn't change anything, it works directly.
And I know it is working with gcc as well. So something I can do for the msvc project to make it working without changing the code?

xDispatch LNK2019 Linker error Unresolved Externals

I realise this i mighty popular question, but all of the other posts seem to follow the same idea. That the include, lib and bin folder need to be correctly configured. I believe my settings are correct, but i am still getting the LNK2019 error. What am i doing wrong?
Using Visual Studio 2012
I am getting the infamous LNK2019 error. Many posts of this issue seem to think it is a linker issue. I am using a library with lib and dll files. The project folder has an include, bin and lib folder that need to be configured in the project.
Install instructions are here.....
http://opensource.mlba-team.de/xdispatch/docs/current/tutorial.html
However, this is clearly a linker issue as it occurs in other libraries of a similar type. I have followed the instructions for other posts and i'm still a bit lost. I believe this should be correct, but i have tried virtually every possible combination. Don't get it.
My Project Configurations
C++ -> General -> Additional Include Directories.
C:\Users\Daniel\Documents\Visual Studio 2012\Projects\LibDispatchTest\xdispatch_0.7.2_Visual Studio 10_i386\include;%(AdditionalIncludeDirectories)
Linker -> General -> Additional Library Directories
C:\Users\Daniel\Documents\Visual Studio 2012\Projects\LibDispatchTest\xdispatch_0.7.2_Visual Studio 10_i386\lib;%(AdditionalLibraryDirectories)
Linker -> Input -> Additional Dependancies:
.....uuid.lib;odbc32.lib;odbccp32.lib;xdispatch.lib;%(AdditionalDependencies)
Environment Variables.
I have the PATH variable set.
C:\Chocolatey\bin;C:\Users\Daniel\Documents\Visual Studio 2012\Projects\VisionBase\xdispatch_0.7.2_Visual Studio 10_i386\bin;
The error messages are:
error LNK2019: unresolved external symbol "_declspec(dllimport) public: void __thiscall xdispatch::queue::async(class std::function<void __cdecl(void)> const &)" (__imp?async#queue#xdispatch##QAEXABV?$function#$$A6AXXZ#std###Z) referenced in function "void __cdecl some_function(void)" (?some_function##YAXXZ) c:\Users\Daniel\documents\visual studio 2012\Projects\LibDispatchTest\LibDispatchTest\main.obj LibDispatchTest
error LNK1120: 1 unresolved externals c:\users\daniel\documents\visual studio 2012\Projects\LibDispatchTest\Debug\LibDispatchTest.exe 1 1 LibDispatchTest
Seriously, am totally lost and i do not see what i am doing wrong here.
EDIT 1
This is similar to a sample from the above link, but modified to just couNT 1000000^2 and print some stuff. We just want to be able to compile and run this sample and i can correct my larger project exhibiting this issue. This project was made fresh with the simplest code that is representative of what i need to get working. Both this sample and my other project have this problem and produce the same error.
#include <xdispatch/dispatch>
#include <vector>
#include <cmath>
class SomeData {
public:
std::vector<double> a;
std::vector<double> b;
std::vector<double> c;
std::vector<double> results;
};
void do_calculations(SomeData* sd){
// our output will go in here
sd->results = std::vector<double>(sd->a.size());
// the calculation - running on one thread only
for(unsigned int i = 0; i < 1000000; i++){
sd->results[i] = 0;
for(unsigned int j = 0; j < 10000000; j++){
for(unsigned int z = 0; z < sd->c.size(); z++){
std::cout << i << " " << j << std::endl;
}
}
} }
/* This function is getting called from your main thread also powering the user interface */
void some_function() {
SomeData* sd = new SomeData();
xdispatch::global_queue().async(${
// execute the heavy code
do_calculations(sd);
}); }
int main() {
some_function();
return 0; }
Is anyone able to help?
The binaries you used where built with and for MS Visual Studio 2010. Since then the CRT has changed quite a bit and might not be compatible, especially when parts of the STL is used. Because of that I do not recommend to ever use a C++ dll built with VS 2010 for use in VS 2012 or later. It could be that building and linking succeeds but during runtime you experience weird and unexpected issues. In your case even linking won’t work because std::function has changed its signature in the meantime, so lucky enough you already discover those incompatibilities at compile time.
I assume xdispatch will work just fine with VS2012 and maybe even VS2013, however you will need to do your own build for that. All information needed is summarized at [1]. A tarball containing the sources can always be found at [2].
[1] http://opensource.mlba-team.de/xdispatch/docs/current/requirements.html
[2] http://opensource.mlba-team.de/xdispatch/files/

LNK2019 Despite the contents of code (Visual Studio 2013, C++)

I have recently updated to Visual Studio 2013, and to avoid the known problems with uninstalling one of the two programs (I previously used 2010) while the other is installed I uninstalled 2010 before I installed 2013.
Despite what code I place in it, even simple code that is only a few lines, Everything gets this LNK2019 error.
#include<iostream>
using namespace std;
int main()
{
cout << "Testing" << endl;
system("pause");
return 0;
}
Before anyone comments with the "Do not use system("pause")" I know this and I did it purely for simplicity reasons to see if the code would even compile as it would not with any of my longer code either.
Here is a copy of the Error message.
Error 1 error LNK2019: unresolved external symbol WinMain#16 referenced in >function __tmainCRTStartup C:\Users\z49203\Documents\Visual Studio >2013\Projects\JCCNEW\JCCNEW\MSVCRTD.lib(crtexew.obj) JCCNEW
As for extensions in Visual Studio, I have the English version of it with the Japanese language pack. As I need to be able to code using both character sets.
Make your project a Console application not a Window Form one. Otherwise the program needs a WinMain as entry point instead of main.