gpt4 book ai didi

ios - 为什么 Xcode 5 告诉我在为模拟器 (i386) 构建时我有重复的 C 库函数符号?

转载 作者:行者123 更新时间:2023-11-28 22:21:04 27 4
gpt4 key购买 nike

我有一个现有的 iOS 应用程序项目,可以在 Xcode 4 上很好地构 build 备和模拟器。当我尝试在 Xcode 5 上为模拟器构建相同的项目时,我得到许多 (>800) C 的“重复符号”许多(所有?)目标文件的标准库函数,如下所示:

Ld Build/Products/Debug-iphonesimulator/Uploader.app/Uploader normal i386
cd /Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2
setenv IPHONEOS_DEPLOYMENT_TARGET 6.0
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/cmarkle/gcutil-1.2.0:/aspera/bin:/Users/cmarkle/bin:/Users/cmarkle/devel/android-sdk/platform-tools:/Applications/Xcode.app/Contents/Developer/usr/bin/"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk -L/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Products/Debug-iphonesimulator -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/usr/lib/system -L/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/imports/objc-utils/build/Release-iphoneuniversal -F/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Products/Debug-iphonesimulator -F/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2 -F/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/imports/session_manager/release/framework -filelist /Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Intermediates/iphone_upload_app.build/Debug-iphonesimulator/iphone_upload_app.build/Objects-normal/i386/Uploader.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -lobjc-utils -all_load -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=6.0 -liconv -lz -framework CoreVideo -framework CoreMedia -framework AVFoundation -framework MediaPlayer -framework SystemConfiguration -framework AudioToolbox -framework MessageUI -framework Foundation -framework UIKit -framework CoreGraphics -framework AssetsLibrary -framework QuartzCore -framework AsperaMobile -Xlinker -dependency_info -Xlinker /Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Intermediates/iphone_upload_app.build/Debug-iphonesimulator/iphone_upload_app.build/Objects-normal/i386/Uploader_dependency_info.dat -o /Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Products/Debug-iphonesimulator/Uploader.app/Uploader

duplicate symbol _isascii in:
/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/ \
Intermediates/iphone_upload_app.build/Debug-iphonesimulator/ \
iphone_upload_app.build/Objects-normal/i386/AsTransferViewController.o
/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/ \
Intermediates/iphone_upload_app.build/Debug-iphonesimulator/ \
iphone_upload_app.build/Objects-normal/i386/main.o

duplicate symbol ___istype in:
/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/ \
Intermediates/iphone_upload_app.build/Debug-iphonesimulator/ \
iphone_upload_app.build/Objects-normal/i386/AsTransferViewController.o
/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/ \
Intermediates/iphone_upload_app.build/Debug-iphonesimulator/ \
iphone_upload_app.build/Objects-normal/i386/main.o

[... 842 more examples deleted ...]

duplicate symbol ___sigbits in:
/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/ \
Intermediates/iphone_upload_app.build/Debug-iphonesimulator/ \
iphone_upload_app.build/Objects-normal/i386/AsTransferViewController.o
/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/ \
Intermediates/iphone_upload_app.build/Debug-iphonesimulator/ \
iphone_upload_app.build/Objects-normal/i386/PresetsViewController.o

duplicate symbol ___sputc in:
/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/ \
Intermediates/iphone_upload_app.build/Debug-iphonesimulator/ \
iphone_upload_app.build/Objects-normal/i386/AsTransferViewController.o
/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/ \
Intermediates/iphone_upload_app.build/Debug-iphonesimulator/ \
iphone_upload_app.build/Objects-normal/i386/PresetsViewController.o

ld: 846 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

如果我查看创建的对象文件,我会看到对象中包含 C 标准库函数(在 nm 输出中显示为类型 T):

