Typename and tracking down a LNK2019 error

I have the following code:

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef CONNECTIONMANAGER_H
#define CONNECTIONMANAGER_H

#include <list>
#include <iostream>
#include "ThreadLib.h"
#include "SocketLibTypes.h"
#include "SocketLibErrors.h"
#include "SocketSet.h"
#include "Connection.h"



namespace SocketLib
{
	 // Forward Declarations.
	 template<typename protocol>
	 class Connection;

	 // ================================================================================================================
	 // Description: This connection manager class will manage connections, all identified with an ID. 
	 // ================================================================================================================
	 template<typename protocol, typename defaulthandler>
	 class ConnectionManager
	 {
		  typedef std::list< Connection<protocol> > clist;
		  typedef std::list< Connection<protocol> >::iterator clistitr;

	.
        .
        .
		  void NewConnection(DataSocket& p_socket);
        .
        .
        .

	 protected:
		  // ============================================================================================================
		  // This closes a connection within the connection manager; it is assumed that this is an external call- noth-
		  // ing needs to be notified about the connection being closed.
		  // ============================================================================================================
		  void Close(clistitr p_itr);

	 .
         .
         .

	 // ================================================================================================================
	 //  Destructs the manager, closing every connection contained within.
	 // ================================================================================================================
	 template<typename protocol, typename defaulthandler>
	 ConnectionManager<protocol, defaulthandler>::~ConnectionManager()
		  {
				// Close every socket in the manager.
				clistitr itr;

				for (itr = m_connections.begin(); itr != m_connections.end(); ++itr)
					 itr->CloseSocket();
		  }



