2017-03-17 7 views
0

私はpostgresデータベースに接続するC言語のプログラムを(Windows上に)書いてみたいです。 まず、私は3行C with postgresql

#include <libpq-fe.h> 

に持っていたが、その後、私は

#include "C:/Program Files/PostgreSQL/9.6/include/libpq-fe.h" 

に3行を変えそう

... main.c|3|fatal error: libpq-fe.h: No such file or directory 

エラーが発生しましたが、私はまだエラーが出る

ld.exe||cannot find -lpq-fe.h| 

任意のアイデア?あなたには、ディレクティブにパスを追加しない

#include <stdio.h> 
#include <stdlib.h> 
#include "C:/Program Files/PostgreSQL/9.6/include/libpq-fe.h" 
#include <string.h> 


int main() 
{ 
    PGresult *result; 
    PGconn *conn; 

    conn = PQconnectdb("host=localhost port=5432 dbname=mydb 
      user=postgres password=mypassword"); 

    if(PQstatus(conn) == CONNECTION_OK) { 
    printf("connection made\n"); 
    } 
    else 
    printf("connection failed: %s\n", PQerrorMessage(conn)); 

    PQfinish(conn); 
    return 0; 
} 
+1

https://www.postgresql.org/docs/current/static /libpq-build.html –

答えて

0

、それはあなたがは、コンパイラにディレクトリを含めるとあなたは、ファイルへのパスを指定

#include <libpq-fe.h> 

に固執です。

どのように行うかは、使用しているコンパイラによって異なります。マイクロソフトのVisual Cで

、あなたは、あなたが書くでしょう

cl /I C:/Program Files/PostgreSQL/9.6/include ... 
のMinGWで

gccclを呼び出します

gcc -L C:/Program Files/PostgreSQL/9.6/include ... 
+0

この場合、コードブロックを使用し、コンパイラオプション-L "C:/ Program Files/PostgreSQL/9.6/include"に追加しました。 ld.exe ||が見つかりませんC:\ Program Files \ PostgreSQL \ 9にあります。 6 \ include:許可が拒否されました。 – FiliusBonacci

+0

あなたは答えがあります:*許可が拒否されました*。コンパイラを実行するユーザーにヘッダーファイルを読み取る権限があるように、ファイルとディレクトリのアクセス許可を変更する必要があります。 –