如何使用 C++ 查询 Informix 数据库在 Linux 上?使用 C++ 对象接口时出现编译器错误

发布于 2024-11-26 21:23:31 字数 3615 浏览 2 评论 0原文

我使用 IBM 提供的 C++ 对象接口编写了以下代码。我正在尝试在 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。谁能帮助我摆脱这些错误?

I have written below code using C++ Object Interface provided by IBM. I am trying to compile that on 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();
}

While compiling on Linux like this:

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

I am getting the errors shown below:

/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

The directory /opt/Informix/11.5FC8/lib/c++ is listed in LD_LIBRARY_PATH. Can anyone help me to get rid of these errors?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深居我梦 2024-12-03 21:23:31

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

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

You are not actually linking with the library using the -l command line parameter. The -L command line parameter tells the linker where to look to find it, but you don't specify the actual library.

Also LD_LIBRARY_PATH is used during runtime, but a better way to configure a non-standard directory is to configure the dynamic linker using /etc/ld.so.conf or a file in /etc/ld.so.conf.d/.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文