您的位置:首页 > 运维架构 > Linux

linux 使用github和eclipse管理C工程

2014-09-04 16:10 316 查看
这篇文章http://blog.csdn.net/stormragewang/article/details/39025331中介绍了怎么在linux下生成ssh密匙和加入到系统中,下面介绍下在linux下使用github和eclipse管理C工程。

1、在github下新建一个仓库

怎么申请账号什么的就不介绍了,申请完账号后在个人主页右下角点击“新建仓库"



在向导页中填入必要的信息



仓库建立完成后,将生成的ssh密匙的公钥添加到仓库中,点击仓库主页的setting链接



点击"Deploy keys" 



点击 "Add deploy key"



输入完成后点击”Add key"



这样github上仓库的设置就完成了

2、在linux客户端对仓库进行操作

2.1、克隆该工程

[WangZhi@Panda-CentOS ~]$cd GitProjects/
[WangZhi@Panda-CentOS GitProjects]$git clone git@github.com:wangzhics/TestGitHub.git
Initialized empty Git repository in /home/WangZhi/GitProjects/TestGitHub/.git/
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
2.2、将工程导入eclipse(已经安装CDT插件)中

选择 “File" -> "Import" -> "Existing Code as Makefile Project"



选择本地克隆的工程仓库目录,并设置编译器



点击”Finish“就完成了



有时候添加的工程没有自动和github关联,右键点击工程”Team“ -> ”Share"



点击下一步就可以了。

2.3、完成Helloword代码的创建



此时需要在src目录下新建一个Makefile文件,指定程序的规则。简单的Makefile实现如下

CC = gcc -Wall

all: helloworld

clean :
rm -f *.o helloworld

helloworld: helloworld.o
${CC} -o helloworld helloworld.o

helloworld.o:
${CC} -c helloworld.c
同时,注意工程默认的编译路径是工程的目录(我这个示例为:/home/WangZhi/GitProjects/TestGitHub),需要修改下

右键点击工程 “Properties" -> "C/C++ Build" -> "Build Location"



2.4、修改.gitignore文件忽略src下的中间文件和结果文件,以及工程设置文件



2.5、将新建的源文件和修改的.gitignore文件提交到本地(提交时必须添加注释信息),完成后结果如图



2.6、去工程根目录使用git push命令提交到github服务器上

[WangZhi@Panda-CentOS TestGitHub]$git push
Counting objects: 8, done.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 678 bytes, done.
Total 6 (delta 1), reused 0 (delta 0)
To git@github.com:wangzhics/TestGitHub.git
c8bd894..d6fc1ea master -> master
[WangZhi@Panda-CentOS TestGitHub]$
在github服务器上可以看到提交的信息



3、其他

在调试程序是,默认的程序调试入口是工程根目录下的debug文件,这样在运行时设计到文件的操作就容易出现路径上的问题,我们可以在Debug Configurations 中设置debug的入口路径

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  github c linux eclipse