|
-DHAVA_NAMESPACE_STD和-DDLLIMPORT
当我输入下面的命令的时候可以编译通过:
- g++ -DHAVE_NAMESPACE_STD -DDLLIMPORT="" -I/usr/local/pgsql/include -o cpptest cpptest.cc -L/usr/local/pgsql/lib -lpq++
复制代码
如果把-DHAVE_NAMESPACE_STD和-DDLLIMPORT=""去掉(或去掉任何一个)就会出现如下错误:
- In file included from /usr/local/pgsql/include/libpq++.h:30,
- from cpptest.cc:2:
- /usr/local/pgsql/include/libpq++/pgconnection.h:49: syntax error before `{'
- token
- /usr/local/pgsql/include/libpq++/pgconnection.h:55: syntax error before `public
- '
- /usr/local/pgsql/include/libpq++/pgconnection.h:57: destructors must be member
- functions
- /usr/local/pgsql/include/libpq++/pgconnection.h:57: virtual outside class
- declaration
- /usr/local/pgsql/include/libpq++/pgconnection.h:60: non-member function `
- ConnStatusType Status()' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgconnection.h:61: non-member function `bool
- ConnectionBad()' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgconnection.h:62: non-member function `const
- char* ErrorMessage()' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgconnection.h:65: non-member function `const
- char* DBName()' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgconnection.h:76: syntax error before `
- protected'
- /usr/local/pgsql/include/libpq++/pgconnection.h:79: syntax error before `('
- token
- /usr/local/pgsql/include/libpq++/pgconnection.h:81: ISO C++ forbids declaration
- of `PgConnection' with no type
- /usr/local/pgsql/include/libpq++/pgconnection.h:81: new declaration `int
- PgConnection()'
- /usr/local/pgsql/include/libpq++/pgconnection.h:57: ambiguates old declaration
- `void PgConnection()'
- /usr/local/pgsql/include/libpq++/pgconnection.h:83: syntax error before `
- private'
- /usr/local/pgsql/include/libpq++/pgconnection.h:87: syntax error before `&'
- token
- In file included from /usr/local/pgsql/include/libpq++.h:31,
- from cpptest.cc:2:
- /usr/local/pgsql/include/libpq++/pgdatabase.h:37: syntax error before `:' token
- /usr/local/pgsql/include/libpq++/pgdatabase.h:45: destructors must be member
- functions
- /usr/local/pgsql/include/libpq++/pgdatabase.h:51: non-member function `
- size_type Tuples()' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:52: non-member function `
- size_type CmdTuples()' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:54: non-member function `const
- char* FieldName(int)' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:55: non-member function `int
- FieldNum(const char*)' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:56: non-member function `Oid
- FieldType(int)' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:57: non-member function `Oid
- FieldType(const char*)' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:58: non-member function `int
- FieldSize(int)' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:59: non-member function `int
- FieldSize(const char*)' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:60: non-member function `const
- char* GetValue(int, int)' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:61: non-member function `const
- char* GetValue(int, const char*)' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:62: non-member function `bool
- GetIsNull(int, int)' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:63: non-member function `bool
- GetIsNull(int, const char*)' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:64: non-member function `int
- GetLength(int, int)' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:65: non-member function `int
- GetLength(int, const char*)' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:69: non-member function `void
- DisplayTuples(FILE*, bool, const char*, bool, bool)' cannot have `const'
- method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:71: non-member function `void
- PrintTuples(FILE*, bool, bool, bool)' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:76: non-member function `const
- char* OidStatus()' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgdatabase.h:79: syntax error before `
- protected'
- /usr/local/pgsql/include/libpq++/pgdatabase.h:88: syntax error before `&' token
- In file included from /usr/local/pgsql/include/libpq++.h:32,
- from cpptest.cc:2:
- /usr/local/pgsql/include/libpq++/pglobject.h:38: syntax error before `:' token
- /usr/local/pgsql/include/libpq++/pglobject.h:43: 'string' is used as a type,
- but is not defined as a type.
- /usr/local/pgsql/include/libpq++/pglobject.h:46: syntax error before `public'
- /usr/local/pgsql/include/libpq++/pglobject.h:48: ISO C++ forbids declaration of
- `PgLargeObject' with no type
- /usr/local/pgsql/include/libpq++/pglobject.h:48: only declarations of
- constructors can be `explicit'
- /usr/local/pgsql/include/libpq++/pglobject.h:49: destructors must be member
- functions
- /usr/local/pgsql/include/libpq++/pglobject.h:57: non-member function `int
- Tell()' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pglobject.h:62: syntax error before `)' token
- /usr/local/pgsql/include/libpq++/pglobject.h:68: syntax error before `&' token
- In file included from /usr/local/pgsql/include/libpq++.h:33,
- from cpptest.cc:2:
- /usr/local/pgsql/include/libpq++/pgtransdb.h:38: syntax error before `:' token
- /usr/local/pgsql/include/libpq++/pgtransdb.h:44: destructors must be member
- functions
- /usr/local/pgsql/include/libpq++/pgtransdb.h:49: syntax error before `protected
- '
- /usr/local/pgsql/include/libpq++/pgtransdb.h:59: syntax error before `&' token
- /usr/local/pgsql/include/libpq++/pgtransdb.h:59: ISO C++ forbids declaration of
- `PgTransaction' with no type
- /usr/local/pgsql/include/libpq++/pgtransdb.h:60: syntax error before `&' token
- In file included from /usr/local/pgsql/include/libpq++.h:34,
- from cpptest.cc:2:
- /usr/local/pgsql/include/libpq++/pgcursordb.h:44: syntax error before `:' token
- /usr/local/pgsql/include/libpq++/pgcursordb.h:50: destructors must be member
- functions
- /usr/local/pgsql/include/libpq++/pgcursordb.h:53: `string' was not declared in
- this scope
- /usr/local/pgsql/include/libpq++/pgcursordb.h:53: syntax error before `,' token
- /usr/local/pgsql/include/libpq++/pgcursordb.h:56: new declaration `int Close()'
- /usr/local/pgsql/include/libpq++/pglobject.h:53: ambiguates old declaration `
- void Close()'
- /usr/local/pgsql/include/libpq++/pgcursordb.h:60: non-member function `const
- char* Cursor()' cannot have `const' method qualifier
- /usr/local/pgsql/include/libpq++/pgcursordb.h: In function `const char*
- Cursor()':
- /usr/local/pgsql/include/libpq++/pgcursordb.h:61: `pgCursor' undeclared (first
- use this function)
- /usr/local/pgsql/include/libpq++/pgcursordb.h:61: (Each undeclared identifier
- is reported only once for each function it appears in.)
- /usr/local/pgsql/include/libpq++/pgcursordb.h: At global scope:
- /usr/local/pgsql/include/libpq++/pgcursordb.h:65: `string' was not declared in
- this scope
- /usr/local/pgsql/include/libpq++/pgcursordb.h:65: syntax error before `)' token
- /usr/local/pgsql/include/libpq++/pgcursordb.h: In function `void Cursor(...)':
- /usr/local/pgsql/include/libpq++/pgcursordb.h:67: `cursor' undeclared (first
- use this function)
- /usr/local/pgsql/include/libpq++/pgcursordb.h: At global scope:
- /usr/local/pgsql/include/libpq++/pgcursordb.h:70: syntax error before `
- protected'
- /usr/local/pgsql/include/libpq++/pgcursordb.h:85: syntax error before `&' token
- cpptest.cc: In function `int main()':
- cpptest.cc:8: `PgDatabase' undeclared (first use this function)
- cpptest.cc:8: syntax error before `(' token
- cpptest.cc:9: `data' undeclared (first use this function)
复制代码
请问这是为什么? :confused: :confused: :confused:
下面是我的代码:
- /** cpptest.cc*/
- #include <iostream>
- #include <libpq++.h>
- using namespace std;
- int main() {
- char query_string[256]= "SELECT * FROM v;";
- PgDatabase data("dbname = test");
- if (data.ConnectionBad()) {
- cout <<"connected failed" << endl;
- cout <<"Error is "<<data.ErrorMessage() << endl;
- exit(1);
- }
- if (! data.ExecTuplesOk(query_string)) {
- cout<<"Query Failed!" << endl;
- exit(1);
- }
- for(int k=0; k<data.Fields(); k++) /**显示字段名称*/ {
- cout<<data.FieldName(k);
- cout <<" " ;
- }
- cout<<endl;
- for (int i = 0; i < data.Tuples(); i++) /**取得查询结果的记录数量*/ {
- for(int k=0; k<data.Fields(); k++) {
- cout << data.GetValue(i,k);
- cout <<" | " ;
- }
- cout<<endl;
- }
- return 0 ;
- }
复制代码 |
|