我在我的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>/span>
#include <string.h>
//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
uj5u.com熱心網友回復:
在命令列的末尾指定庫的內容
gcc -Wall -Wextra -I/home/userX/postgresql/include
-L/home/userX/postgresql/lib -g my_program.c -lpq -lm
// ^^^^^^^^
gcc在命令列中從左到右查看所需的符號。
由于庫在源檔案之前,當gcc處理-llib引數時,它沒有任何要求,因此不會從庫中 "提取 "任何函式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/307979.html
標籤:
