Note, right now, I'm not asking for any help with any of my functions UNLESS they are my problem.
Basically running into another Visual Studio problem. Mind you, I am now using Visual Studio 2005 (and not VC++ Express like before).
I compile, and get these:
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
CTrees.exe : fatal error LNK1120: 1 unresolved externals
I've googled the error and tried what was suggested on the MSDN forums (changing linker properties from console to windows and vice versa, or even setting it to none and manually defining the entry point.) Still get this linker error.
So, anyone got an idea?
Heres my various .cpp and .h files:
Node.h
#pragma once
typedef char STRING[20];
struct NODE
{
STRING data;
NODE *left;
NODE *right;
};
Tree.h
#include "Node.h"
#pragma once
typedef NODE * NODEPTR;
class TREE
{
NODEPTR root;
int count;
void add(NODEPTR & r, STRING str);
void destroy(NODEPTR r);
//actual traversing functions
void preorder(NODEPTR r);
void inorder(NODEPTR r);
void postorder(NODEPTR r);
public:
//basic ADT functions
TREE();
~TREE();
void create();
void destroy();
void add(STRING str);
void remove(STRING &str);
bool empty();
bool full();
//search functions
int getCount();
void search(STRING str);
//traversing wrapper functions
void preorder();
void inorder();
void postorder();
};
Tree.cpp
#define _CRT_SECURE_NO_DEPRECATE
#include <string>
#include <iostream>
#include "Tree.h"
using namespace std;
void TREE::add(NODEPTR & r, STRING str)
{
if( r == 0 )
{
NODEPTR temp;
temp = new NODE;
strcpy(temp->data, str);
temp->left = 0;
temp->right = 0;
r = temp;
}
else if( str < r->data )
add(r->left, str);
else
add(r->right, str);
}
void TREE::destroy(NODEPTR r)
{
if( r!= 0 )
{
destroy(r->left);
destroy(r->right);
delete r;
}
}
void TREE::preorder(NODEPTR r)
{
if( r != 0 )
{
cout << r->data << endl;
inorder(r->left);
inorder(r->right);
}
}
void TREE::inorder(NODEPTR r)
{
if(r != 0)
{
inorder(r->left);
cout << r->data << endl;
inorder(r->right);
}
}
void TREE::postorder(NODEPTR r)
{
if(r != 0)
{
inorder(r->left);
inorder(r->right);
cout << r->data << endl;
}
}
TREE::TREE()
{
TREE::create();
}
TREE::~TREE()
{
TREE::destroy();
}
void TREE::create()
{
root = 0; //initialize the pointer to 0
count = 0; //set counter
}
void TREE::destroy()
{
destroy(root);
}
void TREE::add(STRING str)
{
add(root, str);
}
void TREE::remove(STRING &str)
{
count--;
}
bool TREE::empty()
{
return root == 0;
}
bool TREE::full()
{
bool result = false;
NODEPTR temp; //create a pointer
temp = new NODE; //point temp to a newly create block of RAM
if( temp == 0 ) //0 = no memory left = full
{
result = true;
delete temp;
}
return result;
}
int TREE::getCount()
{
return count;
}
void TREE::search(STRING str)
{
}
void TREE::preorder()
{
preorder(root);
}
void TREE::inorder()
{
inorder(root);
}
void TREE::postorder()
{
postorder(root);
}
Posts
See how many books I've read so far in 2010
Also, I believe the main() function is looked at only if you have a console application. For Windows applications, it's WinMain so make sure that your project settings are for a console application.
I ahve set the setting to console already, and I still get this error.
See how many books I've read so far in 2010
"#include" has nothing to do with linking. All the compiler does when it sees "#include 'Tree.h'" is replace that statement with the text in the file Tree.h. It doesn't do anything about linking object files together. This isn't Java or C#.
See how many books I've read so far in 2010
It looks something like:
1>
Rebuild All started: Project: Test, Configuration: Debug Win32
1>Deleting intermediate and output files for project 'Test', configuration 'Debug|Win32'
1>Compiling...
1>Source1.cpp
1>Compiling manifest to resources...
1>Linking...
1>Embedding manifest...
1>Build log was saved at "file://e:\Temp\Test\Test\Debug\BuildLog.htm"
1>Test - 0 error(s), 0 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
Maybe there's something there that'll give a bit more information?
Rebuild All started: Project: Trees, Configuration: Debug Win32
Deleting intermediate and output files for project 'Trees', configuration 'Debug|Win32'
Compiling...
Spellcheck.cpp
Tree.cpp
Generating Code...
Compiling manifest to resources...
Linking...
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
C:\Documents and Settings\Lucas\My Documents\Visual Studio 2005\Projects\Trees\Debug\Trees.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Lucas\My Documents\Visual Studio 2005\Projects\Trees\Trees\Debug\BuildLog.htm"
Trees - 2 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
See how many books I've read so far in 2010
Rebuild started: Project: Trees, Configuration: Debug|Win32
Command Lines
Creating temporary file "c:\Documents and Settings\Lucas\My Documents\Visual Studio 2005\Projects\Trees\Trees\Debug\RSP00000339962848.rsp" with contents
[
/Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /c /Wp64 /ZI /TP ".\Tree.cpp"
".\Spellcheck.cpp"
]
Creating command line "cl.exe @c:\Documents and Settings\Lucas\My Documents\Visual Studio 2005\Projects\Trees\Trees\Debug\RSP00000339962848.rsp /nologo /errorReport:prompt"
Creating temporary file "c:\Documents and Settings\Lucas\My Documents\Visual Studio 2005\Projects\Trees\Trees\Debug\TMP00000439962848.tmp" with contents
[
1 /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 24 /* RT_MANIFEST */ ".\\Debug\\Trees.exe.embed.manifest"
]
Creating command line "rc.exe /fo".\Debug\Trees.exe.embed.manifest.res" "c:\Documents and Settings\Lucas\My Documents\Visual Studio 2005\Projects\Trees\Trees\Debug\TMP00000439962848.tmp""
Creating temporary file "c:\Documents and Settings\Lucas\My Documents\Visual Studio 2005\Projects\Trees\Trees\Debug\RSP00000539962848.rsp" with contents
[
/OUT:"C:\Documents and Settings\Lucas\My Documents\Visual Studio 2005\Projects\Trees\Debug\Trees.exe" /INCREMENTAL /MANIFEST /MANIFESTFILE:"Debug\Trees.exe.intermediate.manifest" /DEBUG /PDB:"c:\Documents and Settings\Lucas\My Documents\Visual Studio 2005\Projects\Trees\debug\Trees.pdb" /SUBSYSTEM:WINDOWS /MACHINE:X86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
".\Debug\Spellcheck.obj"
".\Debug\Tree.obj"
".\Debug\Trees.exe.embed.manifest.res"
]
Creating command line "link.exe @c:\Documents and Settings\Lucas\My Documents\Visual Studio 2005\Projects\Trees\Trees\Debug\RSP00000539962848.rsp /NOLOGO /ERRORREPORT:PROMPT"
Output Window
Compiling...
Spellcheck.cpp
Tree.cpp
Generating Code...
Compiling manifest to resources...
Linking...
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
C:\Documents and Settings\Lucas\My Documents\Visual Studio 2005\Projects\Trees\Debug\Trees.exe : fatal error LNK1120: 1 unresolved externals
Results
Build log was saved at "file://c:\Documents and Settings\Lucas\My Documents\Visual Studio 2005\Projects\Trees\Trees\Debug\BuildLog.htm"
Trees - 2 error(s), 0 warning(s)
See how many books I've read so far in 2010
Say you're including a header file, node.h.
If you structure your .h file this way, you'll know for certain that your .h file is actually being included one time and only one time. Compilers that claim to support #pragma once have been known to screw up and cause linker problems (at least it was common in my university).
I have no idea if it will solve your problem or not, but it's worth a shot.
As far as the #pragma once issue, I've not been taught one way or the other as far as #ifndef, #pragma, etc. It's just there when I "Add class," it builds the .cpp and .h file and puts the #pragma in there. I've done projects with multiple files before and the #pragma once never caused any errors.
See how many books I've read so far in 2010
See where it goes /SUBSYSTEM:WINDOWS ?
It should be /SUBSYSTEM:CONSOLE
Now, you said you've since recreated the project, so could you check to make sure that the SUBSYSTEM is set to CONSOLE by looking into your BuildLog.htm file again?
If not, try recreating the project by going:
File -> New -> Project -> Visual C++ -> Win32 -> Win32 Console Application
This should pop up a new window, go into "Application Settings"
Application Type: Console application
Additional Options: Only check "Empty Project"
Add common header files for: Don't check anything here
Finish
And add all your files again.
Re: #pragma once - it's a header protection method that's specific to Visual C++. At this stage, I wouldn't worry about it since you're just learning the language, and your programmes aren't intended to be portable. Really, at this stage, I believe that you just need to keep in mind that #pragma once won't necessarily work on other compilers.
Wierd, I had changed that option before, and I still got the same error. Maybe there was something else going on before I recreated it. Hmm, whatever. Thanks.
See how many books I've read so far in 2010