Thread: Can't compile this with VC 6.0

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    9

    Question Can't compile this with VC 6.0

    I took this code from Andre LaMothe's Game Dev Series. The book is the Game Programming All-In-One by Bruno Miguel Teixeira de Sousa.
    I can get this code to compile with the GNU g++ compiler, but the VC 6.0 compiler just won't do it. It give me a link error of:
    LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
    Debug/IVA.exe : fatal error LNK1120: 1 unresolved externals

    What kinda funny is that the code was written (according to the writer) with VC in mind.

    Code:
    #include <iostream>
    
    using std::cout;
    using std::endl;
    
    void CalcIVA(long Money, double IVA = 0.17);
    
    int main()
    {
    	cout << "Specifying the IVA value: $1000\n";
    	CalcIVA (1000, 0.12);
    	cout << "Using default IVA value: $1000\n";
    	CalcIVA (1000);
    
    	return 0;
    }
    
    void CalcIVA(long Money, double IVA)
    {
    	double MoneyWithIVA;
    	MoneyWithIVA = Money * IVA;
    
    	cout << "Money after IVA at " << IVA << " is " << MoneyWithIVA << endl;
    }
    Is there something wrong with the code, or is there something wrong with my VC 6.0 setup?

    Thanks.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Any program written can be made to have linker errors with VC++. You didn't choose the right project settings when you created your project. You should have chosen Win32 console application.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    9
    It is a Win32 Console Project.
    Just to be sure I went back and checked it. I think the problem is somewhere is the namespace declarations or with the header files. It seems like VC 6.0 REALLY likes you to include the "stdafx.h" header, but I thought I could skip this if I used namespaces.
    If I pull out the namespaces and include the stdafx.h header I can get it to work. However, why doesn't anyone ever mention using this header?
    Is there a way around using it for portability's sake?

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    "Just to be sure I went back and checked it."

    How did you do that?

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    9
    To check the code again, I copied it off of the CD (copy/paste) then ran it again.
    It looks like the linker problem was do to me possibly selecting the wrong project type. Oops! I was getting a different error message when I tried this code the other day.

    What's totally confusing is I JUST ran the code again to copy/paste the error message, and it ran fine without the stdafx.h and with the namespaces. I guess that answers my question. There has GOT to be something wrong with my installation of Visual Studio!

    Thanks for all of the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling x64 code in VC++ 6.0?
    By cpjust in forum Windows Programming
    Replies: 7
    Last Post: 07-29-2008, 09:36 AM
  2. Finalizing Projects in Visual C++ 6.0
    By jdm in forum C++ Programming
    Replies: 1
    Last Post: 04-19-2004, 08:52 PM
  3. question about .net to 6.0 change causing errors
    By jverkoey in forum C++ Programming
    Replies: 17
    Last Post: 03-23-2004, 10:45 AM
  4. adding a header file in VC 6.0
    By stimpyzu in forum C++ Programming
    Replies: 5
    Last Post: 10-28-2002, 02:26 AM
  5. VC 6.0 compiled error
    By alan4100 in forum Windows Programming
    Replies: 4
    Last Post: 09-17-2001, 03:10 PM