osgearth IOS版本编译

1、准备工作

    文档参照:Building osgEarth for IOS Generating an IOS XCode Project

1.1、Mac OS

          Mac OS 10.8.3

1.2、XCode

          XCode 4.6(4H127)

1.3、CMake

          CMake 2.8.12.1

1.4、svn

          随便安装个能下载代码的就行

1.5、代码下载

          OpenSceneGraph3.2.1-rc1  osgearth2.4

         项目工程目录:

         osgearth-build

                    --  osg-ios

                    --  osgearth-ios

                    --  3rdparty                    

1.6、3rdparty下载

         ios 3rdparty JavaScriptCore 

1.7、OSGEarth IOS下载

       osgearth ios application,只需要拷贝osgearth/src/applications/osgearth_viewIOS工程即可,其他部分仍使用下载的IOS代码

1.8、Xcode开发者许可证

        编译前必须搞定Xcode开发者许可证,否则编译过程报错。

2、工程生成、编译

2.1、OSG IOS工程编译

2.1.1、SDK路径确认、修改配置

Check /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs // 检查该路径是否存在、SDK版本
Open CMakeList.txt and change line 236 to your SDK version: (SET (IPHONE_SDKVER "5.1" CACHE STRING "IOS SDK-Version") // 设置SDK版本,Xcode4.6默认使用6.1SDK

2.1.2、启动CMake,确认配置项

    Use below command line to generate static GLES2 build for iOS devices, change 3rdparty paths to reflect your 3rdparty path

    cd ./osg-ios

    cmake ./ -G Xcode -DOSG_BUILD_PLATFORM_IPHONE:BOOL=ON \
    -DBUILD_OSG_APPLICATIONS:BOOL=OFF \
    -DOSG_WINDOWING_SYSTEM:STRING=IOS \
    -DOSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX="imageio" \
    -DOSG_GL1_AVAILABLE:BOOL=OFF \
    -DOSG_GL2_AVAILABLE:BOOL=OFF \
    -DOSG_GLES1_AVAILABLE:BOOL=OFF \
    -DOSG_GLES2_AVAILABLE:BOOL=ON \
    -DOSG_GL_DISPLAYLISTS_AVAILABLE:BOOL=OFF \
    -DOSG_GL_FIXED_FUNCTION_AVAILABLE:BOOL=OFF \
    -DOSG_GL_LIBRARY_STATIC:BOOL=OFF \
    -DOSG_GL_MATRICES_AVAILABLE:BOOL=OFF \
    -DOSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE:BOOL=OFF \
    -DOSG_GL_VERTEX_FUNCS_AVAILABLE:BOOL=OFF \
    -DCURL_INCLUDE_DIR:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/curl-ios-device/include" \
    -DCURL_LIBRARY:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/curl-ios-device/lib/libcurl.a" \
    -DFREETYPE_INCLUDE_DIR_freetype2:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/freetype-ios-universal/include/freetype" \
    -DFREETYPE_INCLUDE_DIR_ft2build:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/freetype-ios-universal/include" \
    -DFREETYPE_LIBRARY:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/freetype-ios-universal/lib/libFreeType_iphone_universal.a" \
    -DTIFF_INCLUDE_DIR:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/tiff-ios-device/include" \
    -DTIFF_LIBRARY:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/tiff-ios-device/lib/libtiff.a" \
    -DGDAL_INCLUDE_DIR:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/gdal-ios-device/include" \
    -DGDAL_LIBRARY:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/gdal-ios-device/lib/libgdal.a" \
    -DDYNAMIC_OPENSCENEGRAPH:BOOL=OFF \
    -DDYNAMIC_OPENTHREADS:BOOL=OFF

        参照上面的配置表,确认CMake配置。CMake默认使用Mac OS的配置,当配置完OSG_BUILD_PLATFORM_IPHONE后,最好点击下"Configure",再确定"OSG_WINDOWING_SYSTEM"的值是否为IOS,否则配置错误。需要将以上的第三方库的头文件、路径改成项目的路径。

        再检查:

CMake uses the CMAKE_OSX_SYSROOT variable to know where the iOS sdk is located. OSG will automatically set this to
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk

If you use a different sdk or your sdk is installed in a different location change CMAKE_OSX_SYSROOT to point to the correct location

You can also specify a different sdk number as the minimum requirement, this is set via the -miphoneos-version-min option in the CMAKE_CXX_FLAGS, by default this is set to 4.0. If using the CMake GUI you may need to tick 'Advanced' in order to see the CMAKE_CXX_FLAGS setting.
       确认:CMAKE_OSX_SYSROOT的路径为
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk
,Xcode默认路径为MacOS.platform的开发路径,需要修改。(
/Applications/Xcode.app/Contents/Developer/Platforms,目录下有MacOS.platform、iPhoneOS.platform、iPhoneSimulator.platform,配置工程对应的平台)

       确认:CMAKE_CXX_FLAGS:中是否包含-miphoneos-version-min=4.0,如果包含-mmacos-version-min=10.8,需去除

       CMake生成工程

2.1.3、连接设备,启动Xcode,编译osg

2.2、osgearth工程编译

2.2.1、cmake配置,生成工程

cmake ./ -G Xcode -DOSG_BUILD_PLATFORM_IPHONE:BOOL=ON \
-DOSG_DIR:PATH="/Users/hogbox/Documents/osgearth-build/osg-ios" \
-DCURL_INCLUDE_DIR:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/curl-ios-device/include" \
-DCURL_LIBRARY:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/curl-ios-device/lib/libcurl.a" \
-DGDAL_INCLUDE_DIR:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/gdal-ios-device/include" \
-DGDAL_LIBRARY:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/gdal-ios-device/lib/libgdal.a" \
-DGEOS_INCLUDE_DIR:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/geos-ios-device/include/source/headers" \
-DGEOS_LIBRARY:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/geos-ios-device/lib/libGEOS_3.2.a" \
-DOSGEARTH_BUILD_APPLICATION_BUNDLES:BOOL=OFF \
-DDYNAMIC_OSGEARTH:BOOL=OFF \
-DOSGEARTH_USE_QT:BOOL=OFF
      根据以上配置内容,确认CMake配置,并生成osgearth ios工程文件。

2.2.2、连接设备,启动Xcode,编译osgearth

2.2.3、编译工程可能遇到的错误处理

2.2.3.1、stat64错误

      跟踪代码,可发现此错误由于没有找到工程对应的平台TargetConditionals.h,只要将报错的Target的“Framework Search Paths",修改为:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks  并且在“Header Search Paths"中添加 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/include。

2.2.3.2、Unknown archivement错误

   只要将报错的Target的“Framework Search Paths",修改为:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks

2.2.3.3、-mmacos-version-min错误

    由于当前编译的是iphoneos,所以需要将-mmacos-version-min宏删除

2.2.3.4、not found "osg/config"错误

   openscenegraph3.2.1/build/include路径找不到报错,在Target的“Header Search Paths"中添加此路径即可。

2.2.3.5、Undefined Symbols for Architecture armv7 错误

    Architecture的版本取决于你使用的硬件,iphone5s使用armv7、armv7s,项目使用的是armv6、armv7。虚拟机编译使用的是i386

2.2.3.6、神奇的报错(找不出原有的神奇报错)

     只要将报错的Target的“Framework Search Paths",修改为:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks

2.3 osgearthView_IOS编译

     从github下载代码,下载路径见前面的说明,工程下载后,只需要将osgearth/src/applications/osgearthView_IOS文件夹拷过来即可。

    最好联机编译,之前编译的osg、osgearth都是联机编译的库。(虚拟机的还没试过)

     配置osg、osgearth的头文件、库文件,系统framework。

    编译到最后是,osgearthView_IOS工程需要拷贝osgearth目录下的tests、data、moon_1024....png,还有gdal_data(最好上gdal网站下载,再将data文件夹拷贝到xcode工程中)

3、osgearthView_IOS运行

      今天设备被拿走,还没编译完,待编译完,再续。

     ps:下午拿到设备,将osgearthView_IOS打到iPhone5上运行,闪退。

你可能感兴趣的:(osgearth IOS版本编译)