Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

linking with the lib

I have an existing simple exe project, and i have just added a new project to the workspace. It compiles fine for when i include the header of one of the files in the newly added project, but when i try to call one of the methods in the included file i get these errors below..

testerDlg.obj :error LNK2001: unresolved external symbol "public: __thiscall smtpapp::~smtpapp(void)" (??1smtpapp@@QAE@XZ)
testerDlg.obj : error LNK2001: unresolved external symbol "public: void __thiscall smtpapp::Create(void)" (?Create@smtpapp@@QAEXXZ)
testerDlg.obj : error LNK2001: unresolved external symbol "public: __thiscall smtpapp::smtpapp(void)" (??0smtpapp@@QAE@XZ)
Debug/tester.exe : fatal error LNK1120: 3 unresolved externals

no .lib file is created so how do you link it with the lib?
[808 byte] By [Laurio] at [2007-11-11 10:23:01]
# 1 Re: linking with the lib
you can define functions you do not have a body for in a .h file, and until you call those functions, its all good. When you call them, you see this problem. To fix it, the compiler needs a body for the function you called. This body is either in a source file (add .cpp file to project) or a lib file (could be .dll but all dll files have a .lib file that you use at compile time) or possibly other file (platform specific / such as an activex add on). But wherever the body for the function is, you have to have that visible to the compiler.
jonnin at 2007-11-11 20:58:59 >
# 2 Re: linking with the lib
I have the cpp file already added to the project, in which it has the implemplentation for the function that i want to call, how do i make this known to the compiler? as for the DLL's, i havnt a clue where they get created or such, all i have are the .obj and .pch files
Laurio at 2007-11-11 21:00:06 >
# 3 Re: linking with the lib
pch is precompiled headers, which are buggy and should be turned off in the project settings. Possibly this is part of your problem -- precompiled headers tend to keep errors that you have fixed, making it difficult to tell when you resolve an issue.

You need a .h file with the prototype & the cpp file with the body. The user will include the .h file, the project will contain the cpp file. If all that matches, it should compile! If not, something is wrong in your project settings most likely.
jonnin at 2007-11-11 21:01:04 >
# 4 Re: linking with the lib
Are these ordinary classes or templates? If it's the latter, add the implementation of the functions into the .h file.
Danny at 2007-11-11 21:02:04 >
# 5 Re: linking with the lib
These are ordinary classes, and in the class where i seem to get these LNK2001 errors, there is only 1 function with implementation, and one constructor and destructor. Would moving the body of the 1 function to the header file solve this problem?
Laurio at 2007-11-11 21:03:03 >
# 6 Re: linking with the lib
No, if these are ordinary classes you shouldn't move the functions' bodies to the header file. They should be placed in a separate .cpp file, unless these functions are very short (or have an empty body). In that case, you can define them inside the class declration.
Danny at 2007-11-11 21:04:08 >
# 7 Re: linking with the lib
All implementation is in a seperate Cpp file and is included in the project, but for some reason when i come to call the method it comes with this link error ive no idea whats wrong!
Laurio at 2007-11-11 21:05:01 >
# 8 Re: linking with the lib
can you post the cpp and h file? also, try deleting all the temporary files (debug or release folders, *.i* and .ncb, .pch files)
jonnin at 2007-11-11 21:06:10 >
# 9 Re: linking with the lib
the actual project is at http://www.codeguru.com/cpp/in/int...icle.php/c6177/

All that i want it to do is add to me workspace and be a dependancy of another project within the workspace. Ive removed all temp files but still the problem resides
Laurio at 2007-11-11 21:07:07 >