0

I'm having an issue including a C++ static library (.a) in my Cocoa Touch Static Library.

I'm getting a warning that ignoring file /../libfileWrite.a, was built for archive which is not the architecture being linked (i386): /../libFileWrite.a

Later there are errors stating Undefined symbols for architecture i386: "_add", referenced from...

My Setup

I have a fileWrite.cpp and fileWrite.h in a separate Xcode Cocoa Touch Static Library project.

fileWrite.h

#include <stdio.h>
#include <fstream>
#include <iostream>

#ifdef __cplusplus
extern "C" {
#endif

int add(int a, int b);
bool writeFile(const char* filePath);

#ifdef __cplusplus
}
#endif

fileWrite.cpp

#include "fileWrite.h"

using namespace std;

#ifdef __cplusplus
extern "C" {
#endif

int add(int a, int b)
{
  return a+b;
}

bool writeFile(const char* filePath)
{
  ofstream file;
  file.open(filePath);
  if(!file)
  {
    return false;
  }

  file << "This is a test file write" << endl;
  file.close();
  return true;
}

#ifdef __cplusplus
}
#endif

I built my .h / .cpp project on the command line...

armv7

/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project fileWrite.xcodeproj -target fileWrite -sdk iphoneos -arch armv7 -configuration Release clean build

armv7s

/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project fileWrite.xcodeproj -target fileWrite -sdk iphoneos -arch armv7s -configuration Release clean build

i386

/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project fileWrite.xcodeproj -target fileWrite -sdk iphonesimulator -arch i386 -configuration Release clean build

...and built it into a fat file with lipo

lipo -create -output libFileWrite.a libFileWrite-armv7.a libFileWrite-armv7s.a libFileWrite-i386.a

lipo -info libFileWrite.a

returns

Architectures in the fat file: libFileWrite.a are: armv7 armv7s i386

Now, I took this static library and my single .h file and added it to my current project

Here is my current architecture setup. (I changed the Build Active Architectures Only to No and changed the Valid Architectures to i386 armv7 armv7s

I made sure my library was part of the build phase and added a libc++ library too

The function that calls my add comes from a .mm file and it #import "fileWrite.h"

I just can't seem to get rid of this error: ignoring file /../libfileWrite.a, was built for archive which is not the architecture being linked (i386): /../libFileWrite.a

I tried adding -lstdc++ to my Other Linker Flags,but had no luck.

I even tried toggling between these two options:

Any help is appreciated. Thanks!

Josh Schultz
  • 897
  • 1
  • 13
  • 32

0 Answers0