RtnWait sleepするshared library for DataStage routine
DataStageジョブのsleepするroutine
routineはDataStageジョブのtransformerから呼び出し変換に使用するが、ジョブの実行時間を恣意的に伸ばしたい場合に使用する。
GNU g++でコンパイル、リンクする。
source code:
/*
* FileName: RtnWait.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
char *RtnWait(int interval) {
static char rc[256];
sprintf(rc,"RtnWait was sleeping %d seconds.\n",interval);
int mil = 1000000;
if (interval <= 0) {
sprintf(rc,"RtnWait Interval must be grater than 0.\n",interval);
}
usleep(mil * interval);
return rc;
}
makefile:
SRCDIR = .
OBJDIR = .
TARGETDIR = /usr/local/lib
CODESRC = $(SRCDIR)/RtnWait.c
TARGETOBJ = $(OBJDIR)/RtnWait.o
TARGETLIB = $(TARGETDIR)/libRtnWait.so
CC = g++
CCOPTIONS = -c -O -fPIC -Wno-deprecated -m64 -mtune=generic -mcmodel=small
LIBCC = $(CC)
LDOPTIONS = -shared -m64
#------------------------------
# Compile Rule
#------------------------------
all: $(TARGETLIB)
$(TARGETLIB): $(TARGETOBJ)
$(LIBCC) $(LDOPTIONS) $(TARGETOBJ) -o $(TARGETLIB)
$(TARGETOBJ): $(CODESRC)
$(CC) $(CCOPTIONS) -c $(CODESRC) -o $(TARGETOBJ)
clean:
@rm -f $(TARGETOBJ) $(TARGETLIB)
install:
@cp -p $(TARGETLIB) $(TARGETDIR)
C programからの呼び出し:
test_RtnWait.c
#include <stdio.h>
#include <stdlib.h>
extern char *RtnWait(int interval);
int main()
{
int interval = 10;
char *rc = RtnWait(interval);
printf("Test RtnWait\n");
printf("Input=%d\n",interval);
printf("rc=%s\n",rc);
return 0;
}
test_RtnWait.mk
SRCDIR = .
OBJDIR = .
LIBDIR = .
TARGETDIR = /usr/local/lib
TARGETLIB = $(LIBDIR)/test_RtnWait
TARGETOBJ = $(OBJDIR)/test_RtnWait.o
TARGETSRC = $(SRCDIR)/test_RtnWait.c
# dynamic link library
# -L$(LOOKUPDIR) -l$(LOOKUPLIB)
LOOKUPDIR = .
LOOKUPLIB =RtnWait
CC = g++
CCOPTIONS = -c -O -fPIC -Wno-deprecated -m64 -mtune=generic -mcmodel=small
LIBCC = $(CC)
LDOPTIONS = -m64
.SUFFIXES: .c .o
# -------------------------------
# rules
# -------------------------------
all: $(TARGETLIB)
$(TARGETLIB): $(TARGETOBJ)
$(LIBCC) $(LDOPTIONS) -L$(LOOKUPDIR) -l$(LOOKUPLIB) $(TARGETOBJ) -o $(TARGETLIB)
$(TARGETOBJ): $(TARGETSRC)
$(CC) $(CCOPTIONS) $(TARGETSRC) -o $(TARGETOBJ)
clean:
@rm -f $(TARGETOBJ) $(TARGETLIB)
install:
@cp -p $(TARGETLIB) $(TARGETDIR)
OBJDIR = .
LIBDIR = .
TARGETDIR = /usr/local/lib
TARGETLIB = $(LIBDIR)/test_RtnWait
TARGETOBJ = $(OBJDIR)/test_RtnWait.o
TARGETSRC = $(SRCDIR)/test_RtnWait.c
# dynamic link library
# -L$(LOOKUPDIR) -l$(LOOKUPLIB)
LOOKUPDIR = .
LOOKUPLIB =RtnWait
CC = g++
CCOPTIONS = -c -O -fPIC -Wno-deprecated -m64 -mtune=generic -mcmodel=small
LIBCC = $(CC)
LDOPTIONS = -m64
.SUFFIXES: .c .o
# -------------------------------
# rules
# -------------------------------
all: $(TARGETLIB)
$(TARGETLIB): $(TARGETOBJ)
$(LIBCC) $(LDOPTIONS) -L$(LOOKUPDIR) -l$(LOOKUPLIB) $(TARGETOBJ) -o $(TARGETLIB)
$(TARGETOBJ): $(TARGETSRC)
$(CC) $(CCOPTIONS) $(TARGETSRC) -o $(TARGETOBJ)
clean:
@rm -f $(TARGETOBJ) $(TARGETLIB)
install:
@cp -p $(TARGETLIB) $(TARGETDIR)
実行例:
パスが通っていないとエラーが出力される。
# echo $LD_LIBRARY_PATH
# ./test_RtnWait
./test_RtnWait: error while loading shared libraries: libRtnWait.so: cannot open shared object file: No such file or directory
パスを通すと
# export LD_LIBRARY_PATH=/usr/local/lib
# ./test_RtnWait
Test RtnWait
Input=10
rc=RtnWait was sleeping 10 seconds.
コメント
コメントを投稿