生命如歌,代码如诗 2019-05-29 18:51 采纳率: 0%
浏览 4462
已采纳

C++类调用函数显示:undefined reference to 'XXX'

UdpBroadcast.h文件中创建一个类及成员函数的声明,UdpBroadcast.cpp中包含成员函数的实现方法。

VADettask.cpp调用UdpBroadcast.h的函数成员显示 undefined reference to `UdpBroadcast::UdpSocketCreate()

UdpBroadcast.h代码:

#ifndef _UDP_BROADCAST_H_
#define _UDP_BROADCAST_H_

#include <iostream>
#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>
#include <sys/types.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>

using namespace std;

class UdpBroadcast
{
private:
    struct sockaddr_in sendaddr;
    struct sockaddr_in recvaddr;

public:
    //UdpBroadcast();
    Uint32 UdpSocketCreate();
    void UdpSendProc(Int32 sockfd,    const char *IP, Uint32 Port);
    void UdpRecvProc(Int32 sockfd, Uint32 Port);
    Uint32 UdpSend(Int32 sockfd, char* msg);
    Uint32 UdpRecv(Int32 sockfd, char *msg, Uint32 len);
};

#endif

UdpBroadcast.cpp代码:

#include <iostream>
#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>
#include <sys/types.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include "UdpBroadcast.h"

using namespace std;

Uint32 UdpBroadcast::UdpSocketCreate()
{
    Int32 sockfd;
    sockfd=socket(AF_INET,SOCK_DGRAM,0);
    if(sockfd ==-1)
    {
         cout<<"socket error"<<endl;
        return -1;
    }
    return sockfd;
}

VADettask.cpp代码:

UdpBroadcast *m_UdpBroadcast = new(UdpBroadcast);
m_UdpBroadcast->UdpSocketCreate();

图片说明

大家知道是什么原因吗?

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 已采纳回答 5月12日

      悬赏问题

      • ¥15 vsc C++ 终端开头有大量空行
      • ¥20 【matlab】运输问题优化问题。
      • ¥15 nodejs express 和 axios 前后端对接,数据体类型
      • ¥15 fluent计算后处理中如何把质量分数和摩尔分数转化为体积分数
      • ¥20 asn1c编码问题,懂asn1的人很简单
      • ¥15 使用vs2019开发的动态链路库在win7环境下使用有问题
      • ¥15 MFC滚动条如何正确使用
      • ¥15 缓冲区算法求面积,基于文献
      • ¥50 电路PCB原理图设计AD19
      • ¥15 openstack 云平台搭建 创建实例错误