I'm trying to use the mysqlcppconn.lib in my c++ project. However, when I put use functionality from the library I get an error:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _mysql_init#4 referenced in function "public: void __thiscall Achievement::set(void)" (?set#Achievement##QAEXXZ) zombie C:\Users\jorda\OneDrive - Limerick Institute Of Technology\College\Final Year Project\Achievement_Libary\Copy - Copy\zombie\Achievement.obj 1
The code I'm using:
MYSQL* conn;
MYSQL_ROW row;
MYSQL_RES* res;
conn = mysql_init(0);
The errors seems to come from the mysql_init(0);
I've tried both the 32 and 64-bit version of the library but both give the same error. I'm not sure if I need to put some dlls inside the executable directory. I've tried putting libssl-1_1.dll & libcrypto-1_1.dll from both the 32 bit and 64-bit files as that's what one tutorial did however this did not work.
Would anyone know the process of trying to use the C++ connector in a visual studio project? Any help is appreciated. Here are the lib and input paths from the Linker
Would anyone know the process of trying to use the C++ connector in a visual studio project?
I suggest you could try the following steps:
1,Add the path to the header file to the Additional Include Directories(property - >c/c++ -> General -> Additional Include Directories)
2,Add the path to the .lib file to the Additional Library Directories (property -> linker -> General -> Additional Library Directories)
3,Add the name of the .lib file with its extension to Additional Dependencies (property -> linker -> input -> Additional Dependencies)
I suggest you could try to check if the file is in the location that you specified, or if you have provided the correct library path. And you couldn't mix 32 bit and 64 bit. Please make sure you're linking in 64-bit libraries with the 64-bit application, or change your app to 32-bit and link with the 32-bit libraries.
Related
Trying to use .lib in Visual c++ CLR project.
This .lib is built in c++ builder 5, i have .lib file and .hpp file.
created visual c++ -> CLR -> class library project.
In properties following fields are added,
C/C++ -> General ->
Additional include directories = C:\Users\D2\source\repos\CLR\CLR\LIB
Linker -> Additional include directories = C:\Users\D2\source\repos\CLR\CLR\LIB
Input -> Additional Dependencies = lib0.lib
C:\Users\D2\source\repos\CLR\CLR\LIB, This location contains .hpp, .lib, .dll files.
And Builded,
Linker error is coming, LNK1136 invalid or corrupt file
As this error says, I checked no other application is using this library and specified the correct library name and path. I'm confused with this corrupt file word because the same library is working with c++ builder 5.
please give suggestions.
I'm working in a Cocos2dx (c++) win 32 project and trying to use sqlite to save the game data. My knowledge of c++ / Visual Studio is very limited right now.
This is part of the code that I'm trying to compile.
#include <sqlite3\include\sqlite3.h>
...
void HelloWorld::SaveAndLoadTest()
{
sqlite3 *pdb = NULL;
sqlite3_open("writablePath", &pdb);
...
}
But when I try to compile the line with the sqlite3_open command I get the following error:
Error 7 error LNK2019: unresolved external symbol _sqlite3_open referenced in function...
I've been trying to find an answer for this many hours. The most similar question I found was this one but I don't understand the answer.
Error: undefined reference to `sqlite3_open'
You need to link the sqlite3 library along with your program:
g++ main.cpp -lsqlite3
I'm new to Visual Studio and I don't understand how to solve this, anyone?
The error LNK2019 means that references are missing probably because a library is mising.
To add sqlite to a MSVC project, you have to make sure that:
the header is included in your source files
sqlite3.dll is in the path or in the directory of the executable
AND that sqlite3.lib is added to the additional dependencies in the VS project (options of the project > Linker > Input > Additional dependencies)
This last point is mandatory, because the lib tells the linker which functions are stored in the dll.
The solution, quite simply, is to link sqlite3 to your project. Libraries need to be linked (via the linker) for you to be able to use them. Head over here and download the pre-compiled binaries for your platform of choice (in this case, Win32). You may also choose to compile sqlite3 from source. You should end up with a .lib file. Go to Project -> Configuration Properties -> Linker -> General -> Additional Include Directories and add the path to your library file to it. Then go to Linker -> Input -> Additional Dependencies and put in sqlite3.lib.
And remember that you must build sqlite3.lib from file SQLite3.def:
Download source from source (https://www.sqlite.org/download.html)
For example: source https://www.sqlite.org/2022/sqlite-amalgamation-3390300.zip
Or download binary from binary
For example: binary https://www.sqlite.org/2022/sqlite-dll-win64-x64-3390300.zip
Extract both archives to the same directory
Open Developer Command Prompt for VS 2017 by typing Developer Command in Windows Search
Go to directory where you've extracted source code and binary files (via opened cmd)
Run lib /DEF:sqlite3.def /OUT:sqlite3.lib /MACHINE:x64
(Remember if win32, replace "MACHINE:x64" by MACHINE:x86)
I am trying to add ANN(open source k-d tree for fast nearest neighbor searching) to my VC++ project. I followed the manual and completed every step:
include the .h files
copy the .lib file, add its location to the linker additional directory
copy the .dll file, set location to environmental variable PATH, and import it in my project
I still get 24 "unresolved external..." errors. The library seems to be widely used and not supposed to be wrong, wondering what else do I need to do to use it?
Thanks guys!
The "unresolved external" error comes because the linker is not finding the "lib" files. The DLL files are only found during run time, not link time.
Do you set the names of the lib files in the project's Properties?
Configuration Properties -> Linker -> Input -> Additional Dependencies
Enter the filenames of the all the lib files, separated by spaces. If they are in your Project folder, use something like
$(ProjectDir)Foobar.lib
have you set path of lib correctly?
you can use lib file along with its path in
on Configuration Properties -> Linker -> Input -> Additional Dependencies
or
just give lib file name in
Configuration Properties -> Linker -> Input -> Additional Dependencies
and lib path in
Configuration Properties -> Linker -> General -> Additional library directories
So currently I'm trying to use the VISA library from National Intruments and the IVI Foundation to read/write commands to various external devices.
I am relatively novice with my IDE: Microsoft Visual C++ Express 2010 and this is my first time trying to use a third party library that requires more than a .h import.
Basically I have a directory with 3 header files, a directory with 3 .lib libraries and a directory with 7 DLLs. They have no documentation as to what any of the individual files do, only the library as a whole. So, I need to be able to get all of these files associated with my project.
Currently I have all the headers imported in my header file and the header directory added to the include directories in the project properties. I also have the directory containing the .lib files added to the library directories in the project properties. I assumed that .lib files would link to the DLLs, but apparently that is not the case because I'm getting the error:
VISA Console 2.obj : error LNK2019: unresolved external symbol _viOpenDefaultRM#4 referenced in function _wmain
This error occurs when using any function from the library. Here is my code currently:
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
ViStatus status;
ViSession defaultRM, instr;
status = viOpenDefaultRM(&defaultRM);
return 0;
}
The project will build when I comment out the viOpenDefaultRM command, so I assume that means I can use the objects from the library and not the commands. Since I have the 3 object declarations that build just fine.
Okay this is all my information, hopefully someone can help and hope this helps someone else!
In addition to having the directory for the .lib file(s) added to the library directories property, you need to also add the actual libraries that the linker should search.
Add the libraries to the project's
Configuration Properties | Linker | Input | Additional Dependencies
field.
The DLLs are not necessary for the build process, but to run the program they should be in a directory inthe PATH or in the same directory as the program file.
Have you added to the project properties the additional dependecies?
Under "Linker->Input" find "Additional Dependecies" and place there the libs that you got from
I'm trying to use ImageMagick Magick++ for a C++ Project in VS2010.
I installed the Library from here: klick
Then in my Project, I added c:/program files/ImageMagick-6.6.6-Q16/include to the include folders. Then I tried to use Magick++ with this code:
#include <Magick++.h>
void main(int argc, char ** argv){
InitializeMagick(*argv);
}
But this does not work!
VS2010 returns the following errors:
error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl Magick::InitializeMagick(char const *)" (__imp_?InitializeMagick#Magick##YAXPBD#Z)
error LNK1120: 1 unresolved externals
What am I doing wrong?
Thanks very much for your help!
UPDATE:
Set Linker -> Input -> Additionnal Dependencies to:
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;CORE_RL_Magick++_.lib
And Linker -> General -> Additionnal Library Directories to:
C:\Program Files\ImageMagick-6.6.6-Q16\lib
It still results in the same error...
UPDATE 2
Opening the .lib files in C:\Program Files\ImageMagick-6.6.6-Q16\lib results in this error:
UPDATE 3
CORE_RL_Magick++_.lib does contain ?InitializeMagick#Magick##YAXPEBD#Z, but not ?InitializeMagick#Magick##YAXPBD#Z. Does this mean the .lib file is corrupted?
UPDATE 4
I solved my problem by manually compliling the .lib files.
Thanks to all!
CORE_RL_Magick++_.lib does contain ?InitializeMagick#Magick##YAXPEBD#Z, but not ?InitializeMagick#Magick##YAXPBD#Z
Using the undname.exe utility, these names undecorate to:
void __cdecl Magick::InitializeMagick(char const *)
void __cdecl Magick::InitializeMagick(char const * __ptr64)
Note the __ptr64 declarator you got on the argument. You've got some kind of compile setting that turns that char* into a 64-bit pointer. Like compiling this code targeting a 64-bit operating system. But linking the 32-bit .lib. This normally generates a linker error about the bit-ness of the .lib being wrong, not so sure why you don't see this. Maybe a mingw artifact, not sure how it works.
You should also indicate to Visual Studio the .lib to be used for linking
in Linker -> Input -> Additionnal Dependencies
EDIT: and put the path of the magick library
in Linker -> General -> Additionnal Library Directories
EDIT2: if it still doesnt work, then you are calling a fonction with a wrong exported signature.
Launch the msdev tool Dependency Walker. And check if the magick.lib really exports the function whose name is ?InitializeMagick#Magick##YAXPBD#Z
I am wrong it's not a microsoft tool: Dependency Walker
I was wrong Dependency Walker doesnt open .lib, only Dlls and Exes.
However since you have found ?InitializeMagick#Magick##YAXPBD#Z in the content of the .lib file, it means that it is reaaly exported this way.
EDIT3: Are you SURE the name and the folder of the additionnal library is correct. I really cannot think of another reason for Visual C++ being unable to link with your library. If your .lib DO contains the string ?InitializeMagick#Magick##YAXPBD#Z I really think it should link.
EDIT4: could you paste from the file <Magick++.h> the prototype definition of InitializeMagick ?
there is something that makes it be compiled differently between visual c++ and your library supplier. ?InitializeMagick#Magick##YAXPEBD#Z and ?InitializeMagick#Magick##YAXPEBD#Z are two DIFFERENT signatures. When including <Magick++.h> Visual C++ understands its differently. (that's why I need to see the prototype of the function)
You should also indicate to Visual Studio the .lib to be used for linking
in Linker -> Input -> Additionnal Dependencies
Thank you!
The additional dependecies line contains now the following text (look at the end):
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;C:\Program Files\ImageMagick-6.6.6-Q16\lib\CORE_RL_Magick++_.lib
It still does not work. Is it the wrong .lib file?
what is this .lib file for?
Shouldn't source code just work? There isn't any DLL...
The documentation says: "Windows users may get started by manually editing a project file for one of the Magick++ demo programs." Did you try that?