即使我在头文件中放置了包含保护,我总是会收到以下错误。
duplicate symbol _Bittorrent in:
/Users/tracking/Library/Developer/Xcode/DerivedData/SHT-giuwkwyqonghabcqbvbwpucmavvg/Build/Intermediates/SHT.build/Debug/SHT.build/Objects-normal/x86_64/main.o
/Users/tracking/Library/Developer/Xcode/DerivedData/SHT-giuwkwyqonghabcqbvbwpucmavvg/Build/Intermediates/SHT.build/Debug/SHT.build/Objects-normal/x86_64/Handshake.o
duplicate symbol _eight_byte in:
/Users/tracking/Library/Developer/Xcode/DerivedData/SHT-giuwkwyqonghabcqbvbwpucmavvg/Build/Intermediates/SHT.build/Debug/SHT.build/Objects-normal/x86_64/main.o
/Users/tracking/Library/Developer/Xcode/DerivedData/SHT-giuwkwyqonghabcqbvbwpucmavvg/Build/Intermediates/SHT.build/Debug/SHT.build/Objects-normal/x86_64/Handshake.o
ld: 2 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这里是 .h 头文件、.c 文件和 main.c
主程序
#include "Handshake.h"
int main(int argc, char** argv)
{
// some code.
return 0;
}
握手.h
#ifndef SHT_Handshake_h
#define SHT_Handshake_h
const char *Bittorrent = "BitTorrent protocol";
const char eight_byte[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
#endif
握手.c
#include "Handshake.h"
int Send_fisrt_Handshake(download_connection *pPeer, Handshake *necessary_info)
{
//some statements
return 1;
}
void Set_Handshake_information(TorrentFile* pArg, Handshake *pYours)
{
//some statements
}
但是,如果我从头文件中删除全局变量,这些代码编译成功。
我不明白为什么。有人可以解释为什么吗?先感谢您。