DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Notes about 21st Century C


  • 第10页,"gcc erf.c -o erf -lm -g -Wall -O3 -std=gnu11"指令,Ubuntu 11和Red Hat 5都不识别"-std=gnu11"选项,都能够识别"-std=gnu99"选项,都能够正常运行"c99 erf.c -o erf -lm -g -Wall -O3"指令。

  • Ubuntu能够正常运行第15页的makefile,Red Hat(服务器47)不能正常编译。

  • 第21页:Using Libraries from Source一节,Red Hat上安装gsl库后pkg-config指令找不到路径,可能是权限问题导致的;Ubuntu上安装gsl库后pkg-config指令能找到安装位置,make指令编译能正常生成可执行文件,但执行时报下面的错误:

./gsl_erf: error while loading shared libraries: libgsl.so.0: cannot open shared object file: No such file or directory

  • 第27页:Compiling form stdin一节介绍的在命令行中运行C代码的方法在Ubuntu上试验成功,首先在$HOME下新建一个allheads.h文件,内容为(与书中P26页内容一样,但不包括最后一行,否则会提示gsl_rng.h文件找不到):

#include #include #include #include #include

#include // #include

然后修改.bashrc文件,在文件末尾增加下面3行内容(书中第28页):

go_libs="-lm" go_flags="-g -Wall -include allheads.h -O3" alias go_c="c99 -xc '-' $go_libs $go_flags"

然后在命令行下输入:

go_c << '---' int main(){printf("Hello from the command line.\n");}


没有报错说明正常编译完成,这时当前件夹下会出现一个a.out文件,用./a.out运行之,可以看到运行结果:

Hello from the command line.



Published

Dec 20, 2012

Last Updated

Dec 20, 2012

Category

Tech

Tags

  • C 12

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor