error LNK2019: unresolved external symbol _sqlite3_key referenced in function _main - c++

I am working on one c++ project where I want to use Sqlite database but in my code I am getting error.
as error LNK2019: unresolved external symbol _sqlite3_key referenced in function _main
I my code is:
sqlite3 *db;
int rc;
rc = sqlite3_open("sql.db", &db);
const char ch[] = "1234";
rc = sqlite3_key(db,ch,strlen(ch));
if (sqlite3_exec(db, "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL) == SQLITE_OK) {
printf("Success");
// key is correct.
} else {
// key is incorrect
printf("Error in Database Execution");
}
I am using VS2010.
I did all the required settings of lib and dll.
But it does not help me so far.
Can any one help me out on this?

Looks like you are using an encryption library like SQLCipher or SQLiteEncrypt, which means you have to to add the corresponding library, for example SQLiteEncrypt.lib to the lib settings. You probably can also add use a #pragma instead.
#pragma comment(lib, "SQLiteEncrypt.lib")

Related

LNK2019 error when building MySQL codei n VIsual Studio C++

I've spent about two days now trying to get this to work but I still keep getting the same error with every method I do. I'm new to connecting MySQL to C++ so I'm a bit lost and every time I try to compile it, the thing spits out LNK2019 error. I'm using Visual Studio 2022.
#include <iostream>
#include <mysql.h>
using namespace std;
// DATABASE STUFF
struct connection_details {
const char* server, * user, * password, * database;
};
MYSQL* mysql_connection_setup(struct connection_details mysql_details) {
MYSQL* connection = mysql_init(NULL);
if (!(mysql_real_connect(connection, mysql_details.server, mysql_details.user, mysql_details.password, mysql_details.database, 0, NULL, 0))) {
cout << "Connection Error: " << mysql_error(connection) << endl;
exit(1);
}
return connection;
}
MYSQL_RES* mysql_execute_query(MYSQL* connection, const char* sql_query) {
if (mysql_query(connection, sql_query)) {
cout << "MYSQL Query Error: " << mysql_error(connection) << endl;
exit(1);
}
return mysql_use_result(connection);
}
// MAIN FUNCTION
int main(int argc, char const* argv[]) {
MYSQL* con;
MYSQL_RES* res;
MYSQL_ROW row;
struct connection_details mysql_db;
mysql_db.server = "localhost";
mysql_db.user = "root";
mysql_db.password = "tAblE4wTe3";
mysql_db.database = "test";
con = mysql_connection_setup(mysql_db);
res = mysql_execute_query(con, "select * from table1");
cout << "Displaying Database:\n" << endl;
while ((row = mysql_fetch_row(res)) != NULL) {
cout << row[0] << " | " << row[1] << " | " << row[2] << endl;
}
mysql_free_result(res);
mysql_close(con);
return 0;
}
Errors it shows:
1>------ Build started: Project: Test, Configuration: Debug x64 ------
1>main.obj : error LNK2019: unresolved external symbol mysql_error referenced in function "struct MYSQL * __cdecl mysql_connection_setup(struct connection_details)" (?mysql_connection_setup##YAPEAUMYSQL##Uconnection_details###Z)
1>main.obj : error LNK2019: unresolved external symbol mysql_init referenced in function "struct MYSQL * __cdecl mysql_connection_setup(struct connection_details)" (?mysql_connection_setup##YAPEAUMYSQL##Uconnection_details###Z)
1>main.obj : error LNK2019: unresolved external symbol mysql_real_connect referenced in function "struct MYSQL * __cdecl mysql_connection_setup(struct connection_details)" (?mysql_connection_setup##YAPEAUMYSQL##Uconnection_details###Z)
1>main.obj : error LNK2019: unresolved external symbol mysql_query referenced in function "struct MYSQL_RES * __cdecl mysql_execute_query(struct MYSQL *,char const *)" (?mysql_execute_query##YAPEAUMYSQL_RES##PEAUMYSQL##PEBD#Z)
1>main.obj : error LNK2019: unresolved external symbol mysql_use_result referenced in function "struct MYSQL_RES * __cdecl mysql_execute_query(struct MYSQL *,char const *)" (?mysql_execute_query##YAPEAUMYSQL_RES##PEAUMYSQL##PEBD#Z)
1>main.obj : error LNK2019: unresolved external symbol mysql_free_result referenced in function main
1>main.obj : error LNK2019: unresolved external symbol mysql_fetch_row referenced in function main
1>main.obj : error LNK2019: unresolved external symbol mysql_close referenced in function main
1>C:\Users\Administrator\Documents\Visual Studio 2022\C++ Projects\Test\x64\Debug\Test.exe : fatal error LNK1120: 8 unresolved externals
1>Done building project "Test.vcxproj" -- FAILED.
These are the include/library folder locations:
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\libbinlogevents
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\libbinlogstandalone
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\libchangestreams
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\libmysql
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\libservices
C:\Program Files\MySQL\Connector C++ 8.0\lib64\vs14
C:\Users\Administrator\Documents\Visual Studio 2022\mysql stuff\include
C:\Program Files\MySQL\Connector C++ 8.0\include
I've tried looking it up, and every forum, video, etc. that I try using to resolve doesn't work. I'm not sure if it's a 32-bit or 64-bit issue, though I don't think it is since all files point to 64-bit folders. I'm thinking it's something in my code but I'm very new to this so I can't really pinpoint it. Any help would be appreciated.
EDIT: I managed to solve it, just started the project from scratch and followed the visual studio docs and this video.

Why do I keep getting an Unresolved External Symbol error when using the CredUIPromptForCredentials function from wincred.h [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 3 years ago.
I keep getting these two errors in Visual Studio C++:
"Error LNK2019 unresolved external symbol __imp__CredUIPromptForCredentialsW#40 referenced in function _main ConsoleApplication1"
"Error LNK1120 1 unresolved externals ConsoleApplication1"
I am trying to get the part that opens up the enter credentials dialog of this example code to run: https://learn.microsoft.com/en-us/windows/desktop/taskschd/weekly-trigger-example--c---
I am new to C++ but I am pretty sure that all of the datatypes that I am passing in to the CredUIPromptForCredentials function are correct. I have already tried reading the links from the error but they are not helping me.
int main() {
CREDUI_INFO cui;
TCHAR credLoc[CREDUI_MAX_USERNAME_LENGTH] = _T("");
TCHAR pszName[CREDUI_MAX_USERNAME_LENGTH] = _T("");
TCHAR pszPwd[CREDUI_MAX_PASSWORD_LENGTH] = _T("");
BOOL fSave;
//DWORD dwErr;
cui.cbSize = sizeof(CREDUI_INFO);
cui.hwndParent = NULL;
// Ensure that MessageText and CaptionText identify
// what credentials to use and which application requires them.
cui.pszMessageText = TEXT("Account information for task registration:");
cui.pszCaptionText = TEXT("Enter Account Information for Task Registration");
cui.hbmBanner = NULL;
fSave = FALSE;
// Create the UI asking for the credentials.
CredUIPromptForCredentialsW(
&cui, // CREDUI_INFO structure
credLoc, // Target for credentials
NULL, // Reserved
0, // Reason
pszName, // User name
CREDUI_MAX_USERNAME_LENGTH, // Max number for user name
pszPwd, // Password
CREDUI_MAX_PASSWORD_LENGTH, // Max number for password
&fSave, // State of save check box
CREDUI_FLAGS_DO_NOT_PERSIST);
return 0;
}
I am expecting to see a dialog box that prompts for a username and password but I only get the errors listed above and the program fails to build.
Your project needs to link to Credui.lib, as stated in the CredUIPromptForCredentialsW() documentation. Either add the .lib file to your project, or else use a #pragma comment(lib, "Credui.lib") statement in your code.

WICConvertBitmapSource() gives link error

I was trying to encode an image using WIC.
and i made simple dll (to encode/decode) and reffered it from another aplication.
I added my_bitmap_converter() to do a convertion intended to use WICConvertBitmapSource() but it gives me a link error. here is my work
int my_bitmap_converter
(
REFWICPixelFormatGUID dstPixelFormt,
IWICBitmapSource* piBitmapSource,
IWICBitmapSource** ppiBitmapDst
)
{
IWICBitmapSource* piScr = piBitmapSource;
IWICBitmapSource** ppiDst = ppiBitmapDst;
hr = WICConvertBitmapSource
(
dstPixelFormt,//GUID_WICPixelFormat128bppPRGBAFloat,
piScr,
ppiDst
);
if (SUCCEEDED(hr))
{
piScr->Release();
return 0;
}
return -1;
}
how can i get rid of this error
Error 1 error LNK2019: unresolved external symbol
_WICConvertBitmapSource#12 referenced in function "int __cdecl my_bitmap_converter(struct _GUID const &,struct IWICBitmapSource
*,struct IWICBitmapSource * *)" (?my_bitmap_converter##YAHABU_GUID##PAUIWICBitmapSource##PAPAU2##Z)
---wincodec.h---
HRESULT WINAPI WICConvertBitmapSource(
_In_ REFWICPixelFormatGUID dstFormat, // Destination pixel format
_In_reads_(1) IWICBitmapSource *pISrc, // Source bitmap
_Outptr_result_buffer_(1) IWICBitmapSource **ppIDst // Destination bitmap, a copy or addrefed source
);
if you referred here, you may realize that "Link library name is "windowscodecs.lib" instead of "wincodec.lib" in Windows SDK 7.0 "
maybe you are using SDK 7.0 or later. if it is, try adding windowscodecs.lib as an additional dependencies.

C++ Connector to MySQL

EDITED:
My Problem is the errors at the bottom of this post.
Heres my additional include directories
C:\Program Files\boost
C:\Program Files\MySQL\MySQL Connector C++ 1.1.3\include
C:\Program Files\MySQL\MySQL Server 5.6\include
Additional Library Directories
C:\Program Files\MySQL\MySQL Server 5.6\lib
C:\Program Files\MySQL\Connector C++ 1.1.2\lib\opt
Additional Dependencies
libmysql.lib
mysqlcppconn-static.lib
Heres my code
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
#include <stdlib.h>
#include <Windows.h>
#include <mysql.h>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#define host "localhost"
#define username "root"
#define password "root"
#define database "tests"
int main()
{
MYSQL* conn;
conn = mysql_init( NULL );
if( conn )
{
mysql_real_connect( conn, host, username, password, database, 0, NULL, 0 );
}
MYSQL_RES* res_set;
MYSQL_ROW row;
unsigned int i;
mysql_query( conn, "SELECT * FROM tbl_clients WHERE id = 1" );
res_set = mysql_store_result( conn );
unsigned int numrows = mysql_num_rows( res_set );
if( numrows )
{
row = mysql_fetch_row( res_set );
if( row != NULL )
{
cout << "Client ID : " << row[0] << endl;
cout << "Client Name: " << row[1] << endl;
}
}
if( res_set )
{
mysql_free_result( res_set );
}
if( conn )
{
mysql_close( conn );
}
return 0;
}
These are the errors I get
1>------ Build started: Project: okay, Configuration: Debug Win32 ------
1>welp.obj : error LNK2019: unresolved external symbol _mysql_num_rows#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_init#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_real_connect#32 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_query#8 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_store_result#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_free_result#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_fetch_row#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_close#4 referenced in function _main
1>C:\Users\Damian\documents\visual studio 2012\Projects\okay\Debug\okay.exe : fatal error LNK1120: 8 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Please help, This project is due in about 48 hours for my class, and I've spent so much time trying to figure this out.
Thanks
respectfully, your last two questions are compiler/linker questions. I understand your frustration, as I knew how to code early but knew nothing about compilers/linkers. When you get a moment take some time to read about:
headers
binary vs object file
libraries / shared object
compiler
linker
function mangling (C vs C++)
To answer your question, I am guessing you're doing this in Microsoft Visual Studio:
You need to go to Project Properties and set Additional Library Paths (i see you did that from your last post)
You need to specify the library, I'm going out on a limb here and assuming it will mysql.lib ... There's an "Additional Library" input somewhere in the Linker section, you'll be able to identify it because kernel32.lib will be int it. Add the mysql.lib to that section. Confirm the name by going to the mysql folder which holds the binaries.
Make sure you're using the static library, the .dll will give you new issues that you don't need to worry about. This is usually achieved by setting the correct library directory. Many c++ libraries will ship with precompiled "Static" and "Dynamic" folders containing the correct libraries.
This is error is happening due to linker problem. The linker is not able to find the required static or dynamic libraries (mysql.lib,mysqlcppconn-static.lib,libmysql.dll and libmysql.lib). The additional lib setting is wrong. Check this site give the path correctly Building MySQL Connector/C++ Windows Applications with Microsoft Visual Studio

Linker error "... .obj : error LNK2019: unresolved external symbol referenced in function"

I have read all the previous replies or solutions for the same linker problem. I understand that the Linker is unable to access the library file that has the functions defined but still I have no luck in solving it!
The errors:
1>trial_12th.obj : error LNK2019: unresolved external symbol _viStatusDesc#12 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viClose#4 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viRead#16 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viWrite#16 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viOpen#20 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viOpenDefaultRM#4 referenced in function _main
1>C:\Users\41kchoudhary\Documents\Visual Studio 2010\Projects\trial_12th\Debug\trial_12th.exe : fatal error LNK1120: 6 unresolved externals
I am trying to send and receive data from a mixed-signal oscilloscope. In doing so I am required to write a .cpp file using the pre-defined commands/functions defined using Microsoft Visual Studio C++. I have read the user manual for using these commands, and I also have the header files and libraries required to implement it.
I am using the following code:
#include <visa.h>
#include "stdafx.h"
#include <stdio.h>
#include <memory.h>
int main(int argc, char* argv[])
{
ViSession rm = VI_NULL, vi = VI_NULL;
ViStatus status;
ViChar buffer[256];
ViUInt32 retCnt;
// Open a default session
status = viOpenDefaultRM(&rm);
if (status < VI_SUCCESS) goto error;
// Open the GPIB device at primary address 1, GPIB board 8
status = viOpen(rm, "USB::0x0699::0x0377::C011104::INSTR", VI_NULL, VI_NULL,
&vi);
if (status < VI_SUCCESS) goto error;
// Send an ID query.
status = viWrite(vi, (ViBuf) "*idn?", 5, &retCnt);
if (status < VI_SUCCESS) goto error;
// Clear the buffer and read the response
memset(buffer, 0, sizeof(buffer));
status = viRead(vi, (ViBuf) buffer, sizeof(buffer), &retCnt);
if (status < VI_SUCCESS) goto error;
// Print the response
printf("id: %s\n", buffer);
// Clean up
viClose(vi); // Not needed, but makes things a bit more
// understandable
viClose(rm); // Closes resource manager and any sessions
// opened with it
return 0;
error:
// Report error and clean up
viStatusDesc(vi, status, buffer);
fprintf(stderr, "failure: %s\n", buffer);
if (rm != VI_NULL) {
viClose(rm);
}
return 1;
}
You need to add either visa32.lib or visa64.lib to your linker settings.
One way to do that is to use a pragma in your compiler source file:
#pragma comment(lib,"visa32.lib")
If it is still not found then adjust your lib paths in your IDE or include the full path in the pragma.
I had the same issue. I figured out that you have to add visa32.lib in additional dependencies under the linker properties of your project
Go to your
project properties -> Linker -> Additional Dependencies-> Click Down Arrow -> "Edit -> Type visa32.lib
Click Ok, Ok