CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: error LNK2001

  1. #1
    Join Date
    Jan 2005
    Posts
    63

    error LNK2001

    Hi,
    I am a little puzzled about something. I am using msvs 2005 and I tried compiling a program that is a server client program so it uses winsock2.h. Since the program is a win32 console application, I figured I don't need the stdafx.cpp and stdafx.h file that msvs puts in all it's project. So I removed them from the project and took out the include from the main cpp file. Now I am getting this linker error:
    soctest.obj : error LNK2001: unresolved external symbol __imp__accept@12
    soctest.obj : error LNK2001: unresolved external symbol __imp__listen@8

    and a bunch of others

    I disabled "use precompiled headers in options" but I really don't know what is wrong with it. The funny thing is that if I put the stdafx.cpp in the project without using #include "stdafx.h", then I don't get this error. So what gives. Thanks a lot,
    Amish

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: error LNK2001

    Quote Originally Posted by axr0284
    Since the program is a win32 console application, I figured I don't need the stdafx.cpp and stdafx.h file that msvs puts in all it's project.
    Precompiled headers are used for faster compile times, and has nothing to do whether you create console applications or not.

    Quote Originally Posted by axr0284
    soctest.obj : error LNK2001: unresolved external symbol __imp__accept@12
    soctest.obj : error LNK2001: unresolved external symbol __imp__listen@8
    It seems that you forgot to link with "ws2_32.lib".

    - petter

  3. #3
    Join Date
    Jun 2006
    Posts
    645

    Re: error LNK2001

    Try this:
    Use the Visual Studio Menu bar:-

    Project>Settings>

    click the link tab - and in the LHS drop down menu-> try selecting the 3 options i.e. Win32Release, Win32Debug & All Configurations.

    See if it works?

    Regards,
    Bhushan.

  4. #4
    Join Date
    Jan 2005
    Posts
    63

    Re: error LNK2001

    wildfrog was right on the money. After I added ws2_32.lib as an additional library to link in, it worked fine. I was wondering how'd you figure it out and how it is related to stdafx.cpp. Thanks a lot.
    Amish

  5. #5
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: error LNK2001

    Quote Originally Posted by axr0284
    After I added ws2_32.lib as an additional library to link in, it worked fine. I was wondering how'd you figure it out and how it is related to stdafx.cpp. Thanks a lot.
    Well, IMO it's not related to stdafx.cpp/.h but if your project is configured to use precompiled headers then the compiler will look for stdafx.cpp and all code files should have a #include "stdafx.h." as the first line of code.

    The accept/listen errors was solved simply by looking in the documentation. Both functions are part of ws2_32.lib, thus you'll need to link with that file.

    - petter

  6. #6
    Join Date
    Jan 2005
    Posts
    63

    Re: error LNK2001

    I see. Thanks for taking the time to help me out.
    Amish

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