gpt4 book ai didi

c - 在 OSX 上使用 TEMP_FAILURE_RETRY

转载 作者:行者123 更新时间:2023-11-30 16:52:01 25 4
gpt4 key购买 nike

我有一些使用 TEMP_FAILURE_RETRY 的代码,但无法构建它。我已定义 _GNU_SOURCE 并按此顺序包含 unistd.h

运行gcc -Wall -v archunix5a_2.c -o archunix5a_2 给出以下输出:

Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
"/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.12.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name archunix5a_2.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 274.2 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Library/Developer/CommandLineTools/usr/bin/../lib/clang/8.0.0 -Wall -fdebug-compilation-dir /Users/mateuszsadowski/Documents/programowanie/nauka/C/SOP/4 -ferror-limit 19 -fmessage-length 59 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.12.0 -fencode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/fp/qqgmt88x247bd712wbbw8wh80000gn/T/archunix5a_2-7cb96f.o -x c archunix5a_2.c
clang -cc1 version 8.0.0 (clang-800.0.42.1) default target x86_64-apple-darwin16.3.0
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Library/Developer/CommandLineTools/usr/bin/../lib/clang/8.0.0/include
/Library/Developer/CommandLineTools/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
archunix5a_2.c:113:13: warning: implicit declaration of
function 'TEMP_FAILURE_RETRY' is invalid in C99
[-Wimplicit-function-declaration]
if (TEMP_FAILURE_RETRY(fsync(fd)) == -1)
^
1 warning generated.
"/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.12.0 -o archunix5a_2 /var/folders/fp/qqgmt88x247bd712wbbw8wh80000gn/T/archunix5a_2-7cb96f.o -lSystem /Library/Developer/CommandLineTools/usr/bin/../lib/clang/8.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"_TEMP_FAILURE_RETRY", referenced from:
_cleanup in archunix5a_2-7cb96f.o
_main in archunix5a_2-7cb96f.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [archunix5a_2] Error 1

如果有任何帮助,我将不胜感激。

最佳答案

正如我之前所说,mac osx 不支持大多数 glib 库。如果您想使用TEMP_FAILURE_RETRY,您可以尝试以下操作不要忘记包含 unistd。从这里阅读更多内容

here用这个宏

#include <unistd.h>  // for TEMP_FAILURE_RETRY

#ifndef TEMP_FAILURE_RETRY
#define TEMP_FAILURE_RETRY(exp) \
({ \
decltype(exp) _rc; \
do { \
_rc = (exp); \
} while (_rc == -1 && errno == EINTR); \
_rc; \
})
#endif

我希望这有帮助

关于c - 在 OSX 上使用 TEMP_FAILURE_RETRY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41446716/

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