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 LNK2001: unresolved external symbol "struct setthresholdfinedflb set_thresholdfinedflb" (?set_thresholdfinedflb@@3Usetthresholdfinedflb@@A)

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)

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)

Error 5 error LNK1120: 2 unresolved externals

// 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
    CsocketDlg(CWnd* pParent = NULL);   // standard constructor

// Dialog Data
    enum { IDD = IDD_SOCKET_DIALOG };

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

// Implementation
    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();
    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();

    afx_msg void OnClickedBconnect();

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

    mysocket2 m_sConnectSocket;
    mysocket2 m_sListenSocket;
    afx_msg void OnClickedBsend();
    afx_msg void OnClickedBclose();
    CFineDfThresholdLB m_dFineDfThresholdLB;
    afx_msg void OnClickedFinedfthresholdlbbutton();

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.