Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unresolved external symbol in a dll

Status
Not open for further replies.

michiganalan

Programmer
Joined
Oct 1, 2003
Messages
3
Location
US
Hi all,

I am trying to create a dll, to start with how dll works, I created a very simple dll as followed:

This is the maindll.cpp

#include "test.h"
#include "stdafx.h"

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}

int _stdcall adding(int x, int y)
{
int temp;
temp = perform(x,y);
//temp = x + y;
return temp;
}

while test.h includes:

int perform (int a, int b); // a function declaration

and test.c includes:

int perform (int a, int b) // a very simple function
{
return a + b;
}

I succesfully compile dll_main.cpp, test.c seperately. However, when I build the dll, I encountered

Creating library Debug/simple.lib and object Debug/simple.exp
simple.obj : error LNK2001: unresolved external symbol "int __cdecl perform(int,int)" (?perform@@YAHHH@Z)
Debug/simple.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.


The most interesting thing is that I am able to create a working dll without test.h and test.c, whenever I tried to call functino from test.h, I encounted the linker error.

Thanks all
Alan
 
Are you actually linking the object file for test.c?




-pete
 
what are your dll source files and what are your exe source files?

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Acutally,

I am building this dll with .c files, this is my first time working dll, so I am just wondering if I can use C-Language in VC++ to create a win32s dll?

Thanks in advance
 
you willuse the same header for dll, in dll implementation an in dllusilng. After you compile a dll. will result two files, a .dll and a .lib . When you want to use somethere the dll, link your project with that lib and use the same header for dllapi declaration.
/*yourdll.h*/
#if !defined(__YOUR_DLL_H)
#define __YOUR_DLL_H
#if !defined(__YOUR_DLL_IMPL_H)
# define dllapi __declspec(dllexport)
# else
# define dllapi __declspec(dllimport)
#endif
dllapi int perform (int a, int b);/*function declaration*/
#endif
/*yourdll.cpp*/
#define __YOUR_DLL_IMPL_H
#include "yourdll.h"
int perform (int a, int b) /* a very simple function*/
{
return a + b;
}

/*your_exe_dll_using.c*/
#include "yourdll.h"
main()
{
perform (1, 2);
}

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top