[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

error LNK2001: unresolved external symbol _GetUDPCrequest@24

Posted on 2009-12-30
5
Medium Priority
?
394 Views
Last Modified: 2012-05-08
--------------------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

0
Comment
Question by:1030071002
  • 2
  • 2
5 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 800 total points
ID: 26145434
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
 
LVL 33

Assisted Solution

by:pgnatyuk
pgnatyuk earned 800 total points
ID: 26145595
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
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 800 total points
ID: 26145647
>> 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
 
LVL 45

Assisted Solution

by:AndyAinscow
AndyAinscow earned 400 total points
ID: 26145700
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
 
LVL 33

Assisted Solution

by:pgnatyuk
pgnatyuk earned 800 total points
ID: 26145716
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question