c4,configure the debug environment

时间:2021-07-25 10:52:10

  Yesterday I found a tiny C compiler (less than 600 line of C code, containing commits) called "c4" on github and I wanted to know how I can write a compiler in details.

  During the process, I encounter the following problems:

1> Can not compile c4 on Windows platform, because no "unistd.h" on Windows.

solution: replace the include sentence by the following statements:

  许多在Linux下开发的C程序都需要头文件unistd.h,但VC中没有个头文件, 
  所以用VC编译总是报错。把下面的内容保存为unistd.h,可以解决这个问题。
    1.   /** This file is part of the Mingw32 package.
    2.    *  unistd.h maps     (roughly) to io.h
    3.    */
    4.   #ifndef _UNISTD_H
    5.   #define _UNISTD_H
    6.   #include <io.h>
    7.   #include <process.h>
    8.   #endif /* _UNISTD_H */

2> IDEs:

First tried Vitual Studio 2013, it was hard for me to get used the VS after some many years' leave. I could not find the proper functions to satisfy my needs.

Eclipse: Downloaded the Eclipse-CDT(for C/C++ development). Dowload the minGW project, containing the gcc and other lib file for windows. Configure eclipse, it is not complicated after I configure the BarLearner project from Cristian. Just make the build system right, and adjust the run configuration. But I fould I could not the value of global values and for most pointers, I could only see the address its point to rather than the  content (for example, I wanted to see an array, but got nothing useful for me.) Searching on the Internet, someone said we can see the global values on "Watch" windows. However, I did not think so after trying. I gave it up temporary.

VC6.0: This is a very old platform I had been working on for years. It took me time to install VC 6.0 on Windows 8.1. Here are some useful solution for the installation:

  “1 改名 MSDEV.EXE改成 MSDEV3.EXE
  2 兼容模式修改成 winxp sp2 或者sp3
  3 启动MSDEV3.EXE,如果报错,关闭,立刻再次启动,一般就可以正常启动了,成功启动一次后,以后就可以正常运行了
  4 取消兼容模式,如果运气好,也可以正常运行了,如果不介意,就一直用兼容模式运行也可以"
 
After that, I found VC 6.0 can not show line number by default. WTF! I need a plug in to complete this need.
  1. 如果你的VC安装在C盘,请拷贝文件VC6LineNumberAddin.dll到如下目录: C:\Program Files\Microsoft Visual Studio\Common\MSDev98\AddIns 
  2. 注册 
  双击VC6LineNumberAddin.reg进行注册。
  3. 启用 
  打开vc6,菜单栏:Tools -> customize -> Add-ins and Macro Files 选中VC6LineNumber Developer Studio Add-in
  关闭VC,重启VC即可。
Also, I got a link for setting up vim+GDB environment: