|
-
February 24th, 2011, 10:40 AM
#5
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);
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
double BoxArea(double L, double H, double W)
{
return 2 * ((L*H) + (L*W) + (H*W));
}
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>
extern "C" __declspec(dllimport)void BoxProperties(double L, double H,
double W, double& A, double& V);
int main()
{
double Length, Height, Width, Area, Volume;
cout << "Enter the dimensions of the box\n";
cout << "Length: ";
cin >> Length;
cout << "Height: ";
cin >> Height;
cout << "Width: ";
cin >> Width;
BoxProperties(Length, Height, Width, Area, Volume);
cout << "\nProperties of the box";
cout << "\nLength: " << Length;
cout << "\nHeight: " << Height;
cout << "\nWidth: " << Width;
cout << "\nArea: " << Area;
cout << "\nVolumne: " << Volume;
cout << "\n\n";
return 0;
}
After building the code I get the following linker error(no previous linker errors ):
--------------------Configuration: Exampletest - Win32 Debug--------------------
Linking...
Creating library Debug/Exampletest.lib and object Debug/Exampletest.exp
LIBCMTD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Exampletest.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Exampletest.exe - 2 error(s), 0 warning(s)
Guys help me resolve this
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
|