informix编译痛苦
测试程序:
#include <stdio.h>
#include <stdlib.h>
EXEC SQL INCLUDE sqlca;
int main(int argc, char *argv[])
{
/*打开数据库*/
EXEC SQL DATABASE demodb;
if (sqlca.sqlcode)
{
printf( "[sqlcode=%d] ",sqlca.sqlcode);
return -1;
}
printf( "connect database ok!!!!\n ");
/*关闭数据库*/
EXEC SQL CLOSE DATABASE;
return 0;
}
makefile如下:
INC=-I$(INFORMIXDIR)/incl -I$(INFORMIXDIR)/incl/esql
FLAGS=-DDEBUG
CFLAGS=-g -c $(FLAGS)
CC=cc
ESQL=esql
AR=ar
.SUFFIXES: .ec .c .o
all: iitest clean
.ec.o:
$(ESQL) $(CFLAGS) -o $*.o $(INC) $*.ec
.c.o:
$(CC) $(CFLAGS) -o $*.o $(INC) $*.c
iitest: first.o
$(CC) -o ./iitest first.o $(DBLIBOPTS)
clean:
rm -f *.c *.o
报错如下::::::::::::::::::::::
cc -o ./iitest first.o
first.o(.text+0x27): In function `main ':
/home/rfx/mywork/first.ec:9: undefined reference to `sqli_db_open '
first.o(.text+0x30):/home/rfx/mywork/first.ec:10: undefined reference to `sqlca '
first.o(.text+0x3c):/home/rfx/mywork/first.ec:12: undefined reference to `sqlca '
first.o(.text+0x67):/home/rfx/mywork/first.ec:18: undefined reference to `sqli_db_close '
collect2: ld returned 1 exit status
make: *** [iitest] Error 1
高手们帮忙看看啊,谢谢!!!!
[解决办法]
好高深啊,學習學習
[解决办法]
执行程序编译,应用esql
iitest: first.o
$(CC) -o ./iitest first.o $(DBLIBOPTS)
改为
iitest: first.o
$(ESQL) -o ./iitest first.o $(DBLIBOPTS)
[解决办法]
关键看DBLIBOPTS定义,其中必须有-lifsql -lifasf -lifgen -lifos -lifgls -lc -lm -ldl -lcrypt $INFORMIXDIR/lib/esql/checkapi.o -lifglx,当然这个要视具体的INFORMIX版本而定,可使用esql -libs命令取得Informix LIB选项