VS2008 - main.obj : error LNK2019

Hi,

I am new to the forum and fairly new to C++.

I am creating a basic web testing tool that sends HTTP requests, comparing results sent at different times.

Anyway, I am also trying to get into creating header files etc. The program has the following structure among other header and CPP files I got from a sample online somewhere that does the HTTP stuff. I am essentially building a testing framework around it. Anyway here goes...

Header Files:
test.h

Source Files:
test.cpp
main.cpp

test.h
1
2
3
4
5
6
7
8
9
10
11
#ifndef RECORD_H_
#define RECORD_H_

namespace test{

class record {
public:
	static int recordTest(const string test1, const string test2);
};
}
#endif 


test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <string>
#include <vector>
#include <iostream>

using namespace std;

#include <windows.h>
#include <wininet.h>
#include "test.h"
#include "web.h"
#include <fstream>
#include <iostream>
#include <time.h>
#include <sstream>
#include <iostream>
#include <windows.h>

using namespace test;

int recordTest(const string test1, const string test2){

	using namespace openutils;

	char buffR[500000];
	WebForm wf;
	wf.setHost(test2.c_str());
	wf.sendRequest();
	if(wf.getResponse(buffR,sizeof(buffR)-1))
	{
		cout<<"Test recorded: " + test1<<endl;
		string outf_name1 = "c:/httpCheck/exp - " + test1 + ".txt";
		ofstream outf(outf_name1.c_str());
		outf << buffR << endl;
		return(0);
	}else
	{
		cout << "No response from server" << endl;
		exit(1);
	}

}


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <string>
#include <vector>
#include <iostream>

using namespace std;

#include "test.h"
#include <windows.h>
#include <wininet.h>
#include "web.h"

#include <fstream>
#include <iostream>
#include <time.h>
#include <sstream>
#include <iostream>
#include <windows.h>

...

int main()
{
...
			using namespace test;
			record::recordTest(test1, test2);
...
}



When compiling, compilation works but linking fails as follows:

1>main.obj : error LNK2019: unresolved external symbol "public: static int __cdecl test::record::recordTest(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?recordTest@record@test@@SAHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z) referenced in function _main
1>.\Debug/httpCheck.exe : fatal error LNK1120: 1 unresolved externals



I've looked around the web and found different things regarding settings the system / subsystem in the linker options and also adding DDLs to the compiler options but I don't think these are relevent and also didn't work.

Please can anyone help?

Thanks a lot!
When you define recordTest(), you have to write which class it belongs to. That is int record::recordTest(const string test1, const string test2){//...
From looking at a few other things online the problem may be due to the sample mentioned above being converted to the 2008 VS format. No idea what the problem could be or how to fix it though...
Forget my suggestion :)

Thanks a lot hamsterman! That did the trick.

The silly thing is I did start of with it coded like that but another problem resulted in me getting rid of it.


Thanks for your quick concise response!
you should include your namespaces outside of functions as well unless you are doing this purposefully to stop conflicts.
Last edited on
OK cheers, I wasn't sure where to put it but that makes sense... thanks
Topic archived. No new replies allowed.