关闭

::system has not been declared 的问题

标签: systemmacrosreferencefunction编程
1609人阅读 评论(0) 收藏 举报
分类:
这个问题的出现是由于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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:45459次
    • 积分:667
    • 等级:
    • 排名:千里之外
    • 原创:21篇
    • 转载:2篇
    • 译文:0篇
    • 评论:5条