LNK2019 unresolved external symbol

I'm getting 65 errors on a file in a program I'm trying to compile. I've posted 7 of them below as they are the 7 that I'm getting on all the other files as well. I know it has something to do with the DataSocket class but I can't decipher all the rest of the error. Does anyone know what this means?


Severity	Code	Description	Project	File	Line
Error	LNK2019	unresolved external symbol "protected: virtual __cdecl SocketLib::Socket::~Socket(void)" (??1Socket@SocketLib@@MEAA@XZ) referenced in function "public: virtual __cdecl SocketLib::DataSocket::~DataSocket(void)" (??1DataSocket@SocketLib@@UEAA@XZ)	Demo06-01	C:\Documents\Personal\MUD Project\MUD Telnet\MUD Telnet\Demo06-01\Main.obj	1
Error	LNK2019	unresolved external symbol "public: __cdecl SocketLib::DataSocket::DataSocket(unsigned __int64)" (??0DataSocket@SocketLib@@QEAA@_K@Z) referenced in function main	Demo06-01	C:\Documents\Personal\MUD Project\MUD Telnet\MUD Telnet\Demo06-01\Main.obj	1
Error	LNK2019	unresolved external symbol "public: int __cdecl SocketLib::DataSocket::Send(char const *,int)" (?Send@DataSocket@SocketLib@@QEAAHPEBDH@Z) referenced in function main	Demo06-01	C:\Documents\Personal\MUD Project\MUD Telnet\MUD Telnet\Demo06-01\Main.obj	1
Error	LNK2019	unresolved external symbol "public: int __cdecl SocketLib::DataSocket::Receive(char *,int)" (?Receive@DataSocket@SocketLib@@QEAAHPEADH@Z) referenced in function main	Demo06-01	C:\Documents\Personal\MUD Project\MUD Telnet\MUD Telnet\Demo06-01\Main.obj	1
Error	LNK2019	unresolved external symbol "public: __cdecl SocketLib::ListeningSocket::ListeningSocket(void)" (??0ListeningSocket@SocketLib@@QEAA@XZ) referenced in function main	Demo06-01	C:\Documents\Personal\MUD Project\MUD Telnet\MUD Telnet\Demo06-01\Main.obj	1
Error	LNK2019	unresolved external symbol "public: void __cdecl SocketLib::ListeningSocket::Listen(unsigned short)" (?Listen@ListeningSocket@SocketLib@@QEAAXG@Z) referenced in function main	Demo06-01	C:\Documents\Personal\MUD Project\MUD Telnet\MUD Telnet\Demo06-01\Main.obj	1
Error	LNK2019	unresolved external symbol "public: class SocketLib::DataSocket __cdecl SocketLib::ListeningSocket::Accept(void)" (?Accept@ListeningSocket@SocketLib@@QEAA?AVDataSocket@2@XZ) referenced in function main	Demo06-01	C:\Documents\Personal\MUD Project\MUD Telnet\MUD Telnet\Demo06-01\Main.obj	1

Last edited on
Sorry. Here's the code for the DataSocket class.

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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// This file contains the definitions for the three socket classes: Basic, Data, and Listening.


#ifndef SOCKETLIBSOCKET_H
#define SOCKETLIBSOCKET_H

// ==================================================================================================================
//  Include Files.
// ==================================================================================================================
#include "../BasicLibrary/BasicLib.h"
#include "SocketLibTypes.h"
#include "SocketLibErrors.h"


namespace SocketLib
{
...
	 // Class:       DataSocket
	 // Purpose:     A variation of the BasicSocket base class that handles TCP/IP data connections.
	 // =============================================================================================================
	 class DataSocket : public Socket
	 {
	 public:
		  // ========================================================================================================
		  // Function:    DataSocket
		  // Purpose:     Constructs the data socket with optional values.
		  // ========================================================================================================
		  DataSocket(sock p_socket = -1);

		  // ========================================================================================================
		  // Function:    GetRemoteAddress
		  // Purpose:     Get the IP address of the remote host.
		  // ========================================================================================================
		  inline ipaddress GetRemoteAddress() const
		  {
				return m_remoteinfo.sin_addr.s_addr;
		  }