$ nm -n /Users/cmarkle/devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/ \ 
Intermediates/iphone_upload_app.build/Debug-iphonesimulator/i \
iphone_upload_app.build/Objects-normal/i386/main.o
U _OBJC_CLASS_$_NSAutoreleasePool
U _UIApplicationMain
U __DefaultRuneLocale
U ___maskrune
U ___sincos_stret
U ___sincosf_stret
U ___sincospi_stret
U ___sincospif_stret
U ___swbuf
U ___tolower
U ___toupper
00000000 T _isascii
U _objc_msgSend
00000030 T ___istype
000000d0 T ___isctype
00000150 T ___wcwidth
000001f0 T _isalnum
00000220 T _isalpha
[... more follow ...]
00000ba0 T ___sincospif
00000bf0 T ___sincospi
00000c50 T ___sigbits
00000ca0 T ___sputc
00000d40 T _main
00002fc0 s EH_frame0
00002fd8 S _isascii.eh
00002ff4 S ___istype.eh
[... eh (debugging?) stuff
000034c4 S ___sigbits.eh
000034e0 S ___sputc.eh
000034fc S _main.eh

我将“与标准库的链接”设置为"is",就像通常对应用程序所做的那样。如果我将它设置为 NO(这没有任何意义,但我只是在说),我会收到数百条关于各种 C 标准库函数的 Undefined symbols for architecture i386: xxx 消息。

我已经完成了所有蹩脚的事情,例如清理我的项目、删除派生数据等。

作为测试,我创建了一个新的虚拟 Xcode 5 单 View iOS 项目,确保我在其中使用了 C 标准库函数 (memset) 并查看了我在创建时创建的 main.o为模拟器编译该项目。这是它的外观(请注意,memset 是 U,这意味着它不包含在对象中)。

$ nm main.o
000004ac s EH_frame0
U _NSStringFromClass
U _OBJC_CLASS_$_AppDelegate
U _UIApplicationMain
U ___stack_chk_fail
U ___stack_chk_guard
00000000 T _main
000004c4 S _main.eh
U _memcpy
0000049b s _memcpy$stub
U _memset
000004a0 s _memset$stub
U _objc_autoreleasePoolPop
[... more U _objc_xxx ...]
U _objc_retainAutoreleasedReturnValue

作为引用,下面是一个有问题的目标文件的编译步骤示例:

CompileC Build/Intermediates/iphone_upload_app.build/Debug-iphonesimulator/iphone_upload_app.build/Objects-normal/i386/AsTransferViewController.o Classes/AsTransferViewController.m normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2
setenv LANG en_US.US-ASCII
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/cmarkle/gcutil-1.2.0:/aspera/bin:/Users/cmarkle/bin:/Users/cmarkle/devel/android-sdk/platform-tools:/Applications/Xcode.app/Contents/Developer/usr/bin/"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/ \
usr/bin/clang
-x objective-c -arch i386 -fmessage-length=0 -fdiagnostics-show-note-include-stack
-fmacro-backtrace-limit=0 -std=c99 -Wno-trigraphs -fpascal-strings -O0
-Wno-missing-field-initializers -Wno-missing-prototypes
-Wno-implicit-atomic-properties -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak
-Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label
-Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-empty-body
-Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants
-Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion
-Wno-enum-conversion -Wno-shorten-64-to-32 -Wpointer-sign -Wno-newline-eof
-Wno-selector -Wno-strict-selector-match -Wno-undeclared-selector
-Wno-deprecated-implementations -DAPPLE -DDEBUG
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk
-fexceptions -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations
-g -fvisibility=hidden -Wno-sign-conversion -fobjc-abi-version=2
-fobjc-legacy-dispatch -mios-simulator-version-min=6.0
-iquote /Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Intermediates/iphone_upload_app.build/Debug-iphonesimulator/iphone_upload_app.build/Uploader-generated-files.hmap
-I/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Intermediates/iphone_upload_app.build/Debug-iphonesimulator/iphone_upload_app.build/Uploader-own-target-headers.hmap
-I/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Intermediates/iphone_upload_app.build/Debug-iphonesimulator/iphone_upload_app.build/Uploader-all-target-headers.hmap
-iquote /Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Intermediates/iphone_upload_app.build/Debug-iphonesimulator/iphone_upload_app.build/Uploader-project-headers.hmap
-I/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Products/Debug-iphonesimulator/include -I/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/imports/objc-utils/build/Debug-iphoneos/include/ASOCUtils
-I/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/imports/objc-utils/build/Debug-iphonesimulator/include/ASOCUtils -I/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/imports/objc-utils/build/Release-iphoneos/include/ASOCUtils
-I/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/imports/objc-utils/build/Release-iphonesimulator/include/ASOCUtils
-I/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Intermediates/iphone_upload_app.build/Debug-iphonesimulator/iphone_upload_app.build/DerivedSources/i386
-I/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Intermediates/iphone_upload_app.build/Debug-iphonesimulator/iphone_upload_app.build/DerivedSources
-F/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Products/Debug-iphonesimulator
-F/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2
-F/Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/imports/session_manager/release/framework
-fgnu89-inline
-include /Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Intermediates/PrecompiledHeaders/iphone_upload_app_Prefix-gyxexsjpqpprnwefzartfgpgjyug/iphone_upload_app_Prefix.pch
-MMD -MT dependencies
-MF /Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Intermediates/iphone_upload_app.build/Debug-iphonesimulator/iphone_upload_app.build/Objects-normal/i386/AsTransferViewController.d
--serialize-diagnostics /Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Intermediates/iphone_upload_app.build/Debug-iphonesimulator/iphone_upload_app.build/Objects-normal/i386/AsTransferViewController.dia
-c /Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Classes/AsTransferViewController.m
-o /Users/cmarkle/Devel/uploader/uploader-rel-2.0.0-copied-imports-2/Build/Intermediates/iphone_upload_app.build/Debug-iphonesimulator/iphone_upload_app.build/Objects-normal/i386/AsTransferViewController.o

所以...谁能帮我弄清楚为什么我在为模拟器构建时会在我的对象中获得 C 标准库函数的重复符号?提前致谢。如果需要,很乐意提供更多信息...

编辑 1:根据 Rob 和 Petesh 在下面的评论,我从 Build Settings > Apple LLVM 5.0 - Custom Compiler Flags > Other C Flags 中删除了 -fgnu89-inline 选项,此时我的项目已编译适用于 i386/模拟器。

我还使用 Xcode 向导制作了一个新的单 View 应用程序,并按原样为模拟器编译它,结果按预期运行。然后,我将 -fgnu89-inline 选项添加到build设置中,此时构建失败,出现约 180 个重复符号。

使用 clang 时肯定与 -fgnu89-inline 选项有关...

最佳答案

更新

出于某种原因,您正在使用 -fgnu89-inline 编译器标志。该标志告诉编译器标记为 inline 的函数仍应作为导出符号在目标文件中发出。这就是编译器提示 main.oAsTransferViewController.o 包含重复符号的原因。不应从任何 .o 文件中导出这些重复符号。去掉那个编译器标志。

原创

如果您查看 isascii 的定义(在 /usr/include/ctype.h 中),您会发现:

__DARWIN_CTYPE_TOP_inline int
isascii(int _c)
{
return ((_c & ~0x7F) == 0);
}

你会发现 __DARWIN_CTYPE_TOP_inline 在同一个文件中定义如下:

#define __DARWIN_CTYPE_TOP_inline       __header_inline

你会发现在 /usr/include/sys/cdefs.h 中定义的 __header_inline 是这样的:

/* Declaring inline functions within headers is error-prone due to differences
* across various versions of the C language and extensions. __header_inline
* can be used to declare inline functions within system headers. In cases
* where you want to force inlining instead of letting the compiler make
* the decision, you can use __header_always_inline.
*
* Be aware that using inline for functions which compilers may also provide
* builtins can behave differently under various compilers. If you intend to
* provide an inline version of such a function, you may want to use a macro
* instead.
*
* The check for !__GNUC__ || __clang__ is because gcc doesn't correctly
* support c99 inline in some cases:
* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55965
*/

#if __STDC_VERSION__ >= 199901L && (!defined(__GNUC__) || defined(__clang__))
# define __header_inline inline
#elif defined(__GNUC__) && defined(__GNUC_STDC_INLINE__)
# define __header_inline extern __inline __attribute__((__gnu_inline__))
#elif defined(__GNUC__)
# define __header_inline extern __inline
#else
/* If we land here, we've encountered an unsupported compiler,
* so hopefully it understands static __inline as a fallback.
*/
# define __header_inline static __inline
#endif

通常,__header_inline 的定义方式会阻止符号(例如 isascii)在 .o 文件中导出。我怀疑您正在做一些导致 __header_inline 定义不正确的事情,因此正在导出符号。由于该符号是在您链接在一起的两个 .o 文件中导出的,因此您会收到链接器错误。

您可以要求 Xcode 向您显示预处理器输出,方法是从菜单栏中选择“产品”>“执行操作”>“预处理”“文件名”。查看 main.m 的预处理器输出,看看 isascii 是如何声明的。这是我得到的:

inline int
isascii(int _c)
{
return ((_c & ~0x7F) == 0);
}

如果您得到不同的东西(特别是未声明为 inline 的东西),您需要找出原因。

关于ios - 为什么 Xcode 5 告诉我在为模拟器 (i386) 构建时我有重复的 C 库函数符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20386392/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com