1

A friend of mine asked me to re-write Box2D in objective-c as much as possible. I started writing and when I build the project so far I got, I got some linker errors, I faced similar problem from before, but it didn't help. The error I get is:

Ld /Users/aizen-qa/Library/Developer/Xcode/DerivedData/Obj-Box2D-bwsosdvwkjzsscahpbqrbrnzlall/Build/Products/Debug/Obj-Box2D normal x86_64
    cd /Users/aizen-qa/Desktop/Obj-Box2D
    setenv MACOSX_DEPLOYMENT_TARGET 10.9
    /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.9.sdk -L/Users/aizen-qa/Library/Developer/Xcode/DerivedData/Obj-Box2D-bwsosdvwkjzsscahpbqrbrnzlall/Build/Products/Debug -F/Users/aizen-qa/Library/Developer/Xcode/DerivedData/Obj-Box2D-bwsosdvwkjzsscahpbqrbrnzlall/Build/Products/Debug -filelist /Users/aizen-qa/Library/Developer/Xcode/DerivedData/Obj-Box2D-bwsosdvwkjzsscahpbqrbrnzlall/Build/Intermediates/Obj-Box2D.build/Debug/Obj-Box2D.build/Objects-normal/x86_64/Obj-Box2D.LinkFileList -mmacosx-version-min=10.9 -fobjc-arc -fobjc-link-runtime -framework Foundation -Xlinker -dependency_info -Xlinker /Users/aizen-qa/Library/Developer/Xcode/DerivedData/Obj-Box2D-bwsosdvwkjzsscahpbqrbrnzlall/Build/Intermediates/Obj-Box2D.build/Debug/Obj-Box2D.build/Objects-normal/x86_64/Obj-Box2D_dependency_info.dat -o /Users/aizen-qa/Library/Developer/Xcode/DerivedData/Obj-Box2D-bwsosdvwkjzsscahpbqrbrnzlall/Build/Products/Debug/Obj-Box2D

duplicate symbol _Ob2IsValid in:
    /Users/aizen-qa/Library/Developer/Xcode/DerivedData/Obj-Box2D-bwsosdvwkjzsscahpbqrbrnzlall/Build/Intermediates/Obj-Box2D.build/Debug/Obj-Box2D.build/Objects-normal/x86_64/Ob2Vec3.o
    /Users/aizen-qa/Library/Developer/Xcode/DerivedData/Obj-Box2D-bwsosdvwkjzsscahpbqrbrnzlall/Build/Intermediates/Obj-Box2D.build/Debug/Obj-Box2D.build/Objects-normal/x86_64/Ob2Mat22.o
duplicate symbol _Ob2InvSqr in:
    /Users/aizen-qa/Library/Developer/Xcode/DerivedData/Obj-Box2D-bwsosdvwkjzsscahpbqrbrnzlall/Build/Intermediates/Obj-Box2D.build/Debug/Obj-Box2D.build/Objects-normal/x86_64/Ob2Vec3.o
    /Users/aizen-qa/Library/Developer/Xcode/DerivedData/Obj-Box2D-bwsosdvwkjzsscahpbqrbrnzlall/Build/Intermediates/Obj-Box2D.build/Debug/Obj-Box2D.build/Objects-normal/x86_64/Ob2Mat22.o
duplicate symbol _Ob2IsValid in:
    /Users/aizen-qa/Library/Developer/Xcode/DerivedData/Obj-Box2D-bwsosdvwkjzsscahpbqrbrnzlall/Build/Intermediates/Obj-Box2D.build/Debug/Obj-Box2D.build/Objects-normal/x86_64/Ob2Vec3.o
    /Users/aizen-qa/Library/Developer/Xcode/DerivedData/Obj-Box2D-bwsosdvwkjzsscahpbqrbrnzlall/Build/Intermediates/Obj-Box2D.build/Debug/Obj-Box2D.build/Objects-normal/x86_64/Ob2Vec2.o
duplicate symbol _Ob2InvSqr in:
    /Users/aizen-qa/Library/Developer/Xcode/DerivedData/Obj-Box2D-bwsosdvwkjzsscahpbqrbrnzlall/Build/Intermediates/Obj-Box2D.build/Debug/Obj-Box2D.build/Objects-normal/x86_64/Ob2Vec3.o
    /Users/aizen-qa/Library/Developer/Xcode/DerivedData/Obj-Box2D-bwsosdvwkjzsscahpbqrbrnzlall/Build/Intermediates/Obj-Box2D.build/Debug/Obj-Box2D.build/Objects-normal/x86_64/Ob2Vec2.o
ld: 4 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've read of similar problems, and tried the solutions such as checking the imports not use .m, and duplicate variable names. But I noticed that the classes of vector have same instance variable names, x, y so is this the reason for the error I'm getting or not?

hakuna matata
  • 2,831
  • 11
  • 46
  • 85

4 Answers4

1

You have data elements being defined, rather than declared, in multiple implementation files. This is usually because of something in an included header.

Look for wherever you reference Ob2InvSqr or Ob2IsValid and make sure that storage for those items is only done once.

Phillip Mills
  • 30,195
  • 4
  • 39
  • 55
0

the file Ob2Vec2.o and Ob2Vec3.o contain the same symbol _Ob2InvSqr

very likely that means you have both Ob2Vec2.m and Ob2Vec3.m in the same target.

make sure only one is really compiled

Daij-Djan
  • 47,307
  • 15
  • 99
  • 129
0

I guess you have an inline function _Ob2IsValid(...) in one of your header files that isn't being inlined (it's too large?)

If that's the case you can force it to be inlined like this:

__attribute__((always_inline)) inline void MyFunction(...) {}

Or just make it out-of-line

nielsbot
  • 15,547
  • 4
  • 45
  • 71
0

I was able to solve this thanks to a comment form MartinR. It was because I defined a function in a .h file that I included in multiple Objective-C classes. So what I did was put the function header in the .h file and its implementation in a .m file.

hakuna matata
  • 2,831
  • 11
  • 46
  • 85