我安装的libsasl2版本(Cyrus SASL)遇到了一些麻烦。
特别是,似乎本地 header 和sasl_version报告的版本为2.1.26,但没有为全局函数sasl_client_done提供任何符号。
我很确定我应该使用该符号,因为:
对于复制:
未注释的代码在优胜美地上产生链接错误
Undefined symbols for architecture x86_64:
"_sasl_client_done", referenced from:
_main in foo-072675.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
通过以下方式调用编译器:
clang -Wall -Werror -lsasl2 -o foo foo.c -v
与clang -v的:
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.10.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name foo.c -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 241.9 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -Wall -Werror -fdebug-compilation-dir /Users/jcarey/work -ferror-limit 19 -fmessage-length 0 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.10.0 -fencode-extended-block-signature -fdiagnostics-show-option -vectorize-slp -o /var/folders/wq/jypwqgv976n0db5l5qxw900r0000gq/T/foo-92054e.o -x c foo.c
clang -cc1 version 6.0 based upon LLVM 3.5svn default target x86_64-apple-darwin14.0.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.10.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -o foo -lsasl2 /var/folders/wq/jypwqgv976n0db5l5qxw900r0000gq/T/foo-92054e.o -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"_sasl_client_done", referenced from:
_main in foo-92054e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
和有问题的代码:
#include <sasl/sasl.h>
#include <stdio.h>
#include <stdint.h>
int main(int argc, char ** argv) {
const char *impl;
int version;
uint32_t buf;
uint16_t major;
uint8_t minor;
uint8_t step;
sasl_version(&impl, &version);
buf = version;
major = buf >> 24;
minor = (buf << 8) >> 24;
step = (buf << 24) >> 24;
printf("impl: '%s', version: %d, major: %d, minor: %d, step: %d\n", impl, version, major, minor, step);
/*
{
int (* scd)(void);
scd = &sasl_client_done;
printf("sasl_client_done: %p\n", scd);
}
*/
return 0;
}
我认为cyrus sasl为优胜美地包装的方式有些麻烦(也许使用了Mavericks的符号列表?)。
最佳答案
有兴趣的是,我刚刚检查了10.10.4,现在看到的符号是:
$ nm/usr/lib/libsasl2.dylib | grep sasl_client_done
000000000000724a T _sasl_client_done
现在,示例代码可以正常工作(注释部分现在未注释)。仍然返回相同的Cyrus SASL版本:
impl:“Cyrus SASL”,版本:33619994,主要:2,未成年人:1,步长:26
sasl_client_done:0x7fff8e3dc24a