teiller2008

    我是在windows xp-sp2上使用SSHSecureShellClient-3[1].2.9.exe进行linuxC编程的,下面先讲一下怎么使用这个软件:

    在本地安装SSHSecureShellClient-3[1].2.9.exe,在服务器上建立用户名和密码,然后打开SSH Secure Shell Client,enter键或者点击quick connect,输入目标机(我不懂,瞎叫)ip,输入用户名,enter键,输入密码。现在你应该已经进入linux了,在这里所有的linux命令都可以使用,新手不妨先敲几个常用的命令试一下!

    下面从最简单的hello word讲到比较复杂的库引用,当然怎么写通用的makefile限于水平,不做讨论。

    1、hello word

    1)、程序:

 #include <stdio.h>

int main(void)
{
 printf ("hello, wordn");

 return 0;
}
名字为helloword.c

    2)、运行:

    进入SSH Secure Shell Client,使用 《cd 路径名》进入到你的helloword.c所在的目录,

    然后gcc -o helloword helloword.c,下面将显示编译的情况,有错误和警告将会列出,没有则不显示而返回的你刚才进的目录,要运行则输入。/helloword, 这样就会看到hello, word

    2、编译多个。c和。h文件组成的程序,这时需要写makefile

    1)、程序:

 #include "mytool1.h"
#include "mytool2.h"

int main(int argc,char **argv)
{
mytool1_print("hello");
mytool2_print("hello");
}

名字为main.c

#include "mytool1.h"
void mytool1_print(char *print_str)
{
printf("This is mytool1 print %sn",print_str);
}
名字为mytool1.c

#ifndef _MYTOOL_1_H
#define _MYTOOL_1_H 

void mytool1_print(char *print_str);

#endif
名字为mytool1.h

#include "mytool2.h"
void mytool2_print(char *print_str)
{
printf("This is mytool2 print %sn",print_str);
}
名字为mytool2.c

#ifndef _MYTOOL_2_H
#define _MYTOOL_2_H

void mytool2_print(char *print_str);

#endif
名字为mytool2.h

    2)、makefile

 main:main.o mytool1.o mytool2.o
 gcc -o main main.o mytool1.o mytool2.o
 main.o:main.c mytool1.h mytool2.h
 gcc -c main.c
 mytool1.o:mytool1.c mytool1.h
 gcc -c mytool1.c
 mytool2.o:mytool2.c mytool2.h
 gcc -c mytool2.c

    3)/运行

 [root@svn helloword]# cd -
/home/mengj
[root@svn mengj]# cd makefileexample
[root@svn makefileexample]# make
cc﹛﹛﹛ -c -o main.o main.c
cc﹛﹛﹛ -c -o mytool1.o mytool1.c
mytool1.c: In function 滵ytool1_print?
mytool1.c:4: warning: incompatible implicit declaration of built-in function 漥rintf?
cc﹛﹛﹛ -c -o mytool2.o mytool2.c
mytool2.c: In function 滵ytool2_print?
mytool2.c:4: warning: incompatible implicit declaration of built-in function 漥rintf?
gcc -o main main.o mytool1.o mytool2.o
main.o:main.c mytool1.h mytool2.h
make: main.o:main.c: Command not found
make: *** [main] Error 127
[root@svn makefileexample]# ./main
This is mytool1 print hello
This is mytool2 print hello
[root@svn makefileexample]#

    上面就是这个程序的运行过程

推荐一个学习编程的网站,96堆栈 软件编程网http://www.96dz.com,上面有很多编程教学的视频教程下载。

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-04-05
  • 2021-06-23
  • 2021-07-28
  • 2022-12-23
  • 2021-08-31
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-07
  • 2021-08-25
  • 2021-12-23
  • 2021-10-04
  • 2021-08-14
  • 2022-12-23
相关资源
相似解决方案