Using a Third Party Library Consisting of ".h", ".lib" and ".dll" Files - c++

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

Related

How to link mysqlcppconn.lib to a c++ project

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.

Linking a library and still fatal error LNK1104: cannot open file 'OpenVolumeMesh.lib'

I really did not want to post on something possibly asked a zillion times, but this is very desperate.
I have a solution named HexEx containing 6 projects. 3 of them do not build due to not finding this lib.
The process I follow:
step 1) Configuration properties>general>configuration type set to .exe
step 2) VC++ directories: Added the path where the .lib is (doubled checked the path is correct through the cmd and checked the name is correct (indeed the name is OpenVolumeMesh.lib although the .lib does not appear in windows)).
I added the path in executable directories and library directories.
step 2.5) VC++ directories: Added also include path used to create the OpenVolumeMesh.lib
step 3) In linker >general I added the same path to >Additional Library Directories.
step 4) In linker, once more in >Input I added the library (OpenVolumeMesh.lib) to Additional dependencies.
The error I get is:
3>LINK : fatal error LNK1104: cannot open file 'OpenVolumeMesh.lib'
in 3 out of the 6 projects, I suppose the ones needing it.
Another attempt I tried (and this is probably stupid) was to add #pragma comment(lib,"OpenVolumeMesh.lib") in every .c or c++ file containing code.
The .lib was created by building a previous project of mine. All of this is done in VS 12 2013 x64.
From what I read there must also be some .dll put in windows system32 folder some times? Might this be the problem?
Any suggestions?

Error when trying to compile using sqlite3_open in Visual Studio 2013

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)

Visual Studio Include cpp file from other project

I have a C++ .h and .cpp file from another project that I want to include into my project.
I don't want to copy the files over into my project since I want any changes to those files be applied to both projects.
I've included the directory of the file's folder in the
Properties->VC++ Directories->Include Directories
I've also included the folder in the
Properties->C/C++ -> General -> Additional Include Directories
The .h files seem to work. If I rename the include to anything other than
#include "myfile.h"
The cpp file gets unknown definitions.
When I compile. The error is
fatal error C1083: Cannot open source file: '..\..\..\..\..\..\my project\myfile.cpp': No such file or directory
If I remove the cpp file from the project. Then I get a long list of unresolved functions.
error LNK2019: unresolved external symbol "public: unsigned long __thiscall myclass::myfunction"
How can I include both the .h and .cpp file into my second project?
For cpp files you can just use right mouse click on project, select "add"->existing item.
Then they should compile with others, when a build initiated.
Slightly more complicated with headers. There is two ways to use #include directive:
with < > and " " braces
When " " braces used, compiler treats path as relative (if not absolute used) to location of cpp file.
When < > braces used, compiler looks for file in something like system include folders. For example - stdlib headers folder and windows.h location folder. Properties entry Additional Include Directories also goes there.
I suggest you to change projects structure and extract shared features from both projects to compile it as static library. Place shared headers in some subfolder inside library project and refer then as
#include "mylibHeaderDir/someheader.h"
In dependent projects, after setting Additional Include Directories you can refer theese includes as
#include <myLibHeaderDir/someheader.h>
This approach will help you in future, as you can reuse that shared module in every project you want.
About how to create and link static library you can read this article http://msdn.microsoft.com/en-us/library/vstudio/ms235627(v=vs.110).aspx Version of visual studio may be differ, but basics are the same.
You can't just pick files like that. There are two reasonable ways to solve it. 1, shared the file by means of a Code Versioning System (e.g. svn/git). 2, compile the the .cpp into a library and link to that library.
If the cpp can be used by multiple projects, it must mean that the code is something common. That means you should compile that code by itself into a library and then share that library. Compiling the same cpp into multiple libraries is likely to result in conflicts later if two such libraries are ever needed to work together.
Try to drag them into your solution?
You can create a new folder in your solution, and drag them all into this folder!

Projects references and 3rd-party libraries

I have a solution with two projects on VS2010.
The main project references and depends on the second one, which is built as a static library. The second one uses a static third-party library that is not build within the solution, but is only referenced in the second project's linker settings.
If I try to generate the solution, VS fails and indicates that he didn't find the third-party library. I do not understand why, since the second project's compiled static lib is big enough and seems to "contain" the 3rd-party library.
So far, I see only two solutions to my problem, which I would rather avoid:
Add the 3rd-party library to the main project's linker settings
Include the whole 3rd-party library in my solution and compile it with
Is there any other way to resolve this problem?
EDIT : The problem occurs when compiling the main project, the compiler outputs : LINK : fatal error LNK1104: cannot open file 'wxbase29u.lib' (I'm using wxWidget in my second project)
EDIT2 : I put the -verbose option for linking on, and it seems like the references to the 3rd-party library actually still exists in Project2.lib :
Searching ..\MyAppConfig\Bin\Win32\Release\MyAppConfig.libĀ :
"public: static void __cdecl ConfigWindow::Open(void)" (?Open#ConfigWindow##SAXXZ) found
Referenced in main.obj
Loaded MyAppConfig.lib(configWindow.obj)
/DEFAULTLIB:wxbase29u processed
/DEFAULTLIB:wxbase29u_net processed
/DEFAULTLIB:wxbase29u_xml processed
/DEFAULTLIB:wxregexu processed
/DEFAULTLIB:wxexpat processed
/DEFAULTLIB:wxjpeg processed
/DEFAULTLIB:wxpng processed
/DEFAULTLIB:wxtiff processed
/DEFAULTLIB:wxzlib processed
...
...
LINK : fatal error LNK1104: cannot open file 'wxbase29u.lib'
Funny thing is that I don't even use the other wxWidgets libraries in Project2, but visual studio seems to be searching for all of them though :/
Here's how you should setup your project:
Project 1 (main)
Additional dependencies: Project2.lib
Project 2
Additional dependencies: ThirdParty.lib
Build order: Project 2 -> Project 1
If your project is setup like that and it does not link, then it just means the path to your libraries isn't correctly set (under "Additional include directories"). So just make sure that your project additional dependencies are correctly set and that the include directories point to the place where the libraries you need are located.