Thread: how do i "link the winsock library??"

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    114

    how do i "link the winsock library??"

    In the tutorial
    http://www.hal-pc.org/~johnnie2/winsock.html
    it says this:

    "Remember that any code presented in this tutorial should be linked with the Winsock library, usually wsock32.lib or something similarly named."


    how exactly do" i link the winsock library??"

    #include wsock32.lib???
    #include wsock32.h??

    doesnt work

    wsock32.lib's in binary
    using vc++ 6.0 btw

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Add your library to the list already there
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    You can do that, but I prefer to use this (before #including winsock.h)

    Code:
    #pragma comment(lib, "wsock32.lib")
    Only because it makes it easier to transer code from IDE to IDE (or compiler). Also because I hate going from mouse to keyboard alot.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    What makes you think ANO compiler will pay any attention to that pragma?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Well it works with VC and I'm pretty sure it works with DevCpp. Besides, I use it mostly so that I don't have to mess with windows and go right to typing.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  6. #6
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Besides, when working with other people, if it does work, then they won't have to mess with settings and if it doesn't work, then it should be a clue that they have to mess with settings.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    114
    #include <windows.h>
    #pragma comment(lib, "wsock32.lib")

    #include <winsock.h>
    #include <stdio.h>



    this is what i put at the top but it doesnt work


    --------------------Configuration: server - Win32 Debug--------------------
    Compiling...
    server.c
    Linking...
    LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/server.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > unresolved external symbol _main
    Your code begins with winmain(), which is a GUI project

    But you've set things up to be a console project which always starts at main()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    Originally posted by neandrake
    Besides, when working with other people, if it does work, then they won't have to mess with settings and if it doesn't work, then it should be a clue that they have to mess with settings.
    That pragma is not supported by GCC (unless it changed recently). Since DevC++ uses gcc ("mingw") I would think that it won't work.
    Generally, stuff in a pragma is non standard and should be used with caution.

    Personally, I would love to see a preprocessor command to link a library included in the standard.
    I still dream of C++ unit-support to get rid of seperate header files and libraries...
    [code]

    your code here....

    [/code]

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    The other problem with tricks like this
    #pragma comment(lib, "wsock32.lib")

    Is what do you do when you want to link with a debug library in a debug build, and a release library in a release build.

    Let me see now, I know, I'll put the correct name for the library in the link options for each type of build.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>#include <winsock.h>
    Since all Windows versions from 98 up support Winsock2, and 95 can get the upgrade, I'd suggest using winsock2.h. Also, then I think you need to get rid of the #include <windows.h>, to avoid redefinition errors - if it works on your computer, fine, but if you get those weird errors, you'll know where to look (winsock2.h completely replaces windows.h I believe).

    >>Is what do you do when you want to link with a debug library in a debug build, and a release library in a release build.
    Just link the release build then... But seriously, I never even knew that there were such things as "debug libraries"

    I'd suggest doing whatever you like... I personally usually use #pragma, because then it gets linked if/when I include my header file for my sockets class, meaning I need about 6 fewer mouse clicks and quite a bit fewer keyboard strokes to get started with using Winsock in my program Of course Salem, what you said has validity too, but I'm too lazy to bother with The Tab.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  12. #12
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Originally posted by Hunter2
    I'd suggest doing whatever you like... I personally usually use #pragma, because then it gets linked if/when I include my header file for my sockets class, meaning I need about 6 fewer mouse clicks and quite a bit fewer keyboard strokes to get started with using Winsock in my program Of course Salem, what you said has validity too, but I'm too lazy to bother with The Tab.
    Which is my preference, I thought was clear, but, yea, so, yea.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Winsock issues
    By tjpanda in forum Windows Programming
    Replies: 3
    Last Post: 12-04-2008, 08:32 AM
  2. Winsock Messaging Program
    By Morgul in forum Windows Programming
    Replies: 13
    Last Post: 04-25-2005, 04:00 PM
  3. Where do I initialize Winsock and catch messages for it?
    By Lithorien in forum Windows Programming
    Replies: 10
    Last Post: 12-30-2004, 12:11 PM
  4. weird winsock output and winsock 2 not working
    By whackaxe in forum Networking/Device Communication
    Replies: 4
    Last Post: 07-09-2004, 11:10 AM
  5. winsock
    By pode in forum Networking/Device Communication
    Replies: 2
    Last Post: 09-26-2003, 12:45 AM