In my Cocoa Touch static library project, I have a target set apart for unit testing with OCUnit. When I build the project, I have several unit tests that are supposed to automatically run, but when I actually build the project, I get this linker errors:
"_OBJC_CLASS_$_ObjectIntTreeMap_ObjectEntry", referenced from:
objc-class-ref-to-ObjectIntTreeMap_ObjectEntry in libMyLib.a(ObjectIntTreeMap.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
As far as I know, I am linking the libraries properly (in targets / Tests / Link Binary With Libraries, I have the main project listed there).
Thanks
I figured it out...
My problem was that I had not the class ObjectIntTreeMap_ObjectEntry, and a global variable, and that was what caused my error.
Hope this helps others with the same problem
P.S. I am using GHUnit now
Related
I made a library and I want to test it in a dummy project I made. Both projects are made in Objective-C. When I build my library I get a Successful Build message and three files under the Product directory:
FooIOS.bundle
libFooIOS.a
include
I place these three files at the root level of my dummy project and when I open my myDummyProject.xcworkspace file I see them in my project hierarchy. However, when I build my project I get the following error:
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_FooSelectedPageViewController", referenced from:
objc-class-ref in libFooIOS.a(FooViewController.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I did away with some of the obvious checks:
Made sure to reference my external library
I also made sure that both my library and project architectures are set as armv7 arm64
I don't know what else to do. I may be missing another configuration step or it may even be the way I declared something in my library that doesn't conform with my dummy project. Or a discrepancy between projects, perhaps? Any hints or leads would be a great help. Thanks.
I am trying to create unit tests to my project, I have workspace with several projects with tens of static libraries and apps. So, I created a new project for static library in this workspace and added Cocoa Touch UnitTest bundle to it. Then I added a test for one of the functions in one of the libraries in this workspace, lets say library X, I also added link dependency to my unit test bundle to lib X. But when I run unit tests (Cmd + U). I get linker error:
Undefined symbols for architecture i386:"_OSVersion", referencedfrom:-[MyUnitTest testMethodFromLibX] in MyUnitTestTest.o "_methodFromLibX", referenced symbol(s) not found for architecture i386
Why test bundle is not linking with library X? I can see libX.a and MyUnitTests.octet in build folder.
Ok, thanks all, I found cause of the problem - my libX was Objective-C++ library, so linker mangled all names, but my Unit-Tests were Objective-C library, so when it was linking it obviously couldn't find method or class by name, since linkage was different. So, I convert unit-tests into Objective-C++ library(just changed *.m -> *.mm) and everything works!
Unit tests run in the simulator, and so every library need to have a x386 version. You can use the command line to examine each - i believe "file lib.a" does this but a quick google search will turn up the name.
Undefined symbols for architecture x86_64:
"_objc_unretainedPointer", referenced from:
-[CJSONScanner scanJSONStringConstant:error:] in CJSONScanner.o
-[CJSONSerializer serializeNumber:error:] in CJSONSerializer.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Hey all. Trying to use TouchJSON to do some JSON-y stuff. I followed the read me for the library to the meter I think, but every time I try to compile I get this error. I don't know much about Xcode (I've only been learning Obj-C recently) so I'm clueless about this. Any ideas?
Try to remove "Experimental" folder (and files inside, of course).
README
Be aware that the code in the Experimental subdirectory of Source is
just that and may not have been extensively tested and/or have extra
dependencies
So it could be a problem about extra dependencies (but always make sure if your project already have linked all dependency libraries/framework)
I'm trying to use JSON parsing from RestKit, but I'm receiving
the following compile time error:
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_RKJSONParserJSONKit", referenced from:
objc-class-ref in FloorMapLoaderViewController.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
RestKit works ok, this being the only error I've seen so far.
This is my import line:
#import <RestKit/Support/JSON/JSONKit/RKJSONParserJSONKit.h>
edit:
oddly, it fails to compile only if I try to create a parser like so:
RKJSONParserJSONKit *parser = [RKJSONParserJSONKit new];
Commenting out this line allows for compilation, but I do need to instance a parser.
How can I fix this error?
Thank you.
Importing means that your source code can see the API, so the IDE knows how to auto-complete and so that the compiler knows how to generate the right object code.
You have a linker error. Once your own code is compiled, it has to all be bundled together with all the code it is dependent on (not counting dynamically linked system libraries). Your linker is telling you that after bundled everything it can find together, not all of it is there.
What you need to do is go to the target you are building, select the Build Phases tab, and add the necessary library to the "Link Binary With Libraries" section.
I have an Application Test included in my OCUnit target. I can call instance methods on classes in my Application Host target, but I cannot call class methods. If I call a class method (like alloc), I get the following linker error:
Undefined symbols for architecture armv6:
"_OBJC_CLASS_$_DiceGameViewController", referenced from:
objc-class-ref in DiceGameViewControllerTest.o
(maybe you meant: _OBJC_CLASS_$_DiceGameViewControllerTest)
ld: symbol(s) not found for architecture armv6
collect2: ld returned 1 exit status
I assume this is because Objective-C doesn't need access to the object file at link time to make instance calls, but does need access at link time for class calls. Can someone point me to documentation to confirm this?
This question is similar to these questions:
Imported files not recognized in OCUnit
OCUnit will not allow me to use my own data types
See my answer in Linking error for unit testing with XCode 4?