如何在Windows的Visual Studio 2015中引入BGI图形库?
Setting up BGI Graphics Library for Visual Studio 2015 (and General Windows VS Guide)
Hey there! I’ve tackled this exact problem for academic projects before, so let me break down how to get BGI working in VS2015, plus the general steps that apply to most Windows versions of Visual Studio.
Step-by-Step for Visual Studio 2015
First, you’ll need the Windows-compatible BGI files: graphics.h, winbgim.h (the Windows adaptation of BGI), and either libbgi.a or bgi.lib. You can find these from trusted academic resources or open-source collections built for BGI on Windows.
Once you have those files, follow these steps:
- Add header files to your project’s include path
- Open your VS2015 project, right-click it in the Solution Explorer, and select Properties.
- Navigate to Configuration Properties > C/C++ > General.
- In the Additional Include Directories field, add the folder path where you stored
graphics.handwinbgim.h.
- Configure library file paths
- Still in the Properties window, go to Linker > General.
- In Additional Library Directories, add the folder containing
libbgi.aorbgi.lib.
- Link the BGI library
- Go to Linker > Input.
- In Additional Dependencies, add the name of your BGI library file (e.g.,
libbgi.aorbgi.lib).
- Add required Windows system libraries
- Head to Linker > Command Line.
- In Additional Options, paste these flags:
These link system libraries that BGI relies on for Windows graphics.-lmsimg32 -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
- Test your setup
- Create a simple test program to verify everything works:
#include <graphics.h> int main() { // Create a 640x480 window initwindow(640, 480, "BGI Test"); // Draw a circle at the center circle(320, 240, 100); // Wait for user input before closing getch(); closegraph(); return 0; } - Compile and run—you should see a window with a circle if everything’s set up correctly.
- Create a simple test program to verify everything works:
General Method for Windows Visual Studio (VS2017+)
The core process is nearly identical to VS2015, with one extra tweak for newer versions:
- Follow steps 1-4 from the VS2015 guide above (header paths, library paths, linking BGI, adding system libraries).
- Set the character set to Multi-Byte
- In your project’s Properties, go to Configuration Properties > General.
- Under Character Set, select Use Multi-Byte Character Set (newer VS versions default to Unicode, which can cause BGI function errors).
Key Notes
- Make sure you’re using a Windows-adapted BGI library (like winbgim)—the original DOS BGI won’t work natively on Windows.
- Match your library file’s architecture (32-bit/64-bit) to your project’s build platform (found under Configuration Manager).
- If you hit compiler errors, double-check that your paths are correctly entered, and verify that
graphics.hdoesn’t have outdated syntax (some versions need small tweaks like replacingint farwithintto work with modern VS compilers).
内容的提问来源于stack exchange,提问作者Salman Ahmed
相关产品推荐
相关产品推荐

