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
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.
Re: Linker Error while linking .lib files "nresolved external symbol"
When DLL (und lib) is created (compiled( the EXPORTING_DLL is defined. So the type of the HelloWorld() is
Code:
extern __declspec(dllexport) void HelloWorld() ;
But if EXPORTING_DLL is not defined in exe project then HelloWorld() would be declared as
Code:
extern __declspec(dllimport) void HelloWorld() ;
And it seems to be the case here: the linker in exe project looks for "__declspec(dllimport) void __cdecl HelloWorld(void)" while the lib contains only "__declspec(dllexport) void __cdecl HelloWorld(void)"
Re: Linker Error while linking .lib files "nresolved external symbol"
Hi guys
thanks for the replies. I havent got rid of the previous problem but I tried a new toy project to understand the linking. It is as follows
code for dll
example.cpp
---------------
/ Example.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
// This function is used to calculate the total area of a parallelepiped rectangle
double BoxArea(double L, double H, double W);
// This function is used to calculate the volume of a parallelepiped rectangle
double BoxVolume(double L, double H, double W);
// This function is used to get the dimensions of a rectangular parallelepiped
// calculate the area and volume, then pass the calculated values to the
// function that called it.
extern "C" __declspec(dllexport)void BoxProperties(double Length, double Height,
double Width, double& Area, double& Volume);
double BoxVolume(double L, double H, double W)
{
return L * H * W;
}
void BoxProperties(double L, double H, double W, double& A, double& V)
{
A = BoxArea(L, H, W);
V = BoxVolume(L, H, W);
}
I build the project and there were no errors and I got the .lib and .dll files upon building the project.
There is another project where I am trying to use the .lib generated above. I have copied the Example.lib, Example.dll and Example.obj to the new project folder . I also added these files to the project. In the project->settings->link->input I appended Example.lib to the Object/Library module text box . I wrote the following cpp code in the new project.
test.cpp
-----------
#include <iostream>
Re: Linker Error while linking .lib files "nresolved external symbol"
Thanks for the suggestion Victor! I will take care of that in my future posts.
Well thanks for all the help you guys have done. I finally resolved my issues regarding linker error. I will update this post with step by step procedure I figured out to make a dll and use it in other applications.
Bookmarks