未解析的符号:sql :: mysql :: get_driver_instance(void) [英] Unresolved symbol: sql::mysql::get_driver_instance(void)

查看:1669
本文介绍了未解析的符号:sql :: mysql :: get_driver_instance(void)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序使用MySQL连接器与MySQL数据库交谈。使用Visual Studio 2008应用程序运行良好。我试图让应用程序使用Visual Studio 2010构建,这是问题开始的地方。



VS 2010不支持MySQL Connector 1.05,它们没有与VS 2010配合使用的1.1.0的二进制版本。MySQL信息说下载Connector C ++ 1.10的源代码并使用VS 2010构建。经过大量工作,我构建它。示例运行。



但是,当我用新建的Connector C ++ 1.1.0构建我的应用程序时,我得到以下错误信息:

 错误LNK2019:未解析的外部符号class sql :: mysql :: MySQL_Driver * __cdecl sql :: mysql :: get_driver_instance(void)(?get_driver_instance @ mysql @ sql @@在函数private:void __thiscall Database_NS :: Manager :: initialize_db_driver(void)const(?initialize_db_driver @ Manager @ Database_NS @@ ABEXXZ)中引用的$ YAPAVMySQL_Driver @ 12 @ XZ)
pre>

这是由以下源代码行引起的:

  sql :: Driver * p_driver = sql :: mysql :: get_driver_instance(); 

MySQL连接器C ++ 1.1.0示例使用上述行,他们没有错误。
我试图链接到mysqlconn-static.lib,mysqlconn.lib,mysqlclient.lib,libmysql.lib和仍然错误消息仍然存在。



有趣的是,根据VS 2010,上面的源代码行使用了这个声明:

  CPPCONN_PUBLIC_FUNC MySQL_Driver * get_driver_instance 

注意不同的返回值。



当我使用Visual Studio 2010和连接器项目示例,VS 2010无法找到 get_driver_instance()连接使用的声明或函数声明。 cpp 。我的程序中的语句是 connect.cpp 使用的确切语句,因为我复制它而没有任何更改。



其他人已通过使用其他驱动程序解决了此问题。但是,我不想改变我的代码与VS2008,除非我必须。



另一个回复这个问题说,定义mysqlcppconn_EXPORTS,但这没有工作,也报告在回复的评论。



以下是我的问题:

1.任何人都有MySQL Connector 1.1.0与Visual Studio 2010配合使用?

如果是这样,请按照步骤示例回答,并指出是否为dll或静态库

2. VS编译器如何选择函数返回 MySQL_Driver * 而不是返回驱动程序* get_driver_instance code>?

我甚至不会得到任何关于歧义函数的警告或错误(因为重载的不同,不仅仅是返回类型)。



我使用Visual Studio 2010在Windows-7x64位,MySQL连接器C + + 1.1.0。



另请参阅:

get_driver_instance()与Qt崩溃

未定义对get_driver_instance的引用

MySQL C ++连接器:未定义引用`get_driver_instance'

mysql-connector-c ++ - 'get_driver_instance'不是'sql :: mysql'的成员 < br>
如何解决未解决的问题外部符号由于MySql连接器C ++?

解决方案

一些函数名称已更改。我的最佳解决方案是通过使用预处理器条件来区分它们。


I have a program that uses MySQL connector to talk to a MySQL database. The application runs fine using Visual Studio 2008. I'm trying to get the application to build with Visual Studio 2010 and that's where the problems began.

The MySQL Connector 1.05 is not supported with VS 2010, and they don't have a binary version of 1.1.0 that works with VS 2010. The MySQL information says to download the source for Connector C++ 1.10 and build with VS 2010. After much work, I build it. The examples run.

However, when I build my application with the newly built Connector C++ 1.1.0, I get the following error message:

error LNK2019: unresolved external symbol "class sql::mysql::MySQL_Driver * __cdecl sql::mysql::get_driver_instance(void)" (?get_driver_instance@mysql@sql@@YAPAVMySQL_Driver@12@XZ) referenced in function "private: void __thiscall Database_NS::Manager::initialize_db_driver(void)const " (?initialize_db_driver@Manager@Database_NS@@ABEXXZ)

This is caused by the following source line:

sql::Driver * p_driver = sql::mysql::get_driver_instance();

The MySQL Connector C++ 1.1.0 examples use the above line and they get no errors. I've tried linking with mysqlconn-static.lib, mysqlconn.lib, mysqlclient.lib, libmysql.lib and still the error message persists.

An interesting point is that according to VS 2010, the above source line uses this declaration:

CPPCONN_PUBLIC_FUNC MySQL_Driver * get_driver_instance();

Note the different return values.

When I use Visual Studio 2010 and the connector project example, VS 2010 can't find the declaration or function declaration of get_driver_instance() used by connect.cpp. The statement in my program is the exact statement used by connect.cpp, since I copied it over without any changes.

Other people have resolved this issue by using another driver. However, I don't want to change my code that works with VS2008 unless I have to.

Another reply to this issue says to define "mysqlcppconn_EXPORTS", but this didn't work either, also reported in the comment to the reply.

Here are my questions:
1. Has anybody got MySQL Connector 1.1.0 to work with Visual Studio 2010?
If so, please reply with step by step example and indicate whether dll or static library.
2. How is the VS compiler selecting the get_driver_instance() function that returns MySQL_Driver * rather than the function that returns the Driver *?
I'm not even getting any warnings or errors about ambiguous functions (since overloading must differ by more than only return type).

I am using Visual Studio 2010 on Windows-7x64-bit, MySQL Connector C++ 1.1.0.

See also:
get_driver_instance() crashes with Qt
undefined reference to 'get_driver_instance'
MySQL C++ Connector: undefined reference to `get_driver_instance'
mysql-connector-c++ - ‘get_driver_instance’ is not a member of ‘sql::mysql’
How to fix unresolved external symbol due to MySql Connector C++?

解决方案

Some function names have changed. My best solution is to differentiate between them by using preprocessor conditionals.

这篇关于未解析的符号:sql :: mysql :: get_driver_instance(void)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