CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2012
    Posts
    2

    Unhappy Baffling Link Error

    I'm new to C++ programming and am writing a program to implement an insertion sort in an array. I decided to test out my printArray function before proceeding and keep getting a link error:

    "MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup"

    Here's the code(it's all in one .cpp file):

    Code:
    //main.cpp
    
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    //Function to print out contents of array
    void printArray(const int a[], const int size);
    
    int main(int argc, char* argv[])
    {
    	const int arraySize = 10;
    	int data[arraySize] = {34, 56, 4, 10, 77, 51, 93, 30, 5, 52};
    
    	//Print out contents of usorted Array
    	cout << "Unsorted array:\n";
    	printArray(data, arraySize);
    
    	cout << endl;
    	return 0;
    }
    
    //Function to print out contents of array
    void printArray(const int a[], const int size)
    {
    	for(int i = 0; i < size; i++)
    		cout << setw(5) << a[i];
    }
    I have absolutely no idea what's causing this. I've checked my code over and over and just can't figure out the cause of the link error.

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Baffling Link Error

    You have created a Win32 project instead of a Console project.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  3. #3
    Join Date
    Jun 2012
    Posts
    2

    Re: Baffling Link Error

    I was sure I had selected console. Well it compiles fine if I copy paste it to another new project so I guess I must have checked it as win32 project. Thanks for the help.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured