2011-12-27 46 views
0

我想將用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)

+0

請顯示從C文件中外部存取數據時出現的錯誤。這是正確的道路。 – 2011-12-27 22:57:07

回答

4

I've tried splitting that up into a h file and a c file and declaring the float array as extern, but that didn't work.

然後不正確。這是解決您的問題的正確方法。再看看你在分裂它時看到的錯誤。

我在這裏假設,當你說「重複的對象」時,你指的是鏈接時重複的標識符,而不是「對象」。


編輯:你失敗符號無關GeoidHeightBuffer。它看起來像你沒有鏈接任何代碼提供WMM_TimelyModifyMagneticModel()和它的朋友。這些似乎是C++的名稱 - 損壞。您是否使用C++編譯器編譯C代碼而不使用extern "C" {}

+0

重複的符號,是的,謝謝。我將用我試過的文件更新我的問題。 – Christoph 2011-12-27 22:55:29

+0

C++上的好處。我正在使用Objective-C++(.mm文件)。它現在建立,所以我想這個問題的答案。謝謝! – Christoph 2011-12-27 23:18:05