Duplicate symbol error — global constant

前端 未结 3 1630
清歌不尽
清歌不尽 2021-01-04 03:33

In the header of the class, outside of interface declaration, I\'ve declared global constants:

NSString * const gotFilePathNotification = @\"gotFilePath\";
N         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-04 04:12

    You have two identifier(s) with same name across two different compilation unit(s) at file scope. This violates One Definition Rule. Instead you need to -

    1. Declare the global variables marking to have external linkage in a header file.

      extern NSString * const gotFilePathNotification;
      
    2. Now provide the definition in only one source file.

      NSString * const gotFilePathNotification = @"gotFilePath";
      

    Now where ever you need to use these variables, include the header in the source file.

提交回复
热议问题