这些代码太肤浅了,不想存在电脑里,拿出来晒在这里把,等哪天忘了还可以拿出来用。
首先是三个helloworld文件。
helloc.c
#include <stdio.h>
void main()
{
printf("hello c world.\n");
}
hellocpp.cpp
#include <iostream>
using namespace std;
int main()
{
cout<<"hello cpp world."<<endl;
return 0;
}
hellof90.f90
program main
write(*,*) "hello fortran world."
end program main
run.sh,(shell脚本文件,不借助makefile)
#!/bin/sh
gcc helloc.c -o 1
g++ hellocpp.cpp -o 2
gfortran hellof90.f90 -o 3
./1
./2
./3
rm 1
rm 2
rm 3
这就是全部文件了。运行:
sh run.sh
就可以测试了。终端显示测试结果:
username@machine:~/test/hello_test$ sh run.sh
hello c world.
hello cpp world.
hello fortran world.
这里值得注意:gfortran编译输出有多一个空格。