- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在编写一个带有线程的 C 程序,并使用 pthread_cleanup_push_defer_np()
和 pthread_cleanup_pop_restore_np()
。前提是:
pthread.h
;-pthread
选项进行编译;gcc
版本 4.8.2 (Ubuntu 4.8.2-19ubuntu1);编译时,我收到了上述函数的令人讨厌的 undefined reference 错误,但我不明白为什么。我试图查看 pthread.h ,似乎这两个函数被注释掉了,所以我想知道是否需要以某种方式启用它们或使用其他类型的选项。我已经阅读了手册页并用谷歌搜索了它,但我找不到解决方案,所以我希望得到一些帮助。这是一个片段:
void *start_up(void *arg)
{
char *timestamp;
// ... code ...
timestamp = get_current_timestamp("humread");
pthread_cleanup_push_defer_np(free, timestamp);
// ... some other code
pthread_cleanup_pop_restore_np(1);
// ... more code ...
}
我编译
gcc -pthread -o server *.c
最佳答案
pthread_cleanup_push_defer_np and pthread_cleanup_pop_restore_np的使用手册假设这两个(不可移植)函数是 GNU 扩展并且已启用通过定义_GNU_SOURCE
:
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
pthread_cleanup_push_defer_np(), pthread_cleanup_pop_defer_np():
_GNU_SOURCE
这会导致链接器错误(而不是编译时错误),因为您的编译器是 C99 之前的版本(或者您正在 C99 之前的模式下编译),并且假定这些函数默认返回 int
。
自 C99 以来,如果不存在原型(prototype),则规则 functions-return-int 已被删除。启用更多编译器开关可以帮助您更好地进行诊断。
关于编译问题: undefined reference to pthread_cleanup_push_defer_np() and pthread_cleanup_pop_restore_np(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26590817/
我目前正在编写一个带有线程的 C 程序,并使用 pthread_cleanup_push_defer_np() 和 pthread_cleanup_pop_restore_np()。前提是: 我已经包
我是一名优秀的程序员,十分优秀!