Ok, so I've seen a few tutorials tell me how to do this but my interface and results don't match theirs. I've done this a lot myself with C#, and I don't get why the difference is.
*I have a third party dll (and lib, and .h files)
*I have a project in Visual Studio 2012 Express
*I want to add the dll to the project (I believe what I want is to implicitly link).
There is no References folder in my Solution Explorer. If I select [Project > Properties > Framework and References > Add New Reference] then all it will show me is other projects in my solution. I've looked around at the project options (Linker > Additional Dependencies, etc) but there are a lot of possible places which might do something (or not) in who-knows-what combination.
C++ and C# are different. when you choose c++ project it requires different approach than C# to configure things. You have to add first you header files path in additional include directory then you dll path in linker and dll name in linker input in project settings.
Add the .lib file to the Project -> Properties -> Linker -> Input -> Additional Dependencies field, and #include the .h file. The .dll file will need to be in the search path which is documented here.
Related
I'm having trouble trying to get v8 working with visual studio 2019.
I have followed the compiling guide on v8.dev and built it on windows.
I have followed [this]Google V8 - Neither v8.dll nor v8.dll.lib getting built in release mode answer to obtain .dll and .lib files.
Now I'm stuck. I tried to build the examples they show on the official site (https://chromium.googlesource.com/v8/v8/+/branch-heads/6.8/samples/hello-world.cc) but I get all sorts of errors.
From what I understand, I need .dll, .lib and .h files. I have them, but I'm not able to use them correctly in visual studio.
I have tried adding the header files under include directories and .lib files under Linker > Input > Additional Dependencies without luck.
There are good chances anyone who has worked with c++ beyond simple console programs will laugh at my ignorance, and I would understand that.
Any help would be very appreciated.
UPDATE
These are the steps i followed to use v8:
1) Created a new c++ console solution
2) Added header directory at Configuration > C/C++ > Additional Include Directories
3) Added dll and v8.dll.lib folder in Configuration > Linker > Input > Additional Dependencies
4) Pasted this (https://chromium.googlesource.com/v8/v8/+/branch-heads/6.8/samples/hello-world.cc) code to my editor
The first type of error I got is E1696: it looks like some headers contain references to other headers with absolute paths and not relative paths.
I fix this by myself making reference paths relative in headers.
Then I get 23 LNK2019 errors:
screeshot
What should I do?
I've been programming in Python for over a year now but am just learning C++ and am unfamiliar with how to go about using external libraries, CMake and github for that matter. I'm trying to use an external library called cpr - https://github.com/whoshuu/cpr. So far I've followed the instructions in the 'Usage' section of that link up to, but not including, the "add_subdirectory(cpr)" bit.
So far I've got the source code for cpr in the Visual Studio project folder of my C++ project. In the project properties I've then added into Include Directories (under VC++ Directories) "$(SolutionDir)site_libs\cpr\include" and I've added the same thing into Additional Include Directories (under C/C++ -> All Options). This means that the following code compiles just fine:
#include <cpr/cpr.h>
int main(int argc, char** argv) {
auto r =
cpr::Get(cpr::Url{"https://api.github.com/repos/whoshuu/cpr/contributors"},
cpr::Authentication{"user", "pass"},
cpr::Parameters{{"anon", "true"}, {"key", "value"}});
r.status_code; // 200
r.header["content-type"]; // application/json; charset=utf-8
r.text; // JSON text string
}
However this code isn't working when it comes to building, due to link errors. I'm pretty sure the thing I'm missing is the actual .lib file for it to find where these functions etc are defined (nothing for cpr is set in the Linker -> Input property). So I'm wondering - how do I create this .lib file / is that even the right thing to do / what is this "add_subdirectory(cpr)" and where/how do I run it... basically what do I do to make this whole thing work..?! I've tried compiling cpr with CMake but it throws a load of errors about 'CMakeLists.txt' not present in certain folders.
Apologies if I've used any incorrect terminology here, only been learning C++ for a couple of days now. Any help massively appreciated!
If the library does not come as a binary distribution (that is with the .lib already built) you are going to need to build it as a separate project from the code you want to use the library, that step will build the .lib file. If a .sln is included with the distribution use that otherwise you may well have to create your own (or add it as a project to an existing solution).
Once you have a .lib add the directory under the VC++ directories of the project settings and add the actual .lib file name under Linker->Input on the Additional Dependencies line.
To build the library if the distribution does not include the needed VS files you will need to create a project at minimum (it can be part of the solution for your program), right click on the solution node in solution explorer and select Add->New Project, from there select Visual C++->Windows Desktop and either Dynamic Link Library or Static Library as you desire.
Go to the Project menu and select Project Dependencies, change your program to depend on the new project, this will set build order so your program project builds after the library.
You may need to disable the use of pre-compiled headers, right click on the new project node select Properties, go to C/C++->precompiled headers and change Precompiled Headers->Precompiled Header to Not using precompiled headers.
Next add the header and source files to the project and attempt building.
If this succeeded you will have a .lib suitable for use in the additional dependencies of your program project as already described.
I am having issues compiling a basic openGL program on VS 2012. I get a build error upon compiltation giving me:
1>LINK : fatal error LNK1104: cannot open file 'glew32.lib'
I followed the instructions given to me by the documentation for GLEW.
In your OpenGL project open Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies -> add glew32.lib.
Also you must include #include in your sources; For that add path to your glew folder: Project -> Properties -> Configuration Properies -> General -> VC++ Directories -> Include Directories and Library Directories;
C/C++ Tab -> General -> Additional Include Directories - Add lib folder there
I have also added the glew32.dll onto my Debug folder within my project folder along with the executable. So far I keep getting this error.
If you need any more further clarification of the steps I have done please don't hesitate to ask
In all honesty, there is no real benefit to using the DLL version of glew (short of reduced executable size, but this hardly matters on modern Windows PCs).
It is not like you can simply drop a new version of the DLL into your application and use extensions that you never used before. Likewise, bug fixes are so infrequent/unnecessary with a library that basically just parses the extension spec. files that using the DLL as a means of fixing extension loading bugs in shipped software is also not practical. Statically linking to glew (this means glew32s.lib) makes much more sense in the long run.
The static linking library is also more portable on Windows, it will work with MSVC and MinGW (whereas the DLL library only works with MSVC). Link against glew32s and put that in whatever directory you decided to use for additional library dependencies.
Here is a sample solution configuration for a project I wrote that uses glew. I have established a convention for this particular software where compile-time dependencies are stored under platform/<Subsystem>. Thus, I have glew32s.lib (32-bit) and glew64s.lib (64-bit) in ./Epsilon/platform/OpenGL/glew{32|64}s.lib
Steps to Use Classes form another project (Add header and solver linker errors)
To be able to add the header from another project, first go to "Properties > c++ > General > Additional Include Directories" and add the directory that contains the header. Now you will be able to add the header of the class from the other project, but running the project will still cause Linker Errors.
Add __declspec(dllexport) before the class you are using for the other project. This can be added in the header file of that class. This should be added right before the function or variable or class name. Now you will get a lib file. (if placed in wrong place, you can get this warning: https://msdn.microsoft.com/en-us/library/eehkcz60.aspx)
"Properties > Linker > Additional Library Directories". Specify the location of the lib file that is generated.
"Properties > Linker > Input > Additional Dependencies”: Add the name of the lib file.
This sounds like the library has been specified as a dependency, but the linker/additional search path(s) has not been set to include the directory where the library is located.
This may help.
It happened to me under this situation, I clean the solution and build it again, then many errors like LNK1104 occur.
After trying to restart IIS, I build solution successfully without LNK1104 errors. I do not know why, but restarting IIS takes much more time than normal, so I guess something is used by other IIS worker process.
Just give a shot to see if this magic happens on you.
This question is old and marked solved, but I had a similar problem symptoms with a completely different solution. So just in case anyone else stumbles in here:
It appeared that because I had 2 projects under one solution (a dll and an exe), the building order was mixed (from the output window):
1> Rebuilding project1..
2> Rebuilding project1..
1> file1.cpp
2> file1.cpp
and so on. By the message you copied, it appears you too have more than one project under one solution. One project was looking for the *.lib file that the other build hadn't created yet.
Solution:
Right click on "main" project -> Build Dependencies -> Project Dependencies.. -> Mark which project the main one depends on.
I have a problem. I place my .DLL and .LIB file in the same directory as my project, go to Properties -> Common Properties -> Framework and References -> Add New Reference. But the list comes up empty.
Is there something else I should be doing?
C++ is not C#. You don't include .dlls in C++ applications by adding "references". Unless it's C++/CLI, but that's not C++.
In C++, you would go, in the project configuration, to Linker->Input->Additional Dependencies. There, you would list the library name plus path to the .lib in question.
Normally, when you build a Windows C/C++ DLL, you also get a .lib. This is an import library; users of the library include (as stated above) that .lib in order to access the DLL. They generally do not load the .dll directly (though there are ways to do that).
I have a certain c++ (library) project in netbeans 7.0. Lets call it the A project.
Now i have a c++ (application) project called B.
B depends on A:
1) at compile-time for some includes in A project
2) at link-time for the libA.so
2) is pretty easy, since i just need to go to project properties-> build(linker) -> libraries and click "Add Project.."
However its not that clear what the best nice, clever approach for 1) is. I've created pkg-config entries in the past to help projects find third-party libraries, but is a bit more work to do it for projects themselves. I could also include existing file directly, but i would have to add ugly ../../A/ in the includes which is PRECISELY what i'm trying to avoid
So I would like to hear about people solving this problem in the past and what was the best solution they found
You can add "an additional library directory" in the linker portion of the project properties. Then you can refer to library file "A" without the path specifier. This is a command line option to the linker to search that directory for libraries it has not found.
I'm not sure if they've added that option to the project properties for Qt projects in 7.0 or not. It's missing for those projects in 6.9.1