error LNK2001: unresolved external symbol _GetUDPCrequest@24

--------------------Configuration: soap_udp_test - Win32 Debug--------------------
Compiling...
soap_udp_test.c
automatic link to gmglib.lib
Linking...
soap_udp_test.obj : error LNK2001: unresolved external symbol _GetUDPCrequest@24
Debug/soap_udp_test.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

soap_udp_test.exe - 2 error(s), 0 warning(s)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include ".\DLL1.h"

int _stdcall GetUDPCrequest( char *server_addr, unsigned short server_port, char *reqstr, long sizeof_reqstr, char *resultstr, long sizeof_resultstr );


int main (int argc, char *argv())
	{
		char reqstr[20000],resultstr[20000];
		FILE *inpfile,*outfile;
		char server_addr[] = "68.166.197.178";
		unsigned short server_port = 5510;
		int n, nr;

		
		// open the file

		if ( (inpfile = fopen("C:\\udp_request.txt","r")) == NULL)
			{
			printf("inputfile not found\n");
			gets(reqstr);
			return -1;
			}
		if ( (outfile = fopen("C:\\udp_result.txt","w")) == NULL)
			{
			printf("could not create out file\n");
			gets(reqstr);
			return -1;
			}

		//read each line 
		while( (n = fgets(reqstr, sizeof(reqstr), inpfile) > 0 ))
			{
			 n--;
			 reqstr[n] = 0;

			//send the request
			nr = GetUDPCrequest(server_addr, server_port, reqstr,n, resultstr, sizeof(resultstr) );

			//write the responce
			fprintf(outfile, "%s\n", resultstr);
			}
			
	return 0;
	}

Open in new window

1030071002Asked:
Who is Participating?
 
Infinity08Commented:
You have declared the function GetUDPCrequest, but the linker could not find the definition (implementation) of the function.

Where is that function defined ? Did you use the correct prototype (usually you'd place it in a header file, and include the header file) ?
0
 
pgnatyukCommented:
This code and the compiler message look a bit strange. I can be wrong, but

1. there is an include "DLL1.h" but you declare this function after.
2. the declaration looks like a Win API function, but it should be declared __declspec( dllimport ). How you declared this function in the library?

I think you have a mistake with the function declarations in your map application and in the library.

Please check here: http://www.codeproject.com/KB/DLL/XDllPt2.aspx
0
 
Infinity08Commented:
>> 2. the declaration looks like a Win API function, but it should be declared __declspec( dllimport ). How you declared this function in the library?

Only if the function is defined in a DLL.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
If you coded this function yourself it needs to be declared to the compiler as an 'export' (so that other applications can 'import' it).

eg. in the dll
__declspec(dllexport) int _stdcall GetUDPCrequest( char *server_addr, unsigned short server_port, char *reqstr, long sizeof_reqstr, char *resultstr, long sizeof_resultstr );

and in your exe
__declspec(dllimport) int _stdcall GetUDPCrequest( char *server_addr, unsigned short server_port, char *reqstr, long sizeof_reqstr, char *resultstr, long sizeof_resultstr );



For the dll side of things you could have as an alternative the function specified in the .def file as an exported function.
0
 
pgnatyukCommented:
Yes, I do remember a question about the same function name and the function was in a C-style DLL and the asker called it from a VB app. So I posted that comment with the link.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.