I want this structure variable as well as all the structure elements to be used in multiple source(.cpp) files. I did like this and getting did like this and getting following errors. I am using vs2010. Please help me i am a newbie.

Error
2
error LNK2001: unresolved external symbol "struct setthresholdfinedflb set_thresholdfinedflb" (?set_thresholdfinedflb@@3Usetthresholdfinedflb@@A)
C:\Users\jeevan\Desktop\socket_struct\socket\socket\FineDfThresholdLB.obj

Error 3 error LNK2019: unresolved external symbol "struct setthresholdfinedflb set_thresholdfinedflb" (?set_thresholdfinedflb@@3Usetthresholdfinedflb@@A) referenced in function "public: __thiscall CsocketDlg::CsocketDlg(class CWnd *)" (??0CsocketDlg@@QAE@PAVCWnd@@@Z)
C:\Users\jeevan\Desktop\socket_struct\socket\socket\socketDlg.obj

Error 4 error LNK2019: unresolved external symbol "public: void __thiscall CsocketDlg::OnReceive(void)" (?OnReceive@CsocketDlg@@QAEXXZ) referenced in function "protected: virtual void __thiscall mysocket2::OnReceive(int)" (?OnReceive@mysocket2@@MAEXH@Z)
C:\Users\jeevan\Desktop\socket_struct\socket\socket\mysocket2.obj

Error 5 error LNK1120: 2 unresolved externals
C:\Users\jeevan\Desktop\socket_struct\socket\Debug\socket.exe

// socketDlg.h : header file
//

#pragma once
#include "mysocket1.h"
#include "mysocket2.h"
#include "FineDfThresholdLB.h"

 struct setthresholdfinedflb{
        unsigned char sof_lb;
        //unsigned char msg_type;
        unsigned short command_code;
        unsigned short sequence_no;
        unsigned int msg_length;
        unsigned char eof_lb;
        unsigned char threshold_value;
    };
extern  setthresholdfinedflb set_thresholdfinedflb;
// CsocketDlg dialog
class CsocketDlg : public CDialogEx
{
// Construction
public:
    CsocketDlg(CWnd* pParent = NULL);   // standard constructor

// Dialog Data
    enum { IDD = IDD_SOCKET_DIALOG };

    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support


// Implementation
protected:
    HICON m_hIcon;

    // Generated message map functions
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    DECLARE_MESSAGE_MAP()
public:
    CButton m_ctlConnect;
    CString m_strMessage;
    CString m_strName;
    int m_iPort;
    CListBox m_ctlRecvd;
    CListBox m_ctlSent;
    int m_iType;
    afx_msg void OnRType();
    afx_msg void OnServer();

public:
    afx_msg void OnClickedBconnect();

    void OnAccept(void);
    void OnConnect(void);
    void OnSend(void);
    void OnReceive(void);
    void OnClose(void);
private:

    mysocket2 m_sConnectSocket;
    mysocket2 m_sListenSocket;
public:
    afx_msg void OnClickedBsend();
    afx_msg void OnClickedBclose();
private:
    CFineDfThresholdLB m_dFineDfThresholdLB;
public:
    afx_msg void OnClickedFinedfthresholdlbbutton();
};

Edited 2 Years Ago by jeevan reddy

You need to show us the cpp files, and the command you used to compile them.

The linking errors that you get are telling me that there is no definition for your set_thresholdfinedflb global variable, and that there is no definition for the OnReceive() function. When you have a global extern variable declaration in a header file, you need to have a corresponding global variable definition in a cpp file. A global variable definition is simply this:

setthresholdfinedflb set_thresholdfinedflb;

(without the "extern" keyword)

As for the OnReceive function, I guess it is missing from your cpp file. But I don't know that. It might have the wrong signature, or its missing the class-name (as in void CsocketDlg::OnReceive(), if you are missing the CsocketDlg part, then the compiler will assume you are just defining a different function (non-member function) called OnReceive).

It might help you to read my tutorial on C++ compilation mechanics to better understand how everything comes together.

thx man receive mistake is mine and yes i defined it in my cpp as u said and it worked. thankyou!

This question has already been answered. Start a new discussion instead.