473,657 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What's wrong ?? LNK2019 error (Unresolved externals)

To all

I am new to MS's VC++ and got a question.
I've tried to write a simple console program "HelloWorld.cpp ", then
I've added a simple class (Class01.h and cpp)

Class01 compile well, but when I want to create an instance inside
HelloWorld.cpp, a LNK2019 error pops up (Unresolved Externals). I
guess somehow the HelloWorld.cpp can't find the Class01 !?

I've added the directory of the Class01.h and .cpp to the options
"Additional Include Directories", but still linking problem.

Expand|Select|Wrap|Line Numbers
  1. // HelloWorld.cpp : Defines the entry point for the console
  2. application.
  3. //
  4. #include "stdafx.h"
  5. #include "Class01.h"
  6.  
  7. using namespace std;
  8.  
  9. void list_CString (const char* oCStr) {
  10. size_t iSize = 0;
  11.  
  12. if (oCStr != NULL) {
  13. iSize =  _tcslen (oCStr);
  14. } else {
  15. iSize = 0;
  16. }
  17.  
  18. cout << "cInput has the following contents : " << endl;
  19. for (size_t i=0; i<iSize; i++) {
  20. cout << oCStr[i] << " ";
  21. }
  22. cout << endl;
  23. }
  24.  
  25. int _tmain(int argc, _TCHAR* argv[])
  26. {
  27. char* cInput = new char[10];
  28. memset (cInput, 0, sizeof (cInput));
  29. cout << "Hello World" << endl;
  30. cin >> cInput;
  31.  
  32. ::list_CString (cInput);
  33. cin >> cInput;
  34.  
  35. Class01* oClass01 = NULL;
  36. oClass01 = new Class01 (); // -- linking error!?
  37.  
  38. return 0;
  39. }
  40.  
  41.  
  42. // -- Class01.h
  43. #include "stdafx.h"
  44. #include <tchar.h>
  45.  
  46. #ifndef _CLASS01_
  47. #define _CLASS01_
  48. // -- cheat the compiler, Class01 is a managed class type !
  49. class Class01 {
  50. public:
  51. // Constructor(s)
  52. Class01 ();
  53.  
  54. // Getter and Setter(s)
  55. void setName (_TCHAR* otc_char);
  56.  
  57. private:
  58. _TCHAR* tc_Name;
  59. #endif
  60. };
  61.  
  62. // -- Class01.cpp
  63. #include "Class01.h"
  64.  
  65. void Class01::setName (_TCHAR* otc_char) {
  66. if (otc_char != NULL) {
  67. tc_Name = otc_char;
  68. } else {
  69. return;
  70. }
  71. }
  72.  
From Jason (Kusanagihk)
Nov 17 '05 #1
2 1084
Thanks pal, after adding the constructor code, it worked!

But another question, as from my code, I have set the cInput (char
array) to only a length of 10, but how come I can enter a string of
more than 20 or even 40 characters ?? (It looks quite illogical, but
somehow it works fine till now)

From Jason (Kusanagihk)
Nov 17 '05 #2
Jason Jacob wrote:
But another question, as from my code, I have set the cInput (char
array) to only a length of 10, but how come I can enter a string of
more than 20 or even 40 characters ?? (It looks quite illogical, but
somehow it works fine till now)


You are overflowing the buffer and stomping on memory you don't own.
Don't do that!!! Really bad things can happen. You are just unlucky
that it seems to have worked so far.

In today's C++, you should never use char arrays to manipulate strings.
Doing so can be really tedious, and it's just too easy to forget how big
your buffer is and write past the end of it. Always use a string class
instead. I prefer std::string, but any class, even CString, is better
than using char arrays.

--
David Olsen
qg********@yaho o.com

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
763
by: Bil Muh | last post by:
Hello Developers, I use VC++ .NET v2003. By using Windows Forms .NET, I am developing an application which will work with TCP/IP functions. I can Build my application in Debug Mode normally, but, whenever I want to Build at Release Mode, compiler gives LNK2001, LNK2019 ve LNK1120 errors. I read the MSDN documents, unfortunately, I could not solve my problem. I am requesting your help. All errors are below with my application name...
10
3399
by: Bil Muh | last post by:
Hello Developers, I use VC++ .NET v2003. By using Windows Forms .NET, I am developing an application which will work with TCP/IP functions. I can Build my application in Debug Mode normally, but, whenever I want to Build at Release Mode, compiler gives LNK2001, LNK2019 ve LNK1120 errors. I read the MSDN documents, unfortunately, I could not solve my problem. I am requesting your help. All errors are below with my application name...
2
5278
by: rangalo | last post by:
Hi All, I have succeeded in compiling a massive project, originally from vc6 to VS .Net 2005. Now, while linking I am having loads of linker errors with the above code. LNK20019 and LNK2001. Giving error msg that some symbol is not found. Actually, the library with the symbol has been already compiled as dll. here is the buildlog of one of the projects in the solution. I also attach the implementation of a small class which is referenced...
2
5317
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 Ask on python-list@python.org . - Josiah
0
8326
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8743
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8522
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5647
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.