2

我在 Xcode、C++ 中创建了一个非常简单的 Hello World 应用程序:

#include <iostream>

using namespace std;

int main(int argc,  char * argv[])
{
   cout << "Hello World!" << endl;
   return 0;
}

Xcode 项目是用 Cmake 创建的:

cmake_minimum_required(VERSION 2.6)

set (CMAKE_VERBOSE_MAKEFILE ON)


PROJECT ( Prueba )

SET ( GedcomToHtml_SRCS         
    main.cpp
)
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR} )


#enable all warnings
ADD_DEFINITIONS ( -Wall )

#Here we instruct to build sample executable from all the source files
ADD_EXECUTABLE ( Prueba ${GedcomToHtml_SRCS} 
)

#last thing that we need to do is to tell CMake what libraries our executable needs
#Luckily FIND_PACKAGE preparted QT_LIBRARIES variable for us
TARGET_LINK_LIBRARIES( Prueba )

当我编译它时,会在 Debug 文件夹中创建一个终端应用程序。我已将此应用程序发送到另一台计算机并尝试运行它,但另一台计算机响应分段错误。

原mac的OS是10.8.2,目标mac的OS是10.6.8。

如何在目标 Mac 中运行在我的原始 Mac 中创建的应用程序?谢谢

4

2 回答 2

3

You should instruct the compiler what the earliest Mac OS X version is on which the program will run. To do this you can use -mmacosx-version-min=10.6 in your case given it should also run on 10.6.8. And additionally you should set the root directory for headers using the -isysroot <10.6 SDK directory> flag.

So in CMake this would amount to the following:

SET(SDK "10.6")
SET(DEV_SDK "/Developer/SDKs/MacOSX${SDK}.sdk")

ADD_DEFINITIONS(
  -isysroot ${DEV_SDK} 
  -mmacosx-version-min=${SDK}
  )

SET(
  CMAKE_EXE_LINKER_FLAGS
  "${CMAKE_EXE_LINKER_FLAGS} -isysroot ${DEV_SDK} -mmacosx-version-min=${SDK}"
  )
SET(
  CMAKE_SHARED_LINKER_FLAGS
  "${CMAKE_SHARED_LINKER_FLAGS} -isysroot ${DEV_SDK} -mmacosx-version-min=${SDK}"
  )
SET(
  CMAKE_MODULE_LINKER_FLAGS
  "${CMAKE_MODULE_LINKER_FLAGS} -isysroot ${DEV_SDK} -mmacosx-version-min=${SDK}"
  )

Note that your SDK might be located somewhere else so substitute the correct directory.

于 2012-12-15T18:46:52.223 回答
1

原来我需要做的就是将此行添加到我的 CMakeLists.txt 文件中:

设置(CMAKE_OSX_DEPLOYMENT_TARGET 10.6)

谢谢您的帮助。

于 2012-12-16T12:54:14.317 回答