		  // ========================================================================================================
		  // Function:    GetRemotePort
		  // Purpose:     Gets the remote port of the socket.
		  // ========================================================================================================
		  inline port GetRemotePort() const
		  {
				return ntohs(m_remoteinfo.sin_port);
		  }


		  // ========================================================================================================
		  // Function:    IsConnected
		  // Purpose:     Determines if the socket is connected or not.
		  // ========================================================================================================
		  inline bool IsConnected() const
		  {
				return m_connected;
		  }


		  // ========================================================================================================
		  // Function:    Connect
		  // Purpose:     Connects this socket to another socket. This will fail if the socket is already connected, 
		  //			  or the server rejects the connection.
		  // ========================================================================================================
		  void Connect(ipaddress p_addr, port p_port);

		  // ========================================================================================================
		  // Function:    Send
		  // Purpose:     Attempts to send data, and returns the number of bytes sent.
		  // ========================================================================================================
		  int Send(const char* p_buffer, int p_size);

		  // ========================================================================================================
		  // Function:    Receive
		  // Purpose:     Attempts to receive data from a socket, and returns the amount of data received.
		  // ========================================================================================================
		  int Receive(char* p_buffer, int p_size);

		  // ========================================================================================================
		  // Function:    Close
		  // Purpose:     Closes the socket.
		  // ========================================================================================================
		  void Close();

	 protected:

		  bool m_connected;                // Is the socket connected?

		  struct sockaddr_in m_remoteinfo; // Structure containing information about the remote connection.
	 }; // End class DataSocket

	 // =============================================================================================================
	 // Class:       ListeningSocket
	 // Purpose:     A variation of the BasicSocket base class that handles incoming TCP/IP connection requests.
	 // =============================================================================================================
	 class ListeningSocket : public Socket
	 {
	 public:

		  // ========================================================================================================
		  // Function:    ListeningSocket
		  // Purpose:     Constructor. Constructs the socket with initial values.
		  // ========================================================================================================
		  ListeningSocket();

		  // ========================================================================================================
		  // Function:    Listen
		  // Purpose:     This function will tell the socket to listen on a certain port.  
		  // p_port:      This is the port that the socket will listen on.
		  // ========================================================================================================
		  void Listen(port p_port);

		  // ========================================================================================================
		  // Function:    Accept
		  // Purpose:     This is a blocking function that will accept an incoming connection and return a data 
		  //			  socket with info about the new connection. 
		  // ========================================================================================================
		  DataSocket Accept();

		  // ========================================================================================================
		  // Function:    IsListening
		  // Purpose:     Determines if the socket is listening or not.
		  // ========================================================================================================
		  inline bool IsListening() const
		  {
				return m_listening;
		  }

		  // ========================================================================================================
		  // Function:    Close
		  // Purpose:     Closes the socket.
		  // ========================================================================================================
		  void Close();

	 protected:
		  bool m_listening; // Is the socket listening?

	 }; // End class ListenSocket
} // End namespace SocketLib

#endif
Last edited on
"unresolved external symbol" is a linker error meaning it cannot find the definition of the thing that it is complaining about.
How do I trouble shoot something like this? The errors originate in file "main.obj" on line 1 which is not very helpful. I tried adding the SockLib library to the Additional Library Directories and the Additional Include Directories but that did nothing. I don't see any errors in main.cpp either. Ideas?

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 "../SocketLibrary/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;
}
The linker isn't finding anywhere where those things are defined. This probably means that you're not properly linking against the SocketLib library.

You say you've added the directory containing that library, to your link path. But have you told the linker that you want to link against that library?

I.e. have you added that library to the list of libraries you're linking against?
I have

C:\Path\SocketLibrary
C:\Path\BasicLibrary
C:\Path\ThreadLibrary

added to both Additional Include Directories and Additional Library Directories. If there's another step to this beyond what I've done I'm not familiar with it. SocketLibSocket.h is in the SocketLibrary.

I've already acknowledged that you've added the path to your link path.

What I asked was whether you've added the actual library file(s), to the list of libraries against which you're linking.

