Thread: [Dev-C++] undefined reference error?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Zachary U. <ne...@st...> - 2002-12-14 08:13:43
|
Hi,
I created empty project, I added 2 files to it: stack.h and stack.cpp
When I compile I get weird error. It is very obtuse and does not even give
a Line number of the error! Here is error:
Compiler: Default compiler
Building Makefile: "C:\c++\PSCpp4E\ch15\Makefile.win"
Executing make...
make.exe -f "C:\c++\PSCpp4E\ch15\Makefile.win" all
g++.exe -c stack.cpp -o stack.o
-I"C:/DEV-CPP/include" -I"C:/DEV-CPP/include"
g++.exe stack.o -o "Stack.exe"
-L"C:/DEV-CPP/lib" -I"C:/DEV-CPP/include" -I"C:/DEV-CPP/include"
C:/DEV-CPP/lib/libmingw32.a(main.o)(.text+0x7f):main.c: undefined reference
to `WinMain@16'
Execution terminated
Please help someone.
Below are source files.
Regards,
Zach
//This is the header file stack.h. This is the interface for the class Stack,
//which is a class for a stack of symbols.
#ifndef STACK_H
#define STACK_H
namespace stacksavitch
{
struct StackFrame
{
char data;
StackFrame *link;
};
typedef StackFrame* StackFramePtr;
class Stack
{
public:
Stack( );
//Initializes the object to an empty stack.
Stack(const Stack& a_stack);
//Copy constructor.
~Stack( );
//Destroys the stack and returns all the memory to the freestore.
void push(char the_symbol);
//Postcondition: the_symbol has been added to the stack.
char pop( );
//Precondition: The stack is not empty.
//Returns the top symbol on the stack and removes that
//top symbol from the stack.
bool empty( ) const;
//Returns true if the stack is empty. Returns false otherwise.
private:
StackFramePtr top;
};
}//stacksavitch
#endif //STACK_H
//This is the implementation file stack.cpp.
//This is the implementation of the class Stack.
//The interface for the class Stack is in the header file stack.h.
#include <iostream>
#include <cstddef>
#include "stack.h"
using namespace std;
namespace stacksavitch
{
//Uses cstddef:
Stack::Stack( ) : top(NULL)
{
//Body intentionally empty.
}
//Uses cstddef:
Stack::Stack(const Stack& a_stack)
{
if (a_stack.top == NULL)
top = NULL;
else
{
StackFramePtr temp = a_stack.top;//temp moves
//through the nodes from top to bottom of
//a_stack.
StackFramePtr end;//Points to end of the new stack.
end = new StackFrame;
end->data = temp->data;
top = end;
//First node created and filled with data.
//New nodes are now added AFTER this first node.
temp = temp->link;
while (temp != NULL)
{
end->link = new StackFrame;
end = end->link;
end->data = temp->data;
temp = temp->link;
}
end->link = NULL;
}
}
Stack::~Stack( )
{
char next;
while (! empty( ))
next = pop( );//pop calls delete.
}
//Uses cstddef:
bool Stack::empty( ) const
{
return (top == NULL);
}
//Uses cstddef:
void Stack::push(char the_symbol)
{
StackFramePtr temp_ptr;
temp_ptr = new StackFrame;
temp_ptr->data = the_symbol;
temp_ptr->link = top;
top = temp_ptr;
}
//Uses iostream:
char Stack::pop( )
{
if (empty( ))
{
cout << "Error: popping an empty stack.\n";
exit(1);
}
char result = top->data;
StackFramePtr temp_ptr;
temp_ptr = top;
top = top->link;
delete temp_ptr;
return result;
}
}//stacksavitch
Zachary Uram
John 3:16
<><
|
|
From: Zodiaq <zo...@ac...> - 2002-12-14 10:11:44
|
Hello Zachary and all Dev-C++ users, Saturday, December 14, 2002, 9:12:08 AM, Zachary wrote as follows: ZU> Hi, ZU> I created empty project, I added 2 files to it: stack.h and stack.cpp ZU> When I compile I get weird error. It is very obtuse and does not even give ZU> a Line number of the error! Here is error: Hmm... to run ANY project you need an entry point - special function that acts as begining of application... for console apps you need: int main( ) ,and for GUI Apps you need: int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) And if added ONLY these two files it wont run, or compile properly because there is no entry point - I can't see there int main nor winmain... and It looks like you have chosen WinMain project but the code uses std::iostream so you better choose console project... ZU> Zachary Uram ZU> John 3:16 -- regards, Zodiaq |
|
From: Sebastien M. <seb...@te...> - 2002-12-15 09:19:44
|
Just I don't really agree about your definition of WinMain and main :) I would say, main is the standard, and WinMain is used by windows. According to which libraries you use to compile, you should be able to use main or WinMain under windows for both application (graphical and text). By default I think that main compiler under windows use WinMain, that's why you get the problem. But anyway I'm sure you can do graphical application using a simple main as an entry point. Sebastien. On Sat, Dec 14, 2002 at 11:11:33AM +0100, Zodiaq wrote: > Hello Zachary and all Dev-C++ users, > > Saturday, December 14, 2002, 9:12:08 AM, Zachary wrote as follows: > > ZU> Hi, > > ZU> I created empty project, I added 2 files to it: stack.h and stack.cpp > > ZU> When I compile I get weird error. It is very obtuse and does not even give > ZU> a Line number of the error! Here is error: > > Hmm... to run ANY project you need an entry point - special function > that acts as begining of application... for console apps you need: > int main( ) > ,and for GUI Apps you need: > int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) > > And if added ONLY these two files it wont run, or compile properly > because there is no entry point - I can't see there int main nor > winmain... and It looks like you have chosen WinMain project but the > code uses std::iostream so you better choose console project... > > ZU> Zachary Uram > ZU> John 3:16 > > > -- > regards, Zodiaq > > > > ------------------------------------------------------- > This sf.net email is sponsored by: > With Great Power, Comes Great Responsibility > Learn to use your power at OSDN's High Performance Computing Channel > http://hpc.devchannel.org/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > -- Time remaining: 28 weeks 1 days 21 hours 23 minutes |