【问题标题】:BGI library may not be compatible with 64-bit versions of WindowsBGI 库可能与 64 位版本的 Windows 不兼容
【发布时间】:2021-04-19 04:06:22
【问题描述】:

BGI 库与 windows 不兼容

我需要通过 BGI 库进行图形编程。所以我按照GeeksForGeeks网站的步骤或按照以下步骤操作。

系统:64位Windows 10; 编译器:GNU GCC 编译器 应用:CodeBlocks::MinGW

第 1 步:http://winbgim.codecutter.org/CLICK 下载BGI 库

第 2 步: 提取下载的文件。会有三个文件:

  • 图形.h
  • winbgim.h
  • libbgi.a

第 3 步: 将 graphics.h 和 winbgim.h 文件复制并粘贴到编译器目录的 include 文件夹中。 (如果你的电脑C盘安装了Code::Blocks,请通过:

磁盘 C >> 程序文件 >> 代码块 >> MinGW >> 包含

第 4 步: 将libbgi.a复制粘贴到编译器目录的lib文件夹中。

磁盘 C >> 程序文件 >> 代码块 >> MinGW >> lib

第 5 步: 打开代码::块。前往:

设置>>编译器>>链接器设置

第 6 步: 在该窗口中,单击“链接库”部分下的添加按钮,然后浏览到在步骤 4 中复制到 lib 文件夹的 libbgi.a 文件

第 7 步:其他链接器选项下粘贴这些命令:

-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32.

第 8 步: 尝试用 C 或 C++ 编译 graphics.h 程序,仍然会有错误。要解决此问题,请使用 Notepad++ 打开 graphics.h 文件(在步骤 3 中粘贴在包含文件夹中)。转到行号 302,并将该行替换为以下行:

int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,

第 7 步: 现在,您可以编译任何包含 graphics.h 头文件的 C 或 C++ 程序。如果你编译 C 代码,你仍然会得到一个错误提示:

致命错误:sstream:没有这样的文件目录。

对于这个问题,如果是 .c,请将文件扩展名更改为 .cpp


程序文件中的我的目录结构:

▾ CodeBlocks
 ▾ MinGW
     bin
     etc
   ▾ include
       gdb
       libiberty
   ▾ lib
     ▾ gcc
       ▾ x86_64-w64-mingw32
         ▾ 8.1.0
             finclude
           ▸ include
             include-fixed
           ▸ install-tools
           lib
       ▾ libexec
         ▾ gcc
           ▾ x86_64-w64-mingw32
             ▾ 8.1.0
                install-tools
   ▸ licences
   ▸ opt
   ▸ share
   ▾ x86_64-w64-mingw32 
       bin *(ld.exe is here)*
     ▾ include (graphics.h & winbgim.h) *(all header files are here)*
     ▾ lib (libbgi.a) 

构建日志:

||=== Build file: "no target" in "no project" (compiler: unknown) ===|
C:\Users\UserName\OneDrive\Desktop\Untitled1.cpp||In function 'int main()':|
C:\Users\UserName\OneDrive\Desktop\Untitled1.cpp|6|warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]|
C:\Users\UserName\OneDrive\Desktop\Untitled1.o:Untitled1.cpp|| undefined reference to `initgraph'|
C:\Users\UserName\OneDrive\Desktop\Untitled1.o:Untitled1.cpp|| undefined reference to `bar'|
C:\Users\UserName\OneDrive\Desktop\Untitled1.o:Untitled1.cpp|| undefined reference to `closegraph'|
||error: ld returned 1 exit status|
||=== Build failed: 4 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|

关于 BGI 头文件的说明

// ---------------------------------------------------------------------------
//                          Notes
// ---------------------------------------------------------------------------
// * This library is still under development.
// * Please see http://www.cs.colorado.edu/~main/bgi for information on
// * using this library with the mingw32 g++ compiler.
// * This library only works with Windows API level 4.0 and higher (Windows 95, NT 4.0 and newer)
// * This library may not be compatible with 64-bit versions of Windows
// ---------------------------------------------------------------------------

我有一个 64 位系统。 这可能会导致一些不兼容问题。

【问题讨论】:

  • 但是,为了通过 C 使用图形,必须将扩展名更改为 C++。我自己也不是很了解,只是按照程序来。
  • 你正在用 C++ 编译,例如"ISO C++ forbids ..." 如果您需要编译为 C,那么您需要告诉我们您使用的是什么编译器。如果使用 VS (cl.exe),则需要传递 /TC 选项。
  • 好的,你调用ld.exe链接,所以你必须使用MinGW作为你的编译器。如果需要编译为 C,请使用 gcc,对于 C++,请使用 g++。您可以在项目的构建设置中进行调整。你所有的"ld.exe||cannot find...: 错误都在告诉你你有路径问题。特别是LD_LIBRARY_PATH。您的编译器没有找到您需要的任何库(包括lstdc++)。在修复之前你不会建造任何东西。
  • 您是安装了与 Code::Block 捆绑版本捆绑在一起的 MinGW,还是单独安装了 MinGW?
  • 我安装了捆绑的。带有 MinGW 的代码块。我正在使用 GNU GCC 编译器和 64 位系统。

标签: c


【解决方案1】:

是的,这就是尝试链接自 2006 年以来未重新编译的库的问题。从那时起,很多事情都发生了变化。我不知道 BGI 是否开源(Borland 和 MS 一样关闭)。但是,他们确实放弃了一些非常过时的东西。可以检查 github 是否有 BGI repo。如果您可以从源代码重建所有内容,那将消除所有不兼容性。但老实说,你为什么要这样做? BGI 类型的图形已经死了二十年。字体不再提供画线字符等...最好寻找其他解决方案。

作者- @David C. Rankin

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 2013-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-12
    相关资源
    最近更新 更多