Results 1 to 3 of 3

Thread: Socket error

  1. #1
    Join Date
    Feb 2014
    Posts
    7

    Default Socket error

    Hello guys,
    I would like to use the Mavlink protocol inside of my QT GUI.
    I defined #include "winsock2.h" to use the SOCKET structure. But I am getting error that socketconnectio is already defined.


    Qt Code:
    1. int bytes_sent;
    2. #define DEFAULT_PORT 14550
    3. char target_ip[100];
    4.  
    5. SOCKET ConnectSocket;
    6. int iResult;
    7. typedef int socklen_t;
    8.  
    9.  
    10. void socketconnection()
    11. {
    12. strcpy(target_ip, "127.0.0.1");
    13.  
    14. //----------------------
    15. // Declare and initialize variables.
    16. int iResult;
    17. WSADATA wsaData;
    18.  
    19. ConnectSocket = INVALID_SOCKET;
    20. struct sockaddr_in clientService;
    21. // Initialize Winsock
    22. iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
    23. if (iResult != NO_ERROR) {
    24. cout<<"WSAStartup failed with error: "<< iResult<<endl;
    25. }
    26. ….
    To copy to clipboard, switch view to plain text mode 
    etc


    error LNK2005: "int bytes_sent" (?bytes_sent@@3HA) is already defined in main.obj definiert.
    error LNK2005: "unsigned int ConnectSocket" (?ConnectSocket@@3IA) is already defined in main.obj definiert.
    error LNK2005: "int iResult" (?iResult@@3HA) is already defined in main.obj definiert.
    error LNK2005: "char * target_ip" (?target_ip@@3PADA) is already defined in main.obj definiert.
    error LNK2005: "void __cdecl socketconnection(void)" (?socketconnection@@YAXXZ) is already defined in main.obj definiert.
    error LNK2005: "void __cdecl closesocket(void)" (?closesocket@@YAXXZ) is already defined in main.obj definiert.
    error LNK2005: "void __cdecl mavlinksend(void)" (?mavlinksend@@YAXXZ)is already defined in main.obj definiert.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Socket error

    Any reason for not using QTcpSocket or QUdpSocket (whatever applies here)?

    Cheers,
    _

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Socket error

    The error messages tell you the problem. The four global variables you are defining in this file are also defined in main.cpp (or whatever file compiled to main.obj). Taht os, you are asking the compiler to allocate space fro these variables in two distinct places... Probably a header file and cpp file.

    This has nothing to do with Qt.

Similar Threads

  1. socket error ProxyProtocolError
    By Talei in forum Newbie
    Replies: 1
    Last Post: 7th December 2011, 15:18
  2. Socket Error
    By chethana in forum Qt Programming
    Replies: 0
    Last Post: 16th March 2009, 09:25
  3. HELP ME - socket error in linux
    By donzaza in forum Qt Programming
    Replies: 0
    Last Post: 20th September 2008, 20:20
  4. socket in thread error!
    By alphaboy in forum Qt Programming
    Replies: 6
    Last Post: 18th November 2007, 13:15
  5. Socket bind error
    By rburge in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2007, 01:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.