It sounds like you haven't done that, so you need to figure out how to do that in your IDE.
I'm sorry for being dense but I'm not following you. "...added the directory containing that library to your link path" and "told the linker you want to link against that library" seem, to me, to be the same thing. Else, why would I add the directory to the link path if I didn't want to link against that library. I use Visual Studio 2017. In the past whenever I had a LNK2019 error it was because I hadn't added the paths to the Additional Include Directories and Additional Library Directories. That is the length and breadth of my experience with linking. All of the files are in those libraries with the exception of source files of course.

I posted my question because if the libraries are linked and the files are in the libraries and there's nothing wrong with the class why am I getting these errors.

I appreciate you trying to help. I think I'm just not understanding what you mean because I'm unfamiliar with the inner workings of "linking" in general. Maybe spell it out in simpler terms? That might help me to make some forward progress. Again, I appreciate you taking the time to try and help me.
When you link something, you need to tell it what you are linking and, if it is not in the current directory, where to find it. I think you got that much.

Say I want to make an omelette. I need eggs, cheese and ham. All of the ingredients are in the refrigerator. So, my robot chef program mixes up the eggs and starts cooking them. Then it needs to link in the cheese and ham. I tell the robot chef to get the cheese and ham, and to look in the fridge as one possible place to find them. The robot finds the ingredients, and I get a delicious omelette.

Now, pretend that I don't tell the robot that it needs cheese and ham, but I do tell it to look for things in the refrigerator. Well, the robot doesn't know what to look for, so even if it opens the fridge door, it doesn't get anything out. And I get stuck with scrambled eggs rather than an omelette.

When you gave the paths to different directories, you told the linker where to look for libraries ("in the refrigerator"), but you never told it what libraries you need. You can have a directory that contains lots of libraries, so you need to be more specific when telling the linker what to do. The linker said, "well, I can look in SocketLibrary, BasicLibrary and ThreadLibrary if I need to, but I don't have any libraries that I need to link in right now, so I guess I'll continue on." You need to figure out which libraries are located in those directories and tell the linker you need them. I don't use VS, so I don't know what screen its on. However, there is probably a "link options" page on which you can specify which libraries you need to link in.
That's a great analogy by the way! Sadly it just confirms what I thought. C:\path\SocketLibrary IS the library that contains the files I need. And that's the path I've put in the linker. I can't drill down any further than that without selecting the file itself and the linker doesn't even allow that because it's a file and not a folder.

Are we sure it doesn't have something to do with the class maybe? I don't understand why this exact same fix has worked for the same error in the past but for this project it doesn't for some reason.

Would someone like to try and compile it themselves?
I think you've already been told the answer. You need to tell the linker what libraries to look in, and what directory to look in to find those libraries.

You've told it what directory. You haven't told it what library.
C:\path\SocketLibrary IS the library


No, C:\path\SocketLibrary is the Refrigerator, not the ham. A directory is NOT a library.

The file located at C:\path\SocketLibrary is the library.

You need to set 2 values in your link options.
1. Path to where to find libraries. This is C:\path\SocketLibrary.
2. Libraries you need. This is the file inside the above path.

I don't know how VS is set up, but there have to be 2 fields in the link options. The first is probably something like "link path" or "library path" (similar to include path). The second is something like "library" (similar to a header file you include in your source code).

I can't drill down any further than that without selecting the file itself and the linker doesn't even allow that because it's a file and not a folder.


This sounds like you are setting the link path. The path must be a directory. Somewhere else (on a different screen, maybe) you will have to set the library names.
I did a quick google, and found this shor YouTube video that sets up these fields for use with openCV. The same stuff applies to what you are trying to do.

https://www.youtube.com/watch?v=nHvAS9m-8Gg

So, the fields you need to set are General->Additional Library Directories and Input->Additional Dependencies. Put you path the first and the file name in the second, and you should be good to go.

(If you aren't using property pages, you're on your own. Again, I'm not a VS developer.)

My Google search was visual studio 2017 link library
For anyone reading this in the future I found the solution with some outside help. I had to add "SocketLib.lib" (without the quotes) to the following location:

Right click the main project. Select Properties. Under Linker --> Input --> Additional Dependencies add SocketLib.lib. That solved my linker errors.
Topic archived. No new replies allowed.