我有點卡住了。我幾乎已經完成了這段代碼,但是在嘗試使它與Windows和Linux兼容之後,我遇到了這個我無法解決的問題。我在這方面沒有太多的經驗。以下是錯誤 -c:cygwin-多重定義
$ gcc client.c client.h clientdata.c clientdata.c -o client.exe
/tmp/ccHpxeKs.o:clientdata.c:(.text+0x0): multiple definition of `_handleSendingData'
/tmp/cclpyPee.o:clientdata.c:(.text+0x0): first defined here
/tmp/ccHpxeKs.o:clientdata.c:(.text+0xa9): multiple definition of `_handleRecievingData'
/tmp/cclpyPee.o:clientdata.c:(.text+0xa9): first defined here
/tmp/ccHpxeKs.o:clientdata.c:(.text+0xabb): multiple definition of `_replaceNewLineChar'
/tmp/cclpyPee.o:clientdata.c:(.text+0xabb): first defined here
/tmp/ccHpxeKs.o:clientdata.c:(.text+0xb1c): multiple definition of `_getMyTime'
...........
我有4個文件 - client.c-
#include "client.h"
#ifdef _WIN32
#include "clientdata.c"
#endif //win32
client.h-
#ifndef CLIENT
#define CLIENT
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <signal.h>
#include <time.h>
#define MAXSIZE 2048
#define MILLION 1000000.0
#ifdef _WIN32
#include <winsock.h>
#pragma comment(lib, "wsock32.lib")
#else
#include <sys/socket.h>
#include <netdb.h>
#include <dirent.h>
#include <unistd.h>
#endif //win32
typedef enum {false = 0, true = 1, maybe = 2} bool;
struct messageNode
{
struct timeval *time1;
struct timeval *time2;
int idNumber;
char string[MAXSIZE];
char stringClientArgs[MAXSIZE];
struct messageNode* next;
struct messageNode* moreNext;
char redirectArgs[MAXSIZE];
} *head, *current;
int handleSendingData(struct messageNode *Node);
int handleRecievingData(struct messageNode *Node);
void printNode(struct messageNode *Node);
int setArgs(struct messageNode *Node, int command);
int setNode(struct messageNode* Node, int id);
int getArgs(struct messageNode* Node, char **newArgs);
#endif //CLIENT
clientdata.c-
#include "client.h"
#include "clientdata.h"
clientdata.h-
#ifndef CLIENTDATA
#define CLIENTDATA
#ifdef _WIN32
#include <process.h>
#endif //win32
void replaceNewLineChar(int count, ...);
void copyArray(char* str1, char* str2);
int addId(char *string, int id);
int getId(char *string);
int getReceivedArgs(char *string, char **newArgs, int number);
int getCommand(char* string);
int addToString(char *string, char *text);
int execute(char *cmd, char **args);
int getRedirectArgs(char *string, char **newArgs);
void getMyTime(struct timeval *time);
double timeDifference(struct timeval *start, struct timeval *end);
#endif //CLIENTDATA
我很新的這方面並看了看其他的問題,但我不聲明和值在頭,他們都是函數原型。 太丟了! 這是所有工作之前,我添加#ifdef win32的東西:(但當我試圖改變它回來仍然想出了這些錯誤。
這是一個完整的源代碼?客戶數據僅包含標題? – Spidey
你的'clientdata.c'只是兩行嗎?它有沒有任何定義?如果是的話,你不應該把它作爲'#include「clientdata.c包含在'client.c'中。 – Mahesh
對不起,我剛添加'includes'。對應的.c文件中有所有的函數,從 – RileyVanZeeland