ヘッダー ファイルにインクルード ガードを配置しても、常に次のエラーが発生します。
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 は次のとおりです。
main.c
#include "Handshake.h"
int main(int argc, char** argv)
{
// some code.
return 0;
}
Handshake.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
Handshake.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
}
しかし、ヘッダー ファイルからグローバル変数を削除すると、これらのコードは正常にコンパイルされます。
理由がわかりません。誰かが理由を説明できますか?前もって感謝します。