::system has not been declared 的问题

这个问题的出现是由于system宏在phtread.h中已经有定义,因而产生了冲突,至于为什么这样会产生冲突,我也没想明白,希望高手指点,谢!
一英文网站上贴出的解释:
In <cstdlib> we have:

[-- <cstdlib> ----------]
...
#include <bits/c++config.h>
#include <cstddef>
#include <stdlib.h>
...
#undef system
...
namespace std {
...
using ::system;
...
}
...
[-- <cstdlib> ----------]

And in <pthreads.h> from (GNU pth) we have:

[-- <pthread.h> --------]
#define system __pthread_system
[-- <pthread.h> --------]

So <bits/c++config.h> is indirectly #including <pthreads.h>, and
that #defines the new function, changes all occurrences from there,
and thus the ones on <stdlib.h>, and then <cstdlib> undefs it, so
when the it tries to reference ::system in the using sentence it
cannot find it because it hase been previously remmaped to
__pthread_system.

A test case to show that this is the problem could be:

[-- test-ok.cc ---------]
#include <pthreads.h>
#undef system
#include <cstdlib>
int main() { return 0; }
[-- test-ok.cc ---------]

I'm not sure what's the proper fix, on <cstdlib> we can read:

// Get rid of those macros defined in <stdlib.h> in lieu of real functions.

There are multiple ways to fix this:

* Move the <stdlib.h> and #undefs before #including <bits/c++config.h>
and <cstddef>, as it's supposedly intended to only get rid of macros
from <stdlib.h>.
* Do no undef those macros on <cstdlib>.
* Do not define those macros in <pthread.h> as they are not defined
for LinuxThreads for example.
上诉方法不见得都可以,大家可以试试
我是感觉这些方法也许会给以后带来隐患,就都没用,我在cstdlib.h文件中的
#include <bits/c++config.h>
#include <cstddef>
下加了一句
#undef system
也可以解决问题,而且应该不会在以后的编程中出现因为这个的改动而出现问题
如果会,也希望高手指点!~  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值