Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 对…函数返回指针的未定义引用_C_Postgresql_Pointers_Libpq - Fatal编程技术网

C 对…函数返回指针的未定义引用

C 对…函数返回指针的未定义引用,c,postgresql,pointers,libpq,C,Postgresql,Pointers,Libpq,制作一个连接到PostgreSQL数据库的头我正在将libpq函数封装到我自己的函数中,但是,在其中一个函数中,假设它返回一个PGconn类型的指针,我得到了一个类型的错误 ConexionPostgres.c:32:6:aviso:la asignación crea un punterro desde un entero sin una conversion[缺陷行为] /tmp/ccCeaewL.o:In functionmain': ConexionPostgres.c:(.text+0

制作一个连接到PostgreSQL数据库的头我正在将libpq函数封装到我自己的函数中,但是,在其中一个函数中,假设它返回一个PGconn类型的指针,我得到了一个类型的错误

ConexionPostgres.c:32:6:aviso:la asignación crea un punterro desde un entero sin una conversion[缺陷行为]
/tmp/ccCeaewL.o:In function
main
':
ConexionPostgres.c:
.text+0x86
:未定义对
setBD
的引用。

我认为这是因为原型,所以我改变了原型,把定义直接放在main之前,但什么都没有…有人能告诉我发生了什么吗

我正在直接查看Postgres libpq文档和libpq fe.h以查看原型,所以我没有遗漏任何东西,但我感到困惑。这是我的密码:

PGconn *setDB(char *conninfo)
{
    PGconn *db;
    db = PQconnectdb(conninfo);

    if(!db)
          printf("Error en conexion a la BD");

    if(PQstatus(db) != CONNECTION_OK)
    {
      printf( "%s\n", PQerrorMessage(db));
    }
    else
    {
        return db;
    }

}

int main()
{

      const char *conninfo = "dbname='database' host='somehost' user='me' password='somepass'";
    //char *query = "INSERT INTO productos VALUES ('1','5','235')";

    PGconn *con;
    con = setBD(conninfo); /* --> Here's apparently the problem */  

    PQfinish(con);
    exit(0);

}

打字错误。您可以调用函数
setBD()
,而定义的函数称为
setDB()

Typo。你调用函数
setBD()
,而定义的函数被调用
setDB()

你链接到
postgre
-库了吗?是的,没有那一行就可以了…你链接到
postgre
-库了吗?是的,没有那一行就可以了…哦,老兄!这么晚编程对我的眼睛不好;我反复检查了我的代码,但没有找到错误,谢谢!天哪!这么晚编程对我的眼睛不好;我反复检查了我的代码,但没有找到错误,谢谢!