Debian Lenny 上的 unixODBC MySQL 驱动程序出现问题

发布于 2024-09-11 06:05:12 字数 1359 浏览 0 评论 0原文

在 OpenSuse 11.2 上,我成功编译、链接并运行了以下代码,该代码使用 unixODBC 为 MySQL 数据库安装了数据源:

#include <iostream>
#include <sql.h>
#include <sqlext.h>
#include <odbcinst.h>

/* Add a data source for the following MySQL db: db=testdb, username=test, password = test. */
void inst()
{
   BOOL ret = SQLConfigDataSource(NULL, ODBC_ADD_DSN, "MySQL driver",
                                  "DSN=mysource\0UID=test\0PWD=test\0DATABASE=testdb\0\0");
   if (!ret) {
      DWORD errCode;
      char errBuf[SQL_MAX_MESSAGE_LENGTH];
      WORD msgLen;
      SQLInstallerError(1, &errCode, errBuf, SQL_MAX_MESSAGE_LENGTH, &msgLen);
      std::cerr << errBuf << std::endl;
   }
}

int main()
{
     inst();
     return 0;
}

在 Debian Lenny 上使用相同的代码时,我遇到了问题。首先,我按照以下方式编译了这段代码:

c++ -o main main.cc  -lodbc -lodbcinst -L/usr/lib/odbc -lmyodbc

一切顺利。但是当我尝试运行生成的二进制文件时,我收到了一个链接器错误,实际上通过输入 ldd main 确认了该错误:

libmyodbc3_r-3.51.15.so => not found

尽管我以最简单的方式(即通过 aptitude),我找不到这个共享库。

我错误地认为,好吧,我将在 /usr/lib/odbc/libmyodbc.so 上创建一个符号链接。无论如何,现在我的程序返回以下消息:

General installer error

所以我觉得文件 libmyodbc3_r-3.51.15.so 确实丢失了。

注意:在Debian Lenny上,unixODBC的版本是2.2.11,MySQL的版本是5.0.51a

有人遇到过这样的情况吗?任何帮助将不胜感激。

On OpenSuse 11.2, I successfully compiled, linked, and ran the following code which installs a data source for a MySQL database with unixODBC:

#include <iostream>
#include <sql.h>
#include <sqlext.h>
#include <odbcinst.h>

/* Add a data source for the following MySQL db: db=testdb, username=test, password = test. */
void inst()
{
   BOOL ret = SQLConfigDataSource(NULL, ODBC_ADD_DSN, "MySQL driver",
                                  "DSN=mysource\0UID=test\0PWD=test\0DATABASE=testdb\0\0");
   if (!ret) {
      DWORD errCode;
      char errBuf[SQL_MAX_MESSAGE_LENGTH];
      WORD msgLen;
      SQLInstallerError(1, &errCode, errBuf, SQL_MAX_MESSAGE_LENGTH, &msgLen);
      std::cerr << errBuf << std::endl;
   }
}

int main()
{
     inst();
     return 0;
}

With the same code on Debian Lenny, I have had problems. First, I compiled this code the following way:

c++ -o main main.cc  -lodbc -lodbcinst -L/usr/lib/odbc -lmyodbc

It went ok. But when I attempted to run the resulting binary, I got a linker error which in fact was confirmed by typing ldd main:

libmyodbc3_r-3.51.15.so => not found

Although I correctly installed unixODBC and the associated MySQL driver (myodbc) on my host (Debian Lenny) the simplest way (i.e. via aptitude), I could not find this shared library.

I wrongly thought, well, I will create a symlink on /usr/lib/odbc/libmyodbc.so. Anyway now my program returns the following message:

General installer error

So I feel the file libmyodbc3_r-3.51.15.so is really missing.

Note: on Debian Lenny, the version of unixODBC is 2.2.11, and the version of MySQL is 5.0.51a

Anyone ever ran into such a situation ? Any help would be appreciated.

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

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

发布评论

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

评论(1

凹づ凸ル 2024-09-18 06:05:12

该选项

-L/usr/lib/odbc

告诉编译器在哪里可以找到用于链接的库。

但是当您运行可执行文件时,系统不知道在哪里可以找到该库。

您需要静态链接 libmyodbc,或者告诉系统在哪里可以找到该库。

第一个可以通过更改

-lmyodbc

为来

-static -lmyodbc

完成第二个可以通过编辑 /etc/ld.so.conf(或添加到 /etc/ld.so.conf.d)并重新运行 ldconfig 或设置 LD_LIBRARY_PATH 环境变量来完成包含 /usr/lib/odbc

The option

-L/usr/lib/odbc

tells the compiler where to find the library for linking.

But the system doesn't know where to find the library when you run the executable.

You need to either statically link against libmyodbc, or tell the system where to find the library.

The first can be done by changing

-lmyodbc

to

-static -lmyodbc

The second can be done by editing /etc/ld.so.conf (or adding to /etc/ld.so.conf.d) and re-running ldconfig or by setting the LD_LIBRARY_PATH environment variable to include /usr/lib/odbc

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