我在安装版本的libsasl2(Cyrus SASL)时遇到了一些麻烦。
特别是,似乎本地头文件和sasl_version报告版本2.1.26,但没有为全局函数sasl_client_done提供符号。
我很确定我应该有这个符号,因为:
复制:
未注释的代码在yosemite上产生链接错误
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
with clang -v of:
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为Yosemite打包的方式有些麻烦(或许是使用Mavericks的符号列表?)。
答案 0 :(得分:2)
感兴趣的是,我刚用10.10.4检查过,我看到符号现在在那里:
$ nm /usr/lib/libsasl2.dylib |grep sasl_client_done 000000000000724a T _sasl_client_done
示例代码现在工作正常(注释部分现在取消注释)。仍然返回相同的Cyrus SASL版本:
impl: 'Cyrus SASL', version: 33619994, major: 2, minor: 1, step: 26 sasl_client_done: 0x7fff8e3dc24a