0

I keep getting the error Linker command failed with exit code 1 and it seems to be because of my .h-file. In my stringsDE.h I define constant strings. Might this be the problem?

duplicate symbol _QUESTIONCATBUTTONMIXED in: /Users/philip_air/Library/Developer/Xcode/DerivedData/juraQuiz-awgytksreajdjbdmoctjoffmzmmk/Build/Intermediates/juraQuiz.build/Debug-iphoneos/juraQuiz.build/Objects-normal/armv7/appLaunch.o /Users/philip_air/Library/Developer/Xcode/DerivedData/juraQuiz-awgytksreajdjbdmoctjoffmzmmk/Build/Intermediates/juraQuiz.build/Debug-iphoneos/juraQuiz.build/Objects-normal/armv7/quizVC.o ld: 17 duplicate symbols for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

CODE:

http://pastebin.com/iGTVAb6K

Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
Philip
  • 1,068
  • 3
  • 12
  • 21
  • you may be initalized this QUESTIONCATBUTTONMIXED variable in some other place other than constants file. change the variable name in other places except constants file and build application. – RAJA Mar 10 '14 at 02:08

2 Answers2

2

Declare all of your strings in your .h file using:

// QUESTIONCAT BUTTONS
extern NSString const *QUESTIONCATBUTTON1;
extern NSString const *QUESTIONCATBUTTON2;
extern NSString const *QUESTIONCATBUTTON3;
extern NSString const *QUESTIONCATBUTTONMIXED;

and then truly define them in one single .m file like this:

// QUESTIONCAT BUTTONS
NSString * const QUESTIONCATBUTTON1 = @"Zivilrecht";
NSString * const QUESTIONCATBUTTON2 = @"öffentliches Recht";
NSString * const QUESTIONCATBUTTON3 = @"Strafrecht";
NSString * const QUESTIONCATBUTTONMIXED = @"Gemischt";
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • yes yes, I'm importing it into all my views! In my stringsDE.h I save all the strings I need to use in my program, so I don't have to hardcode them. Is that the wrong way to do it? – Philip Mar 10 '14 at 01:27
  • Just try adding the above code to the very top and bottom of your .h file and see if things get better for you. – Michael Dautermann Mar 10 '14 at 01:28
  • I found this: `also had this problem by declaring a const * NSString in the header file (incorrectly) instead of the implementation file (correctly)`. This means I can't define consts in an `.h-File` to include it everywhere? – Philip Mar 10 '14 at 01:41
  • maybe you should edit your question to show how you are declaring your strings in your .h file? – Michael Dautermann Mar 10 '14 at 01:41
  • do I have to use #ifndef in .m-File too? – Philip Mar 10 '14 at 02:01
  • it works. but thats kind of a weird solution, isn't it? I'd prefer to have only one file. – Philip Mar 10 '14 at 02:05
  • You have a single .h file that you include anywhere you want those constant strings to be used, and a single .m file that actually defines the contents of those constant strings. – Michael Dautermann Mar 10 '14 at 02:06
  • yes but I have to type the string name twice. in my .h and in my .m – Philip Mar 10 '14 at 02:07
  • You could also use "`#define`" in your .h files (which would allow you to ditch the .m), but [that's not optimal for the compiler](http://www.cocoabuilder.com/archive/cocoa/116304-const-nsstring-vs-extern-vs-define-for-global-constants.html) – Michael Dautermann Mar 10 '14 at 02:09
  • so the only way having one .h-File I would have to make them non-const? – Philip Mar 10 '14 at 02:10
0

I have gotten this before it could be you are #importing a .m file instead of a .h.

Charlie
  • 222
  • 3
  • 20
  • Well i don't think constant strings are the problem try commenting them out and see if it builds real quick – Charlie Mar 10 '14 at 01:29
  • they might be, I comment them out, and I commented out every line where I used them. error gone. – Philip Mar 10 '14 at 01:33
  • http://stackoverflow.com/questions/2264455/iphone-duplicate-symbol-error possibly this? – Charlie Mar 10 '14 at 01:41
  • yeah but how shall I define constant strings that i want to use in more than one file? – Philip Mar 10 '14 at 01:45
  • can you show me more code how are you defining. Also you could have one file with a class method returning the string so you could always just call [NEEDSTRING MYSTRING]; and you would get it. – Charlie Mar 10 '14 at 01:50
  • I put a link in my post. I want to keep it simple though. I don't think I need a class for that – Philip Mar 10 '14 at 01:51
  • http://pastebin.com/LJciFZaJ This is what I would do. Does not make it over complicate or anything. Basically if you want to use it #import "strings.h" then you just do [strings GET_QUESTIONS_URL]; and it will return the string. – Charlie Mar 10 '14 at 02:07
  • thanks! great solution, but I don't want to use a class for that. I don't see, why my solution won't work – Philip Mar 10 '14 at 02:10