Posted on 2008-09-09 19:40
Prayer 阅读(2368)
评论(0) 编辑 收藏 引用 所属分类:
C/C++ 、
DB2
line 1.1: 1506-046 (S) Syntax error.
不能在C语言的第一行写注释//
db2 prep mydb.sqc bindfile
db2 bind mydb.bnd
cc -q64 -ldb2 -I/myuser/sqllib/include mydb.c
"mydb.sqc", line 11.44: 1506-045 (S) Undeclared identifier sqlca.
在main中增加EXEC SQL INCLUDE SQLCA;
或者在main之前增加
"mydb.sqc", line 13.43: 1506-280 (W) Function argument assignment between types "struct sqlca*" and "struct sqlca*" is not allowed.
增加头文件#include <sqlca.h>
ld: 0706-006 Cannot find or open library file: -l db2
ld:open(): A file or directory in the path name does not exist.
cc -q64 -L "/myuser/sqllib/lib" -I "/myuser/sqllib/include" mydb.c
出现这个错误
ld: 0711-317 ERROR: Undefined symbol: .sqlastrt
ld: 0711-317 ERROR: Undefined symbol: .sqlaaloc
ld: 0711-317 ERROR: Undefined symbol: .sqlasetdata
ld: 0711-317 ERROR: Undefined symbol: .sqlacall
ld: 0711-317 ERROR: Undefined symbol: .sqlastop
cc -q64 -L "/myuser/sqllib/lib" -ldb2 -I "/myuser/sqllib/include" mydb.c
编译通过。
可能跟配的环境有关系。
具体配置差异没有找出来。
源代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sqlca.h>
int main()
{
EXEC SQL INCLUDE SQLCA;
EXEC SQL BEGIN DECLARE SECTION;
char cd[13+1];
char nm[255+1];
EXEC SQL END DECLARE SECTION;
EXEC SQL CONNECT TO INFDB USER usr USING passwd;
EXEC SQL SELECT CD INTO :cd FROM TBL_INF fetch first 1 row only;
printf("ID is %s\n",cd);
EXEC SQL DISCONNECT CURRENT;
return 0;
}