标签:
说明:以下操作均在Ubuntu 14.04.4 LTS环境下进行,因为我的电脑(asus ux305la)因为BIOS原因不能装win7/8.
绘制dos图形需要用到graphics.h头文件,gcc编译如下代码
1 // file eg1.cpp 2 #include <graphics.h> 3 #include <conio.h> 4 void main() { 5 initgraph(640, 480); 6 line(200, 240, 440, 240); 7 line(320, 120, 320, 360); 8 getch(); 9 closegraph(); 10 }
提示“找不到graphics.h”,
eg1.cpp:1:22: fatal error: graphics.h: No such file or directory
#include <graphics.h>
^
compilation terminated.
所以按照如下步骤配置相应的头文件和库[1],
- First download WinBGIm from http://winbgim.codecutter.org/ Extract it.
- Copy graphics.h and winbgim.h files in include folder of your compiler directory[2]
- Copy libbgi.a to lib folder of your compiler directory
使用命令查看gcc头文件搜索路径[3]:
$echo | gcc -v -x c -E -
...
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/4.8/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include...
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../:/lib/:/usr/lib/...
从http://winbgim.codecutter.org/下载的压缩包有三个文件winbgim.h、graphics.h和libbgi.a。
按照上面的路径显示结果,我将winbgim.h和graphics.h拷贝到/usr/lib/gcc/x86_64-linux-gnu/4.8/include下,把libbgi.a拷贝到/usr/lib/gcc/x86_64-linux-gnu/4.8下。
再次编译,
In file included from eg1.cpp:1:0:
/usr/lib/gcc/x86_64-linux-gnu/4.8/include/graphics.h:28:64: fatal error: windows.h: No such file or directory
#include <windows.h> // Provides the mouse message types
^
compilation terminated.
这次提示找不到“windows.h”头文件,这个问题可以使用Linux的MingGW交叉编译得到Windows上可执行文件。但这样做没有意义啊,我是linux操作系统,仍然不能用。
接下来尝试在学校机房弄一下,或是我使用java编写。
[1] How to use graphics.h in codeblocks
[2] How do I show what the default include path is
[3] gcc编译时查看头文件搜索路径
[4] 俄罗斯方块源码
标签:
原文地址:http://www.cnblogs.com/wuyucheng/p/5658710.html