Results 1 to 5 of 5

Thread: [RESOLVED] Linking error

  1. #1

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Resolved [RESOLVED] Linking error

    I want a code that open a text file and able to write few text on it. Here is the code I have written.

    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    int main()
    {
    	ofstream file;
    	file.open ("example.txt");
    
    	if(file.is_open())
    		{
    			file << "Write a text line";
                		file.close();
    		}
    	else
    		{
    			file << "Unable to wirte text";
    		}
    	return 0;
    }
    When I compiled it, gives the following error.

    Compiling...
    rbf.cpp
    Linking...
    LIBCD.lib(wincrt0.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function _WinMainCRTStartup
    Debug/ReadFile.exe : fatal error LNK1120: 1 unresolved externals
    What's wrong there. Can you guys help me.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Linking error

    It appears you've created a Win32 application, and haven't specified the correct entrypoint.

    An entrypoint, is where your code begins its main execution (hence, the function name "main"). Basic console applications, use this:
    Code:
    int main()
    {
        return 0;
    }
    Win32 applications however, need to pass some information into the entrypoint, like this:
    Code:
    int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
    {
    
    }
    Make sure you take note of what the tutorials say.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Linking error

    If I replace my code with your given, is it ok.

    By the way, I refer the following tutorial to test this.

    http://www.cplusplus.com/doc/tutorial/files.html
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  4. #4
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Linking error

    That tutorial assumes you're writing a console application, or, at the very least, an application that can run with the entrypoint "main".

    Make sure, before you put any code anywhere, that you have created a Console Application. At the moment, you have created a Windows Application, and tried to put 'console code' inside it.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  5. #5

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: Linking error

    Ok, thanks. I'll try it.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

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