	 // ================================================================================================================
	 //  This notifies the manager that there is a new connection available.
	 // ================================================================================================================
	 template<typename protocol, typename defaulthandler>
	 void ConnectionManager<protocol, defaulthandler>::
		  NewConnection(DataSocket& p_socket)
		  {
				// Turn the socket into a connection.
				Connection<protocol> conn(p_socket);

				if (AvailableConnections() == 0)
					 {
						  // tell the default protocol handler that there is no more room for the connection within this 
						  // manager.
						  defaulthandler::NoRoom(conn);

						  // It is assumed that the protocol handler has told the connection the appropriate message, so 
						  // close the connection.
						  conn.CloseSocket();
					 }
				else
					 {
						  // Add the connection.
						  m_connections.push_back(conn);

						  // Get a ref pointing to the connection.
						  Connection<protocol>& c = *m_connections.rbegin();

						  // Turn the connection into nonblocking mode.
						  c.SetBlocking(false);

						  // Add the connection to the socket set.
						  m_set.AddSocket(c);

						  // Give the connection its default handler.
						  c.AddHandler(new defaulthandler(c));
					 }
		  }


At line 44:

 
typedef std::list< Connection<protocol> >::iterator clistitr;


I get warning C4346 and error C2016 which basically means I have to put 'typename' before std like this:

 
typedef typename std::list< Connection<protocol> >::iterator clistitr;


However, once I do this I get error:

LNK2019 unresolved external symbol "public: __thiscall SocketLib::DataSocket(unsigned int)" (??0DataSocket@Socket@@QAE@I@Z) referenced in function _main

DataSocket only shows up in two places in the code.

At line 63:

 
void NewConnection(DataSocket& p_socket);


And at line 172:

1
2
3
template<typename protocol, typename defaulthandler>
	 void ConnectionManager<protocol, defaulthandler>::
		  NewConnection(DataSocket& p_socket)


What does the error mean and how do I fix it?
Last edited on
> DataSocket only shows up in two places in the code.
In the single header file that you incompletely pasted, yes, it appears only two times.

> SocketLib::DataSocket(unsigned int) referenced in function _main
In main() you are trying to use that function (¿a constructor maybe?), either you didn't define such function, or you didn't link it.

http://www.cplusplus.com/forum/general/113904/
Here is the code that generates the error:

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
#include "SocketLib.h"
#include <iostream>

using namespace SocketLib;

int main()
{
	 ListeningSocket lsock;              // the listening socket
	 DataSocket dsock;                   // the data socket
	 char buffer[128];                   // the buffer of data
	 int size = 0;                       // size of data in the buffer
	 int received;                       // number of bytes received

	 lsock.Listen(5098);               // listen on port 5098
	 dsock = lsock.Accept();             // wait for a connection

	 dsock.Send("Hello!\r\n", 8);

	 while (true)
	 {
		  // receive as much data as there is room for
		  received = dsock.Receive(buffer + size, 128 - size);
		  size += received;

		  // process "Enter" characters
		  if (buffer[size - 1] == '\n')
		  {
				// print out the size of the string
				std::cout << size << std::endl;

				// send the string back to the client
				dsock.Send(buffer, size);

				// reset the size
				size = 0;
		  }
	 }
	 return 0;
}


When I searched the entire solution for "DataSocket" there were 5 header files and 1 .cpp file that came up. All of them in the SocketLib library. But the SocketLib library is linked correctly otherwise I'd get an error at the very first #include "SocketLib.h" and I don't.
> But the SocketLib library is linked correctly otherwise I'd get an error at
> the very first #include "SocketLib.h" and I don't.
#include is a preprocessor directive. All you know is that the header file (the *.h) exists and it is found.
You don't get compile errors either. Headers files give you the prototype of the functions, so you know their name, and the number and type of parameters that need. So all you know is that you are calling the function correctly.
What you need are the definitions of the functions, their body. And you don't have that or you didn't specify which file has it (*.cpp, *.o, *.a, *.dll), that's why you get a link error.


> But the SocketLib library is linked correctly
You got an error. That may be because you made a mistake or because the library is bad implemented.
¿Do you consider you post sufficient to help you whatever the reason may be?
¿what library are you using? ¿where can we get it?
¿how are you building your project? ¿what commands are executed?
¿what part of all that code is yours? ¿what can you modify?


> unresolved external symbol SocketLib::DataSocket(unsigned int) referenced in function _main
don't see where you are calling that function in main.
but well, eyes cannot be trusted, would like to be able to build your project.
https://github.com/
Last edited on
So this is my first time using GitHub but I think everything you need is there.

https://github.com/bishoposiris/Demo601

I built this in Visual Studio Community 2015. If you have other questions my email is:

bishoposiris@gmail.com

Thanks for looking at this for me.
Last edited on
> but I think everything you need is there.
Missing SocketLib.h
Should have been included with the SocketLibrary.sln file but I just included the file separately so it should be there now.
> Should have been included with the SocketLibrary.sln file
No.

> it should be there now.
yes, but now I'm missing
1
2
3
4
5
6
7
8
9
#include "SocketLibTypes.h"
#include "SocketLibSystem.h"
#include "SocketLibSocket.h"
#include "Connection.h"
#include "ListeningManager.h"
#include "ConnectionHandler.h"
#include "ConnectionManager.h"
#include "SocketLibErrors.h"
#include "Telnet.h" 
Ok, I've made zip files ThreadLibrary, SocketLibrary and BasicLibrary. Each contains all the files of their corresponding library. I've uploaded these zip files to the repository. In the solution these libraries are called ThreadLib, SocketLib, and BasicLib. Thanks for being so patient.
Missing ThreadLibMutex.h
also, you are missing some includes, like cmath for trigonometric functions and cstring for memset()


> SocketLib::DataSocket(unsigned int) referenced in function _main
The definition is in SocketLibrary/SocketLibSocket.cpp, it has one parameter that has a default value, so you are using it when doing DataSocket dsock;

The problem is a misconfiguration in your project.
I see that it is in SocketLib.vcxproj, so perhaps it is missing in your main project.

Don't use VS so can't tell you how to do it.
Regards.
Topic archived. No new replies allowed.