如何在Linux上使用C ++查询Informix数据库?使用C ++的Object Interface时出现编译器错误

时间:2011-07-28 09:06:33

标签: c++ linux informix

我使用IBM提供的C ++ Object Interface编写了下面的代码。我想在RHEL(Linux)上编译它:

#include <it.h>
#include <iostream.h>

int main() {
    ITDBInfo db("dbname","user","pwd","system"); 
    ITConnection conn(db);
    conn.Open();

    if ( conn.Error() ) {
        cout << "Couldn't open connection" << endl;
        return -1;
    }

    ITQuery query( conn );    
    ITRow *row;
    if( !(row = query.ExecOneRow( "select lname from customer;" )) ) {
        cout << "Couldn't select from table customer" << endl;
        return -1;
    }

    while ((row = query.NextRow()) != NULL) {
        cout << row->Printable() << endl;
    }

    row->Release();
    conn.Close();
}

在Linux上编译时这样:

g++ -Wno-deprecated -I/opt/Informix/11.5FC8/incl/c++ \
    -I/opt/Informix/11.5FC8/incl/public \
    -L/opt/Informix/11.5FC8/lib/c++ -g -o test1 test1.cpp

我收到如下错误:

/tmp/cchJkPb1.o: In function `main':
test1.cpp:(.text+0x82): undefined reference to `ITString::ITString(char const*)'
test1.cpp:(.text+0x90): undefined reference to `ITString::ITString(char const*)'
test1.cpp:(.text+0x9e): undefined reference to `ITString::ITString(char const*)'
test1.cpp:(.text+0xac): undefined reference to `ITString::ITString(char const*)'
test1.cpp:(.text+0xc8): undefined reference to `ITDBInfo::ITDBInfo(ITString const&, ITString const&, ITString const&, ITString const&)'
test1.cpp:(.text+0xd1): undefined reference to `ITString::~ITString()'
test1.cpp:(.text+0xea): undefined reference to `ITString::~ITString()'
test1.cpp:(.text+0xfc): undefined reference to `ITString::~ITString()'
test1.cpp:(.text+0x115): undefined reference to `ITString::~ITString()'
test1.cpp:(.text+0x127): undefined reference to `ITString::~ITString()'
/tmp/cchJkPb1.o:test1.cpp:(.text+0x140): more undefined references to `ITString::~ITString()' follow
/tmp/cchJkPb1.o: In function `main':
test1.cpp:(.text+0x15f): undefined reference to `ITConnection::ITConnection(ITDBInfo const&)'
test1.cpp:(.text+0x178): undefined reference to `ITString::~ITString()'
test1.cpp:(.text+0x194): undefined reference to `ITConnection::Open()'
test1.cpp:(.text+0x19d): undefined reference to `ITErrorManager::Error() const'
test1.cpp:(.text+0x1e6): undefined reference to `ITQuery::ITQuery(ITConnection const&)'
test1.cpp:(.text+0x1f4): undefined reference to `ITString::ITString(char const*)'
test1.cpp:(.text+0x209): undefined reference to `ITQuery::ExecOneRow(ITString const&, ITEssential**)'
test1.cpp:(.text+0x222): undefined reference to `ITString::~ITString()'
test1.cpp:(.text+0x23b): undefined reference to `ITString::~ITString()'
test1.cpp:(.text+0x2a6): undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, ITString const&)'
test1.cpp:(.text+0x2c4): undefined reference to `ITQuery::NextRow(ITEssential**)'
test1.cpp:(.text+0x2f1): undefined reference to `ITConnection::Close()'
test1.cpp:(.text+0x317): undefined reference to `ITQuery::~ITQuery()'
test1.cpp:(.text+0x32c): undefined reference to `ITQuery::~ITQuery()'
test1.cpp:(.text+0x366): undefined reference to `ITConnection::~ITConnection()'
test1.cpp:(.text+0x378): undefined reference to `ITConnection::~ITConnection()'
test1.cpp:(.text+0x3b2): undefined reference to `ITDBInfo::~ITDBInfo()'
test1.cpp:(.text+0x3ce): undefined reference to `ITDBInfo::~ITDBInfo()'
collect2: ld returned 1 exit status

目录/opt/Informix/11.5FC8/lib/c++列在LD_LIBRARY_PATH中。任何人都可以帮我摆脱这些错误吗?

1 个答案:

答案 0 :(得分:2)

您实际上并未使用-l命令行参数链接到库。 -L命令行参数告诉链接器在哪里查找它,但是您没有指定实际的库。

在运行时也使用LD_LIBRARY_PATH,但配置非标准目录的更好方法是使用/etc/ld.so.conf/etc/ld.so.conf.d/中的文件配置动态链接器。