我想將用C編寫的世界磁性模型代碼包含到iOS應用程序中。它包含一個8.5M的頭文件,它定義了一個包含大量元素的浮點數組。如果我按照原樣包含它,則會出現有關重複對象的鏈接器錯誤,可能是因爲頭文件不止一次被不同的編譯單元包含,並且浮點數組在頭文件中定義。這是有點期待。iOS應用程序中的大型數據頭文件
我試過把它分成一個h文件和一個c文件,並將浮點數組聲明爲extern,但這並不起作用。
有關如何通過儘可能少地修改WMM代碼來解決此問題的任何想法?
感謝
編輯:這是我試圖把文件分割:
// EGM9615.h file
extern float GeoidHeightBuffer[];
// EGM9615.c file
#include "EGM9615.h"
float GeoidHeightBuffer[] =
{1.2, 1.2, // lots more
};
它導致鏈接錯誤還是:你這樣做
Undefined symbols for architecture armv7:
"__Z29WMM_TimelyModifyMagneticModel12WMMtype_DateP21WMMtype_MagneticModelS1_", referenced from: -[Waypoint magneticVariation] in Waypoint.o "__Z23WMM_GeodeticToSpherical17WMMtype_Ellipsoid21WMMtype_CoordGeodeticP22WMMtype_CoordSpherical", referenced from: -[Waypoint magneticVariation] in Waypoint.o "__Z26WMM_CalculateGridVariation21WMMtype_CoordGeodeticP27WMMtype_GeoMagneticElements", referenced from: -[Waypoint magneticVariation] in Waypoint.o "__Z10WMM_Geomag17WMMtype_Ellipsoid22WMMtype_CoordSpherical21WMMtype_CoordGeodeticP21WMMtype_MagneticModelP27WMMtype_GeoMagneticElements", referenced from: -[Waypoint magneticVariation] in Waypoint.o "__Z23WMM_AllocateModelMemoryi", referenced from: -[Waypoint magneticVariation] in Waypoint.o "__Z22WMM_GeomagIntroductionP21WMMtype_MagneticModelPc", referenced from: -[Waypoint magneticVariation] in Waypoint.o "__Z23WMM_robustReadMagModelsPcPP21WMMtype_MagneticModeli", referenced from: -[Waypoint magneticVariation] in Waypoint.o "__Z9WMM_Errori", referenced from: -[Waypoint magneticVariation] in Waypoint.o "__Z15WMM_SetDefaultsP17WMMtype_EllipsoidP21WMMtype_MagneticModelP13WMMtype_Geoid", referenced from: -[Waypoint magneticVariation] in Waypoint.o ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)
請顯示從C文件中外部存取數據時出現的錯誤。這是正確的道路。 – 2011-12-27 22:57:07