geany 问题
时间:2010-12-24
来源:互联网
三个文件:
common.h
#ifndef COMMON_H
#define COMMON_H
class common
{
public:
common(){};
~common();
void cur_time(void);
void output();
//void cur_time(int);
};
#endif
common.cpp
#include <time.h>
#include <stdio.h>
#include <string.h>
#include "common.h"
using namespace std;
common::common()
{}
~common::common()
{}
/*void common::cur_time(int pParam)
{
char *wday[]={"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
time_t timep;
struct tm *p;
time(&timep);
p=localtime(&timep); // 获取当前时间
printf("%d年%02d月%02d日",(1900+p->tm_year),(1+p->tm_mon),p->tm_mday);
printf("%s %02d:%02d:%02d\n",wday[p->tm_wday],p->tm_hour,p->tm_min,p->tm_sec);
}*/
void common::cur_time(void)
{
time_t timep;
struct tm *p;
time(&timep);
p=localtime(&timep); /* 获取当前时间 */
printf("%d-%02d-%02d ",(1900+p->tm_year),(1+p->tm_mon),p->tm_mday);
printf("%02d:%02d:%02d\n",p->tm_hour,p->tm_min,p->tm_sec);
}
void common::output()
{
printf("hello\n");
}
client.cpp
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <time.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <arpa/inet.h>
#include "common.h"
using namespace std;
#define NO_FLAGS_SET 0
typedef int SOCKET;
#define SOCKET_ERROR (-1)
#define INVALID_SOCKET (-1)
#define PORT (u_short) 10001
#define DEST_IP_ADDR "192.168.255.199" //Server address
//void cur_time(void);
common *con;
int Connect(int pParam)
{
sockaddr_in destSockAddr;
SOCKET destSocket;
unsigned long destAddr;
int status;
int numsnt;
const char *toSendtxt = "Test String";
char buf[1024];
con = new common();
destSockAddr.sin_addr.s_addr = inet_addr(DEST_IP_ADDR); //.sin_addr.s_addr
destSockAddr.sin_port = htons(PORT);
/* specify the address family as Internet */
destSockAddr.sin_family = AF_INET;
/* create a socket */
destSocket = socket(AF_INET, SOCK_STREAM, 0);
if (destSocket == INVALID_SOCKET)
{
cerr << "ERROR: socket unsuccessful" << endl;
return(1);
}
cout << "Trying to connect to IP Address: " << DEST_IP_ADDR << endl;
/* connect to the server */
status = connect(destSocket, (sockaddr *)&destSockAddr, sizeof(destSockAddr));
if (status == SOCKET_ERROR)
{
cerr << "ERROR: connect unsuccessful" << endl;
status = close(destSocket);
if (status == SOCKET_ERROR)
{
cerr << "ERROR: closesocket unsuccessful" << endl;
}
return 1;
}
cout << "Connected..." << endl;
int count = 1;
while(1)
{
//cout << "FrameNo:" << count << "\tSendingContent:" << toSendtxt << "\ttime:" << time(NULL) << endl; //asctime(localtime(&rawtime))
cout << "FramNo:" << count << "\tSendingContent:" << toSendtxt << "\ttime:";
con->output();
con->cur_time();
numsnt = send(destSocket, toSendtxt, (int)strlen(toSendtxt) + 1, NO_FLAGS_SET);
if (numsnt != (int)strlen(toSendtxt) + 1)
{
cout << "Connection terminated" << endl;
status = close(destSocket);
if (status == SOCKET_ERROR)
{
cerr << "ERROR: closesocket unsuccessful" << endl;
}
return 1;
}
memset(&buf,0,sizeof(buf));
status = recv(destSocket,buf,sizeof(buf),0);
if(SOCKET_ERROR == status)
{
close(destSocket);
return -1;
}
cout << "EchoNo:" << count << "\tContent:" << buf << endl;
/*if(count % 7 == 1)
{
Beep(523,500);
}
else if(count % 7 == 2)
{
Beep(578,500);
}
else if(count % 7 == 3)
{
Beep(659,500);
}
else if(count % 7 == 4)
{
Beep(698,500);
}
else if(count % 7 == 5)
{
Beep(784,500);
}
else if(count % 7 == 6)
{
Beep(880,500);
}
else if(count % 7 == 0)
{
beep(988,500);
}*/
count++;
/* Wait before sending the message again */
sleep(1);
} /* while */
}
int main()
{
Connect(0);
return 0;
}
/*void cur_time(void)
{
char *wday[]={"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
time_t timep;
struct tm *p;
time(&timep);
p=localtime(&timep); // 获取当前时间
printf("%d-%02d-%02d ",(1900+p->tm_year),(1+p->tm_mon),p->tm_mday);
printf("%02d:%02d:%02d\n",p->tm_hour,p->tm_min,p->tm_sec);;
}*/
现在编译出现错误:
g++ -o client client.cpp
/tmp/ccyEy2E2.o: In function `Connect(int)':
client.cpp:(.text+0x21a): undefined reference to `common::output()'
client.cpp:(.text+0x227): undefined reference to `common::cur_time()'
collect2: ld returned 1 exit status
向各位请教,谢谢大家
common.h
#ifndef COMMON_H
#define COMMON_H
class common
{
public:
common(){};
~common();
void cur_time(void);
void output();
//void cur_time(int);
};
#endif
common.cpp
#include <time.h>
#include <stdio.h>
#include <string.h>
#include "common.h"
using namespace std;
common::common()
{}
~common::common()
{}
/*void common::cur_time(int pParam)
{
char *wday[]={"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
time_t timep;
struct tm *p;
time(&timep);
p=localtime(&timep); // 获取当前时间
printf("%d年%02d月%02d日",(1900+p->tm_year),(1+p->tm_mon),p->tm_mday);
printf("%s %02d:%02d:%02d\n",wday[p->tm_wday],p->tm_hour,p->tm_min,p->tm_sec);
}*/
void common::cur_time(void)
{
time_t timep;
struct tm *p;
time(&timep);
p=localtime(&timep); /* 获取当前时间 */
printf("%d-%02d-%02d ",(1900+p->tm_year),(1+p->tm_mon),p->tm_mday);
printf("%02d:%02d:%02d\n",p->tm_hour,p->tm_min,p->tm_sec);
}
void common::output()
{
printf("hello\n");
}
client.cpp
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <time.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <arpa/inet.h>
#include "common.h"
using namespace std;
#define NO_FLAGS_SET 0
typedef int SOCKET;
#define SOCKET_ERROR (-1)
#define INVALID_SOCKET (-1)
#define PORT (u_short) 10001
#define DEST_IP_ADDR "192.168.255.199" //Server address
//void cur_time(void);
common *con;
int Connect(int pParam)
{
sockaddr_in destSockAddr;
SOCKET destSocket;
unsigned long destAddr;
int status;
int numsnt;
const char *toSendtxt = "Test String";
char buf[1024];
con = new common();
destSockAddr.sin_addr.s_addr = inet_addr(DEST_IP_ADDR); //.sin_addr.s_addr
destSockAddr.sin_port = htons(PORT);
/* specify the address family as Internet */
destSockAddr.sin_family = AF_INET;
/* create a socket */
destSocket = socket(AF_INET, SOCK_STREAM, 0);
if (destSocket == INVALID_SOCKET)
{
cerr << "ERROR: socket unsuccessful" << endl;
return(1);
}
cout << "Trying to connect to IP Address: " << DEST_IP_ADDR << endl;
/* connect to the server */
status = connect(destSocket, (sockaddr *)&destSockAddr, sizeof(destSockAddr));
if (status == SOCKET_ERROR)
{
cerr << "ERROR: connect unsuccessful" << endl;
status = close(destSocket);
if (status == SOCKET_ERROR)
{
cerr << "ERROR: closesocket unsuccessful" << endl;
}
return 1;
}
cout << "Connected..." << endl;
int count = 1;
while(1)
{
//cout << "FrameNo:" << count << "\tSendingContent:" << toSendtxt << "\ttime:" << time(NULL) << endl; //asctime(localtime(&rawtime))
cout << "FramNo:" << count << "\tSendingContent:" << toSendtxt << "\ttime:";
con->output();
con->cur_time();
numsnt = send(destSocket, toSendtxt, (int)strlen(toSendtxt) + 1, NO_FLAGS_SET);
if (numsnt != (int)strlen(toSendtxt) + 1)
{
cout << "Connection terminated" << endl;
status = close(destSocket);
if (status == SOCKET_ERROR)
{
cerr << "ERROR: closesocket unsuccessful" << endl;
}
return 1;
}
memset(&buf,0,sizeof(buf));
status = recv(destSocket,buf,sizeof(buf),0);
if(SOCKET_ERROR == status)
{
close(destSocket);
return -1;
}
cout << "EchoNo:" << count << "\tContent:" << buf << endl;
/*if(count % 7 == 1)
{
Beep(523,500);
}
else if(count % 7 == 2)
{
Beep(578,500);
}
else if(count % 7 == 3)
{
Beep(659,500);
}
else if(count % 7 == 4)
{
Beep(698,500);
}
else if(count % 7 == 5)
{
Beep(784,500);
}
else if(count % 7 == 6)
{
Beep(880,500);
}
else if(count % 7 == 0)
{
beep(988,500);
}*/
count++;
/* Wait before sending the message again */
sleep(1);
} /* while */
}
int main()
{
Connect(0);
return 0;
}
/*void cur_time(void)
{
char *wday[]={"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
time_t timep;
struct tm *p;
time(&timep);
p=localtime(&timep); // 获取当前时间
printf("%d-%02d-%02d ",(1900+p->tm_year),(1+p->tm_mon),p->tm_mday);
printf("%02d:%02d:%02d\n",p->tm_hour,p->tm_min,p->tm_sec);;
}*/
现在编译出现错误:
g++ -o client client.cpp
/tmp/ccyEy2E2.o: In function `Connect(int)':
client.cpp:(.text+0x21a): undefined reference to `common::output()'
client.cpp:(.text+0x227): undefined reference to `common::cur_time()'
collect2: ld returned 1 exit status
向各位请教,谢谢大家
作者: csr_hema 发布时间: 2010-12-24
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28