【发布时间】:2021-11-11 09:44:52
【问题描述】:
我在我的 c 程序中使用了search.h,我需要将#define _GNU_SOURCE 放在第一行以引入多个哈希表。但在那之后,像undefined reference to 'log10' 和undefined reference to 'PQntuples' 这样的错误弹出。我当然需要那里的所有包,我现在应该如何编译程序?任何帮助将不胜感激!谢谢。
标题:
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <math.h>
#include <string.h>
// library for psql
#include <libpq-fe.h>
#include <unistd.h>
#include <time.h>
#include <search.h>
int main(void){
char host[] = "localhost";
char port[] = "5432";
char db_name[] = "db_name";
char user[] = "test_usr";
char password[] = "123456";
sprintf(db_str, "host=%s port=%s dbname=%s user=%s password=%s",
host, port, db_name, user, password);
PGconn *db_connection = DBConnect(db_str);
struct hsearch_data htab;
hcreate_r(10, &htb);
ENTRY e, *ep;
e.key = "test";
e.data = (void *) 1;
hsearch_r(e, ENTER, &ep, &htab);
}
这就是我编译文件的方式:
gcc -Wall -Wextra -I/home/userX/postgresql/include -L/home/userX/postgresql/lib -lm -lpq -g my_program.c
【问题讨论】:
-
@kaylum 我更新了
-
什么是
db_str和htb?
标签: c postgresql posix gnu undefined-reference