makefile初接触

    在SIT实习了20几天,对公司整体架构有个初步而模糊的了解后,我进入了研发部的AAA小组,带我的老师先给了我一堆的文档看,看得人整个晕乎乎的(在学校里可没受过这种罪!)。前几天老师(madeline)叫写一个程序以熟悉cachedb的相关函数,鼓捣了几天,终于于昨天大功告成。以下是我的程序(New0001.cpp):
#include <stdio.h>
#include "cacheapi.h"
#include "cachecursor.h"
#include "cachequery.h"
#include "hdb.h"

int main()
{
            int ret = 0;
            int TabId=20803;
            int IndexId = 0;
            int value;
            int one = 0;
            char *two = NULL;
            char *three =NULL;
            char *four = NULL;
            long long five = 0;
            int six = 0;
            int seven = 0;
            long long eight = 0;
            long long nine = 0;
            long long ten = 0;
            int eleven = 0;
            int twelve = 0;
            long long thirteen = 0;
            long long fourteen = 0;
            char *fifteen = NULL;

        
                            
                CacheDBCursor cdb;

                ret = cdb.syDbInitLog("my log");
                if(ret < 0)
                {
                        printf("初始化日志文件失败!\n");
                        return -1;
                }

                ret = cdb.syDbConnect();
                if(ret < 0)
                {
                         printf("数据库连接失败!\n");
                         return -1;
                }

        /*        ret = cdb.syOpenCursor(TabId,IndexId,value);
if(ret < 0)
{
         printf("Open cursor failed, table CACHE_FIELD_DIC[%d], ret[%d].\n",TabId, ret);    
         return -1;
}

ret = cdb.syFetchCursor();
if(ret < 0)
{
            printf("Get record failed.Table CACHE_FIELD_DIC[%d], ret[%d].\n",TabId, ret);
            return -1;
}*/

ret = cdb.syGetRecord(TabId, IndexId,    value);
if(ret<0)
{
                        printf("Get record failed.Table CACHE_FIELD_DIC[%d],ret[%d].\n",TabId,ret);
         return -1;
}
    
                ret = cdb.syGetInt(1,one);
                if(ret < 0)
                {
                         printf("get one failed.Table CACHE_FIELD_DIC[%d],Fieldid[1],ret[%d]\n",TabId, ret);
                         return -1;
                }

                ret = cdb.syGetStr(2,two);
                if(ret < 0)
                {
                        printf("get two failed.Table CACHE_FIELD_DIC[%d],Fieldid[2],ret[%d]\n",TabId, ret);
                        return -1;
                }

    ret = cdb.syGetStr(3,three);
                if(ret < 0)
                {
                         printf("get three failed.Table CACHE_FIELD_DIC[%d],Fieldid[3],ret[%d]\n",TabId, ret);
                         return -1;
                }

    ret = cdb.syGetStr(4,four);
                if(ret < 0)
                {
                         printf("get four failed.Table CACHE_FIELD_DIC[%d],Fieldid[4],ret[%d]\n",TabId, ret);
                         return -1;
                }

    ret = cdb.syGetLong(5,five);
                if(ret < 0)
                {
                         printf("get five failed.Table CACHE_FIELD_DIC[%d],Fieldid[5],ret[%d]\n",TabId, ret);
                         return -1;
                }

    ret = cdb.syGetInt(6,six);
                if(ret < 0)
                {
                         printf("get six failed.Table CACHE_FIELD_DIC[%d],Fieldid[6],ret[%d]\n",TabId, ret);
                         return -1;
                }

    ret = cdb.syGetInt(7,seven);
                if(ret < 0)
                {
                         printf("get seven failed.Table CACHE_FIELD_DIC[%d],Fieldid[7],ret[%d]\n",TabId, ret);
                         return -1;
                }

    ret = cdb.syGetLong(8,eight);
                if(ret < 0)
                {
                         printf("get eight failed.Table CACHE_FIELD_DIC[%d],Fieldid[8],ret[%d]\n",TabId, ret);
                         return -1;
                }

    ret = cdb.syGetLong(9,nine);
                if(ret < 0)
                {
                         printf("get nine failed.Table CACHE_FIELD_DIC[%d],Fieldid[9],ret[%d]\n",TabId, ret);
                         return -1;
                }

    ret = cdb.syGetLong(10,ten);
                if(ret < 0)
                {
                         printf("get ten failed.Table CACHE_FIELD_DIC[%d],Fieldid[10],ret[%d]\n",TabId, ret);
                         return -1;
                }

    ret = cdb.syGetInt(11,eleven);
                if(ret < 0)
                {
                         printf("get eleven failed.Table CACHE_FIELD_DIC[%d],Fieldid[11],ret[%d]\n",TabId, ret);
                         return -1;
                }

    ret = cdb.syGetInt(12,twelve);
                if(ret < 0)
                {
                         printf("get twelve failed.Table CACHE_FIELD_DIC[%d],Fieldid[12],ret[%d]\n",TabId, ret);
                         return -1;
                }

    ret = cdb.syGetLong(13,thirteen);
                if(ret < 0)
                {
                         printf("get thirteen failed.Table CACHE_FIELD_DIC[%d],Fieldid[13],ret[%d]\n",TabId, ret);
                         return -1;
                }

    ret = cdb.syGetLong(14,fourteen);
                if(ret < 0)
                {
                         printf("get fourteen failed.Table CACHE_FIELD_DIC[%d],Fieldid[14],ret[%d]\n",TabId, ret);
                         return -1;
                }

    ret = cdb.syGetStr(15,fifteen);
                if(ret < 0)
                {
                         printf("get fifteen failed.Table CACHE_FIELD_DIC[%d],Fieldid[15],ret[%d]\n",TabId, ret);
                         return -1;
                }

    
    
                         printf("打印所有取得的值:\n");
            printf("%d            %s            %s            %s            %lld\n",one,two,three,four,five);
            printf("%d            %d            %lld            %lld            %lld\n",six,seven,eight,nine,ten);
            printf("%d            %d            %lld            %lld            %s\n",eleven,twelve,thirteen,fourteen,fifteen);


     ret = cdb.syCloseCursor();    
        return 0;
}
        

  并且要将程序上传到服务器(linux环境),写一个makefile进行编译。我对makefile一点概念也没有,在学校的时候听都没听说过,只好硬着头皮看了很多相关的文档(如《跟我一起写makefile》),才基本明白了个大概。以下是我写的第一个makefile文件(名字就叫makefile):
