首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PostgreSQL ECPG数据库连接问题

PostgreSQL ECPG数据库连接问题
EN

Stack Overflow用户
提问于 2020-03-20 20:54:03
回答 1查看 105关注 0票数 1

我正在尝试连接到PostgreSQL数据库使用ecpg程序,我得到下面的错误。

代码语言:javascript
复制
cc testecpg.c
/tmp/ccSzqgA7.o: In function `main':
testecpg.c:(.text+0x5d): undefined reference to `ECPGconnect'
testecpg.c:(.text+0x62): undefined reference to `ECPGget_sqlca'
testecpg.c:(.text+0x70): undefined reference to `sqlprint'
collect2: error: ld returned 1 exit status

执行ecpg testecpg.pgc后生成的testecpg.c文件

代码语言:javascript
复制
/* Processed by ecpg (4.11.0) */
/* These include files are added by the preprocessor */
#include "/opt/rh/rh-postgresql95/root/usr/include/ecpglib.h"
#include "/opt/rh/rh-postgresql95/root/usr/include/ecpgerrno.h"
#include "/opt/rh/rh-postgresql95/root/usr/include/sqlca.h"
/* End of automatic include section */

#line 1 "testecpg.pgc"
#include <stdio.h>
#include "/opt/rh/rh-postgresql95/root/usr/include/libpq-fe.h"
int main(void)
{
/* exec sql begin declare section */

#line 6 "testecpg.pgc"
 char * dbname = "dbname" ;

#line 7 "testecpg.pgc"
 char * db = "dbname@hostname:5432" ;

#line 8 "testecpg.pgc"
 char * user = "user" ;

#line 9 "testecpg.pgc"
 char * passwd = "password" ;

#line 10 "testecpg.pgc"
 const char * target = "dbname@hostname:5432" ;
/* exec sql end declare section */
#line 11 "testecpg.pgc"

/* exec sql whenever sqlerror  sqlprint ; */
#line 12 "testecpg.pgc"

{ ECPGconnect(0, 0, target , user , passwd , NULL, 0);
#line 13 "testecpg.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 13 "testecpg.pgc"

printf("connection succssfull");
}

是否有需要包含的库或我遗漏了什么步骤?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-20 21:14:50

你忘了链接ECPG库了。

在Unix系统上,这看起来有点像

代码语言:javascript
复制
cc -o testecpg testecpg.c -lecpg

您必须添加适当的-I-L选项,以便编译器能够找到包含文件和库。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60774590

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档