开发者

Problem with MySQL driver for unixODBC on Debian Lenny

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