CC = g++
CFLAGS = -g -Wall
OFLAGS = -g
SOURCE = /home/eagle/New0001.cpp    
OBJPATH = /home/eagle

LIBPATH = -L/home/eagle
LIB = -lcachequery -lhdb
INCS = -I$(OBJPATH)
                            
/home/eagle/New0001:/home/eagle/New0001.o    
  $(CC) $(OFLAGS) /home/eagle/New0001.o -o /home/eagle/New0001 $(LIBPATH) $(LIB)    
/home/eagle/New0001.o:$(SOURCE)
  $(CC) $(CFLAGS) -c $(SOURCE) $(INCS) -o /home/eagle/New0001.o    
    
clean:
  rm -rf New0001 New0001.o
当然并不是一开始就写成上面那样,也是实验了很多次,出了很多错,最后在madeline的指导帮助下得以完成。将New0001.cpp,makefile以及几个库文件libmdbcore.so,libcachequery.so,libhdb.so上传到服务器,然后在linux终端输入make指令就顺利执行了。
当然,执行后还涉及到连接oracle数据库、在oracle查看程序执行情况等,这里就不再赘述了。
还是挺有成就感的,呵呵。
                                                                 龙门鱼
                                                                 2010年10月14日于青岛
 
 

你可能感兴趣的:(c,linux,职场,makefile,休闲)