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();
大家知道是什么原因吗?