|
-
February 23rd, 2011, 06:10 PM
#1
Linker Error while linking .lib files "nresolved external symbol"
Hi guys,
I have project named TestingDLL(Win32 DLL project). It has the following header file
(The code has been taken from a site which I dont remember but for discussion purpose this is fine)
sampledll.h
---------------
#ifndef INDLL_H
#define INDLL_H
#ifdef EXPORTING_DLL
extern __declspec(dllexport) void HelloWorld() ;
#else
extern __declspec(dllimport) void HelloWorld() ;
#endif
#endif
and a .cpp file
sampldll.cpp
---------------
#define EXPORTING_DLL
#include "sampledll.h"
#include <stdio.h>
void HelloWorld()
{
printf("hello");
}
I have build this project and I got the TestingDLL.lib sucessfully after the build.
I have another project CallingDLL(Win 32 Console application) whose code is as follows
calling.cpp
--------------
#include "sampledll.h"
#pragma comment(lib,"TestingDLL.lib")
int main()
{
HelloWorld();
return 0;
}
this code calls the library function Helloworld(). Now I went to projects->settings->link->input
and specified the .lib file name and the path to find it. I also made chages in C/C++->preprocessor->Additional include directories and added the path where sampledll.h is found.
I always get
compiling...
calling.cpp
Linking...
calling.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl HelloWorld(void)" (__imp_?HelloWorld@@YAXXZ)
Debug/CallingDll.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
CallingDll.exe - 2 error(s), 0 warning(s)
I have also tried some other ways like going to tools->options->Directories and adding the paths but still I get the same error.
It would be great help if someone tells me in a systematic manner on how to link a .lib file to another project.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|