未解析的符号: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 构建应用程序时,收到以下错误消息:
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)
这是由以下源行引起的:
sql::Driver * p_driver = sql::mysql::get_driver_instance();
The MySQL Connector 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 找不到 connect.cpp
使用的 get_driver_instance()
的声明或函数声明。我的程序中的语句与 connect.cpp
使用的语句完全相同,因为我将其复制过来,没有进行任何更改。
其他人已经通过使用另一个驱动程序解决了这个问题。但是,除非必要,否则我不想更改适用于 VS2008 的代码。
此问题的另一个回复说定义“mysqlcppconn_EXPORTS”,但这也不起作用,也在回复的评论中报告。
这是我的问题:
1. 有人拥有 MySQL Connector 1.1.0 来与 Visual Studio 2010 配合使用吗?
如果是,请回复并附上具体的示例并注明是dll还是静态库。
2. VS编译器如何选择返回MySQL_Driver *
的get_driver_instance()
函数而不是返回Driver *
的函数?
我什至没有收到任何有关不明确函数的警告或错误(因为重载必须不仅仅只是返回类型不同)。
我在 Windows 7x64 位、MySQL Connector C++ 1.1.0 上使用 Visual Studio 2010。
另请参阅:
get_driver_instance() 在 Qt 中崩溃
对“get_driver_instance”的未定义引用
MySQL C++ 连接器:对“get_driver_instance”的未定义引用
mysql-connector-c++ - 'get_driver_instance ' 不是 'sql::mysql' 的成员
如何修复由于 MySql Connector 导致的无法解析的外部符号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++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一些函数名称已更改。我的最佳解决方案是使用预处理器条件来区分它们。
Some function names have changed. My best solution is to differentiate between them by using preprocessor conditionals.
我也有同样的问题,我不断得到:
虽然我尝试了32位连接器并且问题得到了解决(你可能想尝试一下,如果你幸运的话它可能对你有用),但我使用的是64位mysql ,windows 7,所以存在一些兼容性问题..我仍在寻找上述问题的解决方案。
逐字逐句遵循教程,链接所有库
我认为 C++ 1.10 连接器可能有一些问题。
I too have the same problem, I keep getting:
Although I tried a 32 bit connector and the issue was resolved (you may want to try that as, if you are lucky it may work for you), but I was using a 64bit mysql,windows 7 , so there was a bit of compatibility issue .. I am still searching for the solution for the above problem.
Followed the tutorials word by word , linked all libraries
I think the C++ 1.10 connector might have some issue.