pdCurses 在 Windows 中使用,与 3 个 gcc 宏混淆
我正在制作一个非常简单的独立于平台(至少是计划)的控制台应用程序。 我从 conio.h 更改为 pdCurses 以实现这一目标。 问题在于,在 Windows 中,使用 Codeblocks 和 gcc 时遇到问题。
当我包含时,我会遇到很多错误。 它们都涉及位于不同源文件中的 3 个宏:
CodeBlocks\MinGW\bin..\lib\gcc\mingw32\3.4.5........\include\c++\3.4.5\bits\
If我像这样取消定义这 3 个宏:
#include <curses.h>
#undef move
#undef erase
#undef clear
然后一切都编译良好。 如果我不取消定义,那么我会收到大量有关这些宏的错误。
错误示例如下:
macro "move" passed 3 arguments, but takes just 2|
\bits\char_traits.h|185|error: invalid function declaration|
\bits\basic_string.h|604|error: expected `)' before '->' token|
\bits\basic_string.h|1039|macro "erase" passed 2 arguments, but takes just 0|
有人知道为什么会发生这种情况吗? 还有什么不那么丑陋的方法来解决这个问题吗? 预先感谢您的意见。
编辑:每当我调用任何 pdcurses 函数时,我也会收到对各种事物的未定义引用。 我不明白为什么。 我绝对正确地链接了图书馆。 例如,通过尝试在屏幕上回显一个字符,我得到:
main.cpp|74|undefined reference to `__imp__SP'|
main.cpp|74|undefined reference to `__imp__stdscr'|
main.cpp|74|undefined reference to `__imp__stdscr'|
除了库的错误链接之外,还能有什么其他原因吗? 我怎样才能从上述错误中看出 pdcurses 的链接出了什么问题?
-莱夫特里斯
I am making a very simple platform independent(at least that's the plan) console app. I changed from conio.h to pdCurses to make it happen. The problem with that is that in Windows, using Codeblocks and gcc I have a problem.
When I include I get tons of errors. They all concern 3 macros all located in different source files inside:
CodeBlocks\MinGW\bin..\lib\gcc\mingw32\3.4.5........\include\c++\3.4.5\bits\
If I undef those 3 macros like this:
#include <curses.h>
#undef move
#undef erase
#undef clear
then all compiles well. If I don't undef then I get tons of errors about these macros.
Example errors are:
macro "move" passed 3 arguments, but takes just 2|
\bits\char_traits.h|185|error: invalid function declaration|
\bits\basic_string.h|604|error: expected `)' before '->' token|
\bits\basic_string.h|1039|macro "erase" passed 2 arguments, but takes just 0|
Anyone has any idea why this happens? And any not so damn ugly way to correct the problem? Thanks in advance for your input.
Edit: I am also getting undefined references to various things whenever I invoke any pdcurses functions. I can not understand why. I definitely linked the library correctly. For example by trying to echo a char on the screen I get:
main.cpp|74|undefined reference to `__imp__SP'|
main.cpp|74|undefined reference to `__imp__stdscr'|
main.cpp|74|undefined reference to `__imp__stdscr'|
Can it be anything other than bad linking of the library? And how can I see what's wrong with the linking of pdcurses fromthe above errors?
-Lefteris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于宏问题,在curses.h 文件中搜索“STL”,您应该会发现:
也许您可以找到解决方法。
编辑:在我的副本中,如果您#define NCURSES_NOMACROS,它将跳过定义所有宏。 据我所知,所有这些都只是标准屏幕的方便宏,因此您实际上不会丢失任何功能,但您必须使用明确需要屏幕变量的函数。 或者,我想,使用您自己的没有名称冲突的宏。
For the macro problem, do a search for "STL" in the curses.h file and you should find:
Maybe you can find a work around with that.
EDIT: In my copy if you #define NCURSES_NOMACROS it will skip defining all the macros. As far as I looked all of them are just convenience macros for the standard screen so you really don't lose any functionality but you have to use the functions that explicitly require the screen variable. Or, I suppose, use your own macros that don't have name clashes.
答:我不知道为什么会出现这个问题(在带有 PDCurses 的 MSVC 中不会发生这种情况),但“正确的方法”是实现您自己的具有正确指令的标头并包含该标头。
B. 对我来说看起来像是一个链接错误,但为什么不显示相应的代码?
A. I don't know why the problem is there (it doesn't happen in MSVC with PDCurses), but the "proper way" is to implement your own header that has the correct directives and include that instead.
B. Looks like a linking error to me, but why don't you show the corresponding code?