Linker error using Dev-C++

Started by
9 comments, last by Scourage 14 years, 10 months ago
Hello i'm having a problem compiling a simple application. i get this error messages when trying to compile the source code. [Linker error] undefined reference to 'WinMain@16' iD returned 1 exit status What is it that i'm doing wrong? Thank you. Here is the setup file: ac.cpp

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include "account.h"

int main()
{
     Account ac1(200), ac2(300);
     int a;
     cout<<"ac1: "<<ac1.getBalance()<<endl<<"ac2: "<<ac2.getBalance()<<endl;
     cin>>a;
     return 0;
}
file: account.h

class Account{
	public:
      Account(int);
      void credit(int);
	  void debit(int);
	  int getBalance();
			
    private:
		int accountBalance;
};
file: account.cpp

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include "account.h"

Account::Account(int balance)
{
	accountBalance = balance;
	if(accountBalance < 0)
	{
		accountBalance = 0;
		cout<<"incorect balance input. Balance was initiated at "<<accountBalance<<endl;
	}
}
      
void Account::credit(int balToAdd)
{
	if(balToAdd >= 0)
		accountBalance += balToAdd;
	else cout<<"Nothing was added."<<endl;
}

void Account::debit(int balToSubstract)
{
	int newBal = accountBalance - balToSubstract;
	if(balToSubstract >= 0 && newBal >= 0)
		accountBalance = newBal;
	else cout<<"Nothing was substracted."<<endl;
}
int Account::getBalance()
{
	return accountBalance;
}
Advertisement
You need to compile as a console application (GUI applications use WinMain instead of main). However, while you are at it, consider moving to a new IDE - Dev-C++ is hopelessly outdated.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

I'll just throw in a bit on the switch to a new development environment:

I used to be a Dev C++ user, and I was that way for years. Just recently, I moved to a Vista 64 bit OS to accomidate 4 gigs of RAM, and Dev C++ would not work with it. I finally decided to make the jump to VC++ 2005 Express, and it was the best thing I ever did, IDE wise. I used to have problems getting the Platform SDK with all the include files going properly, but this time, it worked perfectly. Go over to VC++ Express and download it. This will be enough to work with Console programs, but when you move on to needing more include files, find the Platform SDK. For some reason, I am having problems finding it (No coffee yet this morning), so simply do a google search for "Platform SDK" and it should be one of the first links. It will be on the microsoft site. Good luck!
The reason why i don't use vc++ 1. really i don't like ms products. 2. I feel that using vc++ will get me into a bad habbit into learing c++ for win only, while my objective is create code as portable as possible.

Keep in mind i just started getting serious with C++ so any suggestion for IDE as well as my paranoias above are welcome :)
Quote:Original post by AluminX
1. really i don't like ms products.
Not sure what to do with that. It's like saying "I don't like yellow things". What's your problem with Minesweeper?
Quote:2. I feel that using vc++ will get me into a bad habbit into learing c++ for win only, while my objective is create code as portable as possible.
That's not really an issue for IDEs. It's more of a libraries thing.
Quote:Original post by AluminX
The reason why i don't use vc++ 1. really i don't like ms products. 2. I feel that using vc++ will get me into a bad habbit into learing c++ for win only, while my objective is create code as portable as possible.

Keep in mind i just started getting serious with C++ so any suggestion for IDE as well as my paranoias above are welcome :)


If you haven't used Visual C++ then you don't know what you're missing. And you're being foolish to think that merely using Visual C++ will get you into the bad habit of learning c++ for windows only. You can write standard compliant code in Visual C++. Unless you specifically look for the non-standard extensions or choose to program with Microsoft's included libraries you have nothing to fear.

If that still doesn't sway you you should still avoid Dev-CPP and use the IDE Code::Blocks. It is quite capable to develop in and much better than what you're using now.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Quote:Original post by Sneftel
That's not really an issue for IDEs. It's more of a libraries thing.

I thought that was a compiler thing no?
Quote:Original post by AluminX
Quote:Original post by Sneftel
That's not really an issue for IDEs. It's more of a libraries thing.

I thought that was a compiler thing no?
No.

There are certainly things that need to be taken into consideration when moving from compiler to compiler, such as non-standard language extensions and differences in how the compiler coforms to (or doesn't conform to) the C++ standard. But these sorts of issues are more or less unavoidable (especially given the complexity of the C++ language), and there are almost always ways to work around them.

In short, using Visual Studio will in no way tie you to writing Windows-specific code. (I and many others here develop cross-platform applications using Visual Studio for Windows, and other IDEs/compilers for other platforms, without any difficulties.)
Practically, it is probably a good idea to set your VC++ to strict standards compliance, and plug in a different vendor's compiler (also on strict standards compliance mode), if you want to avoid learning VC++isms.

That (the standards-extensions and bugs in VC++), and the fact that VC++ has a proprietary "makefile" system, and the editor isn't a "real editor" (heh), etc -- are about the only problems with learning to code using VC++.
This is great.
Well thank you to everyone. I didn't think i would get some much help and insight from that simple error message :)

Thank you!

This topic is closed to new replies.

Advertisement