Trying to use winsock

This is a discussion on Trying to use winsock within the C++ Programming forums, part of the General Programming Boards category; When I try to compile a project with winsock function DoWinsock I get this error: Code: [Linker error] undefined reference ...

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    Trying to use winsock

    When I try to compile a project with winsock function DoWinsock I get this error:
    Code:
      [Linker error] undefined reference to `DoWinsock(char const*, int)'
    libwsock32.a is already included...

  2. #2
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Tell us your OS and compiler (I'm guessing Linux / UNIX and GCC judging by libwsock32.a) and post up your code so far.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Windows 98SE, Dev-C++

  4. #4
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Try linking this library as well: libws2_32.a. I am pretty sure that there are two different libraries you need to link for all the Winsock functions to "be defined". I'm sure you are including the winsock header file?
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  5. #5
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Yes, I'm sure I included winsock header file (winsock.h) and I already tried to link both libraries (libwsock32.a and libws2_32.a). Didn't help...

  6. #6
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    I know someone who had a similar incident once, apparently his winsock headers were buggered, but I doubt it's that.
    What version are you using?
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  7. #7
    Registered User
    Join Date
    May 2005
    Posts
    28
    Is DoWinsock() even an API function Because to me it looks like you either called a function that was declared after the function it was called in and youf ailed to prototype it.

    for example:
    Code:
    void a()
    {
        b();
    }
    
    void b()
    {
        //whatever
    }
    Would nto work and would give you a link error, you need to add:

    Code:
    void b();
    to the top of the file for that to work properly. I think that is your problem.

  8. #8
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Undefined reference should mean its defined, but can't find the library function for it...
    I don't know exactly, not winsock 2, some older version...
    Last edited by maxorator; 10-09-2005 at 10:30 AM.

  9. #9
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Code:
    extern int DoWinsock(const char* pcHost, int nPort);

  10. #10
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    I need to link the project with wsock32.lib to get it to work so I guess you could try that?
    It'll probably be version 1.0 (I think) then.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  11. #11
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Where did you find this function? I'm pretty sure it isn't part of the winsock library...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  12. #12
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    MSDN doesn't have anything on it, but I found several sites that talk about it like it is.

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,832
    From what I can make out, it's a member function of some winsock wrapper class which someone created.
    You need the whole class .cpp/.h or .lib/.h or .dll/.h combo in order to make the code work.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  14. #14
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Perhaps you should read the FAQ before blindly using it's code. http://tangentsoft.net/wskfaq/exampl...sic-client.cpp

  15. #15
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    seems like a poorly named function too, just how does one do winsock?

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, 05:00 PM
  3. Winsock - Where do i start?
    By Brain Cell in forum Networking/Device Communication
    Replies: 5
    Last Post: 02-14-2005, 01:39 PM
  4. 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
  5. winsock
    By pode in forum Networking/Device Communication
    Replies: 2
    Last Post: 09-26-2003, 01:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21