0

I am attempting to connect to a MySQL database using ODBC driver using nanodbc library a C++ wrapper for ODBC but I am getting error LNK2019: unresolved external symbol

I have added the path to installed library directory in additional library directory where nanodbc.lib is located. I even copied nanodbc.lib in my source directory but still no luck.

I had added nanodbc.lib to Properties->Linker->Input->Additional Directories in case #pragma comment(lib, "nanodbc.lib") was not working but its still not working.

The worst part is the same code works in an existing project (having different connection string).

Tooling : Microsoft Visual Studio Community 2017 Version 15.9.11

Package Manager : vcpkg

OS : Windows 10 Professional 64-bit

Language Standard : C++17

Code :

#include <iostream> #include <nanodbc/nanodbc.h> #pragma comment(lib, "nanodbc.lib") int main() { nanodbc::string dns = "PLC_Interface"; nanodbc::string user_name = "root"; nanodbc::string password = "rooot"; nanodbc::connection conn(dns, user_name, password); std::cout << conn.connected() << std::endl; //std::cout << "Database Name : " <<conn.database_name() << std::endl; //std::cout << "DBMS Name : " <<conn.dbms_name() << std::endl; //std::cout << "DBMS Version : " <<conn.dbms_version() << std::endl; conn.disconnect(); std::cout << conn.connected() << std::endl; } 

Error :

error LNK2019: unresolved external symbol "public: __cdecl nanodbc::connection::connection(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,long)" (??0connection@nanodbc@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00J@Z) referenced in function main 
10
  • Have you tried passing nanodbc.lib to the linker directly instead of using the pragma? I didn't even know you could do that with a pragma! Commented Apr 20, 2019 at 8:13
  • There should be two steps. First, pass the directory that contains nanodbc.lib to the linker. Second, pass the file name nanodbc.lib to the linker. I have no experience with VS but it sounds like you're only doing the first step. Commented Apr 20, 2019 at 8:22
  • Yes, as mentioned in my post I passed nanodbc.lib in Properties->Linker->Input->Additional Directories. I have also added the path to directory as mentioned. Commented Apr 20, 2019 at 8:23
  • You put a file in the Additional Directories field? Commented Apr 20, 2019 at 8:24
  • I added the path of directory where nanoodbc.lib was located. Commented Apr 20, 2019 at 8:25

1 Answer 1

0

Solved the problem. The issue was with library created by vcpkg package manager. When I built the library myself manually, the issue got resolved. No code change was necessary (even working with #pragma).


Wanting to know is their any way to compare the libraries to find out why the issue was caused in the first place?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.