Answer the question
In order to leave comments, you need to log in
Why do linker errors occur in VS in c++?
There is a memory manager for which I need to write tests. The fact is that I connected the manager myself: I added it to the project and wrote the pragma, but still, for reasons I don’t understand, linker errors like
Error 4 error LNK2019: link to an unresolved external symbol "public: class std:: basic_string, class std ::allocator > __thiscall Tests::readWriteTest(void)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@ XZ) in the function "void __cdecl readWriteTest(void)" ([email protected]@YAXXZ) E:\MV2010\memoryTester\memoryTester\main.obj memoryTester
What did I do wrong!?
#pragma comment (lib,"Lab1.lib")
#include "Tests.h"
#include "mMemory.h"
#include <string.h>
#include <vector>
using namespace std;
Tests::Tests(){}
string initTest()
{
string str;
for(int n=0; n<12; ++n){
for(int szPage=0; szPage<32; ++szPage){
int retval = _init(n,szPage);
if(n<1 || szPage<1){
if(retval != -1){
str = "ERORR! init is wrong!";
return str;
}
} else{
if(retval != 0){
str = "ERORR! init is wrong!";
return str;
}
}
}
}
str = "You are init your manager.Our congratulations";
return str;
}
string mallocTest(){
string str;
for(int n=1; n<12; ++n){
for(int szPage=0; szPage<32; ++szPage){
vector<int> freeSize(n,szPage);
int retval = _init(n,szPage);
int bufCount = rand()%32;
VA *ptr = new VA[bufCount];
int *bufSize = new int[bufCount];
char **bufValue = new char *[bufCount];
for(int i=0;i<bufCount; ++i){
bufSize[i] = rand()%32;
bufValue[i] = new char[bufSize[i]];
for(int j=0; j<bufSize[i];++j){
bufValue[i][j] = '0' + rand()%10;
}
retval = _malloc(&ptr[i],bufSize[i]);
if(bufSize[i]<1 || (bufSize[i]>szPage)){
if(retval != -1){
str = "ERROR: malloc return code must be -1 but was " + retval;
return str;
}
} else{
bool area = false;
int freeS = freeSize.size();
for(int p=0;p<freeS;++p){
if(freeSize[p]>=bufSize[i]){
freeSize[p] = bufSize[i];
area = true;
break;
}
} if(area){
if(retval != 0){
str = "ERROR: malloc return code must be 0 but was " + retval;
return str;
}
} else{
if(retval != -2){
str = "ERROR: malloc return code must be -2 but was " + retval;
return str;
}
}
}
}
}
}
str = "Our congratulations testing malloc is OK";
return str;
}
string freeTest(){
for(int n=1;n<12;++n){
for(int szPage=1;szPage<32;++szPage){
string str;
_init(n,szPage);
int retval = _free(NULL);
if(retval != -1){
str = "ERROR: free return code must be -1 but was " + retval;
return str;
}
for(int i=0;i<n*2;++i){
VA buf;
retval = _malloc(&buf,szPage);
if(retval ==-2)
{return "ERROR: not enough memory for malloc"; }
retval = _free(buf);
if(retval != 0)
{return "ERROR: free return code must be 0 but was " + retval;}
}
}
}
return "Our congratulations testing free is successful";
}
string readWriteTest(){
for(int n=1; n<12; ++n){
for(int szPage=4;szPage<32;++szPage){
VA buf;
int retval;
_malloc(&buf,szPage/2);
string str = "";
for(int i=0;i<szPage;++i){
str += "@";
// l +="%";
}
char *ch = new char[str.length()];
strcpy(ch,str.c_str());
int value = _write(buf,ch,szPage/2);
if(value == 1)
retval = _read(NULL,&buf,szPage);
if(retval != -1){
return "ERROR: read return code must be -1 but was " + retval;
}
retval = _read(buf,NULL,szPage);
if(retval != -1){
return "ERROR: read return code must be -1 but was " + retval;
}
retval = _read(buf,&buf,szPage+1);
if(retval != -1){
return "ERROR: malloc return code must be -1 but was " + retval;
}
//VA buff;
//manager._malloc(&buff,szPage/2);
//char *chr = new char[l.length()];
//strcpy(chr,l.c_str());
//manager._write(buff,chr,szPage/2);
//manager._read(buf,buff,szPage/4);
_free(buf);
}
}
return "Congratulations! It's successful work";
}
Tests::~Tests(void)
{}
<code lang="cpp">
#pragma once
/*
*/
#include <iostream>
using namespace std;
class Tests
{
private:
public:
Tests();
string initTest();
string mallocTest();
string freeTest();
string readWriteTest();
~Tests();
};
<code lang="cpp">
#pragma once
/*
*/
#include <iostream>
using namespace std;
class Tests
{
private:
public:
Tests();
string initTest();
string mallocTest();
string freeTest();
string readWriteTest();
~Tests();
};
</code>
Answer the question
In order to leave comments, you need to log in
Judging by this support.microsoft.com/kb/153901/ru , you have a new compiler, and the pragma syntax is old.
You need to replace the pragma with
#pragma comment (lib,"")
Also, something like this happens if different versions of the compiler are used. Those. part of the project or standard libs are compiled by one version of the compiler, and the second part by another, or in general by another compiler.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question