C ++框架测试应用程序的链接器错误

时间:2012-10-02 18:28:49

标签: c++ xcode linker static-libraries linker-errors

我想使用AA+ astronomy class framework,我只想让示例应用运行(它包含在framework zip file AATest.cpp中)

我打开了Xcode,为C ++应用程序创建了一个新项目,然后将AA+.hstdafx.h文件添加到项目中,因为它们是包含的。然后,当我构建项目时,我收到很多链接器错误,因为它似乎无法找到与某些示例应用程序代码相关联的符号。

我已经尝试将AA+.hstdafx.h文件的路径添加到Xcode中的Build设置中的库和标题搜索路径,但这并未改变任何内容,错误仍然存​​在那里。

我做错了什么?这是我第一次在Xcode中使用C ++。我是否必须先将AA +框架构建为静态库,还是以这种方式包含它?

通过Xcode编译:

Ld /Users/me/Library/Developer/Xcode/DerivedData/AAPlus-bzgonjwgqlpgescueekcoobljdyf/Build/Products/Debug/AAPlus normal x86_64
    cd "/Users/me/Downloads/aaplus astronomy c++/Example/AAPlus"
    setenv MACOSX_DEPLOYMENT_TARGET 10.7
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/me/Library/Developer/Xcode/DerivedData/AAPlus-bzgonjwgqlpgescueekcoobljdyf/Build/Products/Debug -F/Users/me/Library/Developer/Xcode/DerivedData/AAPlus-bzgonjwgqlpgescueekcoobljdyf/Build/Products/Debug -filelist /Users/me/Library/Developer/Xcode/DerivedData/AAPlus-bzgonjwgqlpgescueekcoobljdyf/Build/Intermediates/AAPlus.build/Debug/AAPlus.build/Objects-normal/x86_64/AAPlus.LinkFileList -mmacosx-version-min=10.7 -stdlib=libc++ -o /Users/me/Library/Developer/Xcode/DerivedData/AAPlus-bzgonjwgqlpgescueekcoobljdyf/Build/Products/Debug/AAPlus

错误:

Undefined symbols for architecture x86_64:
  "CAANutation::TrueObliquityOfEcliptic(double)", referenced from:
      GetSolarRaDecByJulian(double, double&, double&) in main.o
      GetLunarRaDecByJulian(double, double&, double&) in main.o
  "CAADynamicalTime::DeltaT(double)", referenced from:
      GetSolarRaDecByJulian(double, double&, double&) in main.o
  "CAARiseTransitSet::Calculate(double, double, double, double, double, double, double, double, double, double)", referenced from:
      GetSunRiseTransitSet(double, double, double) in main.o
      GetMoonRiseTransitSet(double, double, double) in main.o
  "CAAMoonIlluminatedFraction::PhaseAngle(double, double, double)", referenced from:
      GetMoonIllumination(double, double&, double&, double&) in main.o
  "CAAMoonIlluminatedFraction::PositionAngle(double, double, double, double)", referenced from:
      GetMoonIllumination(double, double&, double&, double&) in main.o
  "CAAMoonIlluminatedFraction::IlluminatedFraction(double)", referenced from:
      GetMoonIllumination(double, double&, double&, double&) in main.o
  "CAAMoonIlluminatedFraction::GeocentricElongation(double, double, double, double)", referenced from:
      GetMoonIllumination(double, double&, double&, double&) in main.o
  "CAACoordinateTransformation::Ecliptic2Equatorial(double, double, double)", referenced from:
      GetSolarRaDecByJulian(double, double&, double&) in main.o
      GetLunarRaDecByJulian(double, double&, double&) in main.o
  "CAASun::ApparentEclipticLatitude(double)", referenced from:
      GetSolarRaDecByJulian(double, double&, double&) in main.o
  "CAASun::ApparentEclipticLongitude(double)", referenced from:
      GetSolarRaDecByJulian(double, double&, double&) in main.o
  "CAADate::CAADate(double, bool)", referenced from:
      PrintTime(double, char const*) in main.o
  "CAADate::CAADate(long, long, double, bool)", referenced from:
      PrintSunAndMoonInfo(int, int, int, double, double) in main.o
  "CAAMoon::EclipticLatitude(double)", referenced from:
      GetLunarRaDecByJulian(double, double&, double&) in main.o
  "CAAMoon::EclipticLongitude(double)", referenced from:
      GetLunarRaDecByJulian(double, double&, double&) in main.o
  "CAADate::Get(long&, long&, long&, long&, long&, double&) const", referenced from:
      PrintTime(double, char const*) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

1 个答案:

答案 0 :(得分:1)

的XCode

您可以在XCode中执行以下操作:

  1. 创建新项目AATest
  2. 将包含框架代码的aaplus/文件夹复制到项目文件夹
  3. 在您的XCode项目中,按住 control 并点击来源
  4. 选择添加>现有文件......
  5. 选择aaplus/文件夹并添加到您的项目
  6. 生成。
  7. 可执行文件位于build/Debug/AATest

    替代

    由于项目包含文件CMakeLists.txt,您可以使用cmake构建程序。在框架文件夹中,在终端上运行以下命令:

    mkdir build/
    cd build/
    cmake ..
    make