Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: LNK 2018 errors

Hybrid View

  1. #1
    Join Date
    Nov 2006
    Location
    Texas
    Posts
    521

    LNK 2018 errors

    Im doing some review of pointers and references. I have a book called "C++ How to Program". Im typing the examples into the compiler. Just reading the code dose'nt to much for me so I type it in and keeps me from getting bored. But I try to run the example I get some LNK errors.

    8.11 code
    Code:
    // Fig 8.11
    // Printing a string one character at a time using
    // a non=constant pointer to constant data.
    #include <iostream>
    using std::cout;
    using std::endl;
    
    void printCharacters(const char *); // print using pointer to const data
    
    void main()
    {
    	const char phrase[] = "print characters of a string";
    
    	cout << "The string is: \n";
    	printCharacters(phrase); // print characters in phrase
    	cout << endl;
    
    } // main() end
    
    // sPtr can be modified, but it cannot modify the character to which 
    // it points, i.e., sPtr is a "read-only" pointer
    void printCharacters(const char *sPtr)
    {
    	for (; *sPtr != '\0'; sPtr++) // no initialization
    		cout << *sPtr; // display character without modification
    }// method() end
    Book code
    Code:
    #include <iostream>
    using std::cout;
    using std::endl;
    
    int cubeByValue(int); // prototype
    
    int main()
    {
    	int number = 5;
    
    	cout << "The original value of number is " << number;
    
    	number = cubeByValue(number); // pass number by value to cubeByValue
    	cout << "The new value of number is" << number << endl;
    	return 0; // indicates successful termination
    
    }//main() end
    
    // calculate and return cube of integer argument
    int cubeByValue(int n)
    {
    	return n * n * n; // cube local variable n and return result
    }//cubebyvalue end
    LNK errors

    Code:
    1>MSVCRTD.lib(crtexew.obj) : error LNK2019: 
    unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
    
    1>d:\Documents and Settings\dod\My Documents\Visual Studio 2008\Projects\Figure8.11\Debug\Figure8.11.exe : 
    fatal error LNK1120: 1 unresolved externals
    
    1>MSVCRTD.lib(crtexew.obj) : error LNK2019: 
    unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
    1>d:\Documents and Settings\dod\My Documents\Visual Studio 2008\Projects\Book\Debug\Book.exe : fatal error LNK1120: 
    1 unresolved externals
    To me it looks correct, it baffles me as to why its not working.

  2. #2
    Join Date
    Aug 2004
    Location
    little rock arkansas
    Posts
    3,482

    Talking

    looks like you made a Windows application project instead of a dos project

    there is a setting to change in properties so you can make it compilable
    i forgot what it was though
    ME WANT AGENTS ME WANT AGENTS ME WANT AGENTS

  3. #3
    Join Date
    Nov 2006
    Location
    UK
    Posts
    3,774
    If you go to project options, Application - change it to console app
    Delphi !ROCKS!
    Got a question? Read this first!!!
    "You gotta help us, Doc. We've tried nothin' and we're all out of ideas"

  4. #4
    Join Date
    Nov 2006
    Location
    Texas
    Posts
    521
    Having the same problem again. I made sure it was a console app this time. I couldn't find the setting to change form windows to console. Heres the code and errors

    Code:
    // Fig. 8.28
    // Multipurpose sorting program using function pointers
    #include <iostream>
    using std::cout;
    using std::cin;
    using std::endl;
    
    #include <iomanip>
    using std::setw;
    
    // protoypes
    void selectionSort(int [], const int, bool (*)(int, int));
    void swap(int *const, int * const);
    bool ascending(int, int ); // implements ascending order
    bool descending (int, int); // implements descending order
    
    void main()
    {
    	const int arraySize = 10;
    	int order; // 1 = ascending, 2 = descending
    	int counter; // array index
    	int a[arraySize] = {2,6, 4, 8, 10, 12, 89, 68, 45, 37};
    
    	cout << "Enter 1 to sort in ascending order,\n"
    		<< "Enter 2 to sort in descending order: ";
    	cin >> order;
    	cout << "\nData items in original order\n";
    
    	// output original array
    	for (counter = 0; counter < arraySize; counter++)
    		cout << setw(4) << a[counter];
    
    	// sort array in ascending order; pass function ascending
    	// as an argument to specify ascending sorting order
    	if(order == 1)
    	{
    		selectionSort(a, arraySize, ascending);
    		cout << "\nData items in ascending order\n";
    	}
    	// sort array in descending order; pass function descending
    	// as an argument to specify descending sorting order
    	else
    	{
    		selectionSort(a, arraySize, descending);
    		cout << "\nData items in descending order\n";
    	}
    
    	// output sorted array
    	for (counter = 0; counter < arraySize; counter++)
    		cout << setw(4) << a[counter];
    
    	cout << endl;
    }// main end
    
    // multipurose selection sort; the parameter compare is a pointer to 
    // the comparison function that determines the sorting order
    void selectionSort(int work[], const int size,
    				   bool (*compare)(int, int))
    {
    	int smallestOrLargest; // index of smallest (or largest) element
    
    	// loop over size - 1 elements
    	for (int i = 0; i < size - 1; i++)
    	{
    		smallestOrLargest = i; // first index of remaining vector 
    
    		// loop to find index of smallest (or largest) element
    		for (int index = i + 1; index < size; index++)
    			if(!(*compare)(work[smallestOrLargest], work [index]))
    				smallestOrLargest = index;
    
    		swap(&work[smallestOrLargest], &work[i]);
    	}
    }
    
    // determine whether element a is less than
    // element b for an ascending order sort
    bool ascending(int a, int b)
    {
    	return a < b; // returns true if a is less than b
    }
    
    // determine whether element a is greater than 
    // element b for a descending order sort
    bool desending(int a, int b)
    {
    	return a > b; /// returns true if a is greater thaan b
    }
    errors

    Code:
    Example.obj : error LNK2019: unresolved external symbol "bool __cdecl descending(int,int)" 
    (?descending@@YA_NHH@Z) referenced in function _main
    
    Example.obj : error LNK2019: unresolved external symbol "void __cdecl swap(int * const,int * const)"
     (?swap@@YAXQAH0@Z) referenced in function "void __cdecl selectionSort(int * const,int,bool (__cdecl*)(int,int))" 
    
    (?selectionSort@@YAXQAHHP6A_NHH@Z@Z)

  5. #5
    Join Date
    Nov 2006
    Location
    UK
    Posts
    3,774
    Which version of VS do you have? As I explained where it was in 2008, I have others..
    Delphi !ROCKS!
    Got a question? Read this first!!!
    "You gotta help us, Doc. We've tried nothin' and we're all out of ideas"

  6. #6
    Join Date
    Nov 2006
    Location
    Texas
    Posts
    521
    I have 2k8 express. When I go to project I see Figure8.28 properties -> then a window pops with various settings.

  7. #7
    Join Date
    Nov 2006
    Location
    UK
    Posts
    3,774
    You should get a new window in the code area, with lables like Application, Build, Build Events, Debug, Resources..

    If you look in application (as mentioned before) Output type is on the right.
    Delphi !ROCKS!
    Got a question? Read this first!!!
    "You gotta help us, Doc. We've tried nothin' and we're all out of ideas"

  8. #8
    Join Date
    Nov 2006
    Location
    Texas
    Posts
    521
    All I have under Project is (projectname)Properties. I dont get a window like the one you describe. Is that a retail only item?

  9. #9
    Join Date
    Nov 2006
    Location
    UK
    Posts
    3,774
    I have express at work, but Im 99% sure it looks exactly the same.. Even my Vs 2005 express has the same

    Can you do me a pic? coz I swear somethings missing.
    Delphi !ROCKS!
    Got a question? Read this first!!!
    "You gotta help us, Doc. We've tried nothin' and we're all out of ideas"

  10. #10
    Join Date
    Nov 2006
    Location
    Texas
    Posts
    521

Page 1 of 2 12 LastLast

Posting Permissions

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