私は少し立ち往生しています。私はこのコードをほぼ完成させましたが、Windows と Linux との互換性を持たせようとした後、解決できないこの問題に遭遇しました。私はこの分野であまり経験がありません。ここにエラーがあります-
$ 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 のものを追加する前はすべて機能していました:(しかし、元に戻そうとすると、これらのエラーが発生しました。