|
Can anyone tell me the possible cause of this linker error? I am making a Communicator Component, in the Communicator.h file I write #include "Sockets.h", the Sockets.h file is in the correct folder and contains a class SocketSystem, So now when I declare an object of SocketSystem in my Communicator.h file which is a component that I am trying to make, the above linker error occurs.
Please help!!!
Note: My Sockets.h is a normal C++ header file which contains different Classes and is not included in the project but is present in the same folder.
|
|
|
|
|
Did you make sure to include the necessary .LIB files in your project's "Additional Dependencies" property?
|
|
|
|
|
LNK2001 error means that your code is referencing functions that the linker
cannot find.
You have to tell it where to find those functions.
Most likely, the functions appear in some DLL that is not part of your
program.
What are the names of the functions that it can't find?
Post some of the exact error messages it is giving you.
Rich
|
|
|
|
|
Communicator.obj : error LNK2001: unresolved external symbol "public: __thiscall SocketSystem::SocketSystem(void)" (??0SocketSystem@@QAE@XZ)
Communicator.obj : error LNK2001: unresolved external symbol "public: __thiscall SocketSystem::~SocketSystem(void)" (??1SocketSystem@@QAE@XZ)
Debug\Trial.dll : fatal error LNK1120: 2 unresolved externals
These are the error messages which I get when I declare an object of SocketSystem Class which is present in my "Sockets.h"
|
|
|
|
|
OK, I understand that the SocketSystem class is declared in "Sockets.h", but where is the class defined? Where are the actual functions located?
Do you have the source for the SocketSystem class, or do you only have the compiled version?
|
|
|
|
|
The "Sockets.h" file only contains the declaration of the functions, and the functions are implemented in "Sockets.cpp".
The Sockets.cpp file is also present in the same folder as Sockets.h
|
|
|
|
|
Well, that must be the problem. You just need to add the Sockets.cpp file to your project.
|
|
|
|
|
Let me ask an easier question:
Do you have a file called "Sockets.cpp" ?
If you have a file by that name, add it to your project, then rebuild, and see if it works.
|
|
|
|
|
Is it mandatory to add the files in the project? I mean I have the files in the same project folder but I have not added those files in my project itself. I tried doing that earlier, but it gave me around 17 linker errors on that, so I removed those files from my project.
|
|
|
|
|
The files which contain the actual implementations of the functions must be part of your project, otherwise how else does the compiler generate code for those functions?
If including the Sockets.cpp file caused more linker errors, then that means that there must be OTHER .cpp files that must ALSO be included.
|
|
|
|
|
Yes I knew about it and so I even tried adding all those 4 modules that I used to use in my previous C++ project. Now when I add all those files as well, the compiler again gives me a linker error, I will list those errors in 5 minutes from now. Please see if that makes any sense to you.
|
|
|
|
|
Linking...
Creating library Debug\Trial.lib and object Debug\Trial.exp
Sockets.obj : error LNK2019: unresolved external symbol __imp__WSAGetLastError@0 referenced in function "public: static class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> > __cdecl SocketSystem::GetLastMsg(bool)" (?GetLastMsg@SocketSystem@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z)
Sockets.obj : error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function "public: __thiscall SocketSystem::SocketSystem(void)" (??0SocketSystem@@QAE@XZ)
Sockets.obj : error LNK2019: unresolved external symbol __imp__WSACleanup@0 referenced in function "public: __thiscall SocketSystem::~SocketSystem(void)" (??1SocketSystem@@QAE@XZ)
Sockets.obj : error LNK2019: unresolved external symbol __imp__inet_ntoa@4 referenced in function "public: static class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> > __cdecl SocketSystem::getIP(class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> > const &)" (?getIP@SocketSystem@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV23@@Z)
Sockets.obj : error LNK2019: unresolved external symbol __imp__gethostbyname@4 referenced in function "public: static class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> > __cdecl SocketSystem::getIP(class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> > const &)" (?getIP@SocketSystem@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV23@@Z)
Sockets.obj : error LNK2019: unresolved external symbol __imp__inet_addr@4 referenced in function "public: static class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> > __cdecl SocketSystem::getIP(class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> > const &)" (?getIP@SocketSystem@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV23@@Z)
Sockets.obj : error LNK2019: unresolved external symbol __imp__socket@12 referenced in function "public: __thiscall Socket::Socket(void)" (??0Socket@@QAE@XZ)
Sockets.obj : error LNK2019: unresolved external symbol __imp__closesocket@4 referenced in function "public: __thiscall Socket::~Socket(void)" (??1Socket@@QAE@XZ)
Sockets.obj : error LNK2019: unresolved external symbol __imp__shutdown@8 referenced in function "public: __thiscall Socket::~Socket(void)" (??1Socket@@QAE@XZ)
Sockets.obj : error LNK2019: unresolved external symbol __imp__connect@12 referenced in function "public: bool __thiscall Socket::connect(class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >,int)" (?connect@Socket@@QAE_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z)
Sockets.obj : error LNK2019: unresolved external symbol __imp__htons@4 referenced in function "public: bool __thiscall Socket::connect(class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >,int)" (?connect@Socket@@QAE_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z)
Sockets.obj : error LNK2019: unresolved external symbol __imp__send@16 referenced in function "public: void __thiscall Socket::send(char const *,unsigned int)" (?send@Socket@@QAEXPBDI@Z)
Sockets.obj : error LNK2019: unresolved external symbol __imp__recv@16 referenced in function "public: void __thiscall Socket::recv(char *,unsigned int)" (?recv@Socket@@QAEXPADI@Z)
Sockets.obj : error LNK2019: unresolved external symbol __imp__listen@8 referenced in function "public: __thiscall SocketListener::SocketListener(int)" (??0SocketListener@@QAE@H@Z)
Sockets.obj : error LNK2019: unresolved external symbol __imp__bind@12 referenced in function "public: __thiscall SocketListener::SocketListener(int)" (??0SocketListener@@QAE@H@Z)
Sockets.obj : error LNK2019: unresolved external symbol __imp__accept@12 referenced in function "public: class Socket __thiscall SocketListener::waitForConnect(void)" (?waitForConnect@SocketListener@@QAE?AVSocket@@XZ)
Debug\Trial.dll : fatal error LNK1120: 16 unresolved externals
Build log was saved at "file://c:\Documents and Settings\ashu\Desktop\Trial\Trial\Debug\BuildLog.htm"
Trial - 17 error(s), 0 warning(s)
List of 17 linker errors that are generated when I include all the files that I use.
|
|
|
|
|
OK now we are getting somewhere.
You must include the Ws2_32.lib file in your project's "Additional Dependencies" property.
Do you know how to set that property?
Those functions in the error messages are located in the ws2_32.dll file.
|
|
|
|
|
How do we use boolean variables in COM?
|
|
|
|
|
Hello rahultaing,
There are actually 3 different boolean types defined in IDL :
1. The boolean type (8 bits) which is equivalent to a "char" typein C++.
2. The VARIANT_BOOL (16-bits) which is equivalent to a "short" type in C++.
3. The BOOL type (32-bits) which is equivalent to a "long" type in C++.
For inter-operability with other COM development languages like VB, always use VARIANT_BOOL.
Best Regards,
Bio.
-- modified at 3:38 Sunday 9th April, 2006
|
|
|
|
|
How do we write Constructors & Destructors in COM, Is it possible? If it is not possible then how and where should I perform the initialization task?
|
|
|
|
|
Hello rahultaing,
COM does not provide any specifications for constructors and destructors. To perform initialization for COM objects written in ATL, use the FinalConstruct() (for initialization) and FinalRelease() (for uninitialization) methods.
Best Regards,
Bio.
|
|
|
|
|
Hello,
How to freeze panes in Excel Spreadsheet?
Thanks.
|
|
|
|
|
Hello,
I want to write a simple program which adds .vcf files to outlook contacts, i mean a program which imports the .vcf file to the contacts list by doing the functionallity of (File->Import and Export->Import a VCardFile)
How can I achive this goal?
Thank you very much...
|
|
|
|
|
Hi I'm trying to import an OCX control into a dialog box. It has IDispatch interface. It fails when I try to call its methods? Can someone tell me the steps requred.
Thanks
|
|
|
|
|
Is the control being created, do you see it on the dialog?
|
|
|
|
|
I have a COM dll that is registered in HKEY_CURRENT_USER\Software\Classes.
It have the correct entries for creating it in the system provided DllSurrogate. ( Eg. DllHost.exe )
Creating an instance of it using Windows 2000 successfully launches DllHost.exe and creates the instance.
Trying the same with WinXP fails with "Class not registered".
( If i register the COM dll under HKEY_LOCAL_MACHINE it works with XP to. )
The creation under XP goes through svchost.exe ( running as system ),
it will find the registry keys registered under HKEY_CURRENT_USER but it will also try to find them under HKEY_CLASSES_ROOT and fail.
( Probably one call is done whilst impersonating and one not. )
For short, what needs to be done to successfully host a COM dll registered under HKEY_CURRENT_USER in DllHost.exe under windows XP?
/Magnus
- I don't necessarily agree with everything I say
|
|
|
|
|
I would to add two methods to already existing activex control. How to do go about it. Should I add a new interface. If yes, how to do it. Any article or help.
Best Regards
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg."
- Bjarne Stroustrup
|
|
|
|
|
Do you have the source code? If Yes what version of VS are you using?
|
|
|
|
|
HI
i want to create a wrapper class of win32_Process class and i want to define my own methods into that wrapper class and after that i want to display messages whenever a new process is started or class using that wrapper class .
Can you please suggest how to procedd with this
Thanks in Advance
abhi
|
|
|
|