Using C++ library that comes as .cpp and .h files - c++

I'm trying to use this library: https://github.com/micknoise/Maximilian to do some DSP and am pretty new to C++ compilation which is leading me to some issues,
I'm using Visual Studio 15 and have successfully included a number of statically linked libraries that come in .lib and .a form but am confused on how to link the aforementioned code into my project since it does not come in a compiled form. Simply putting the unzipped project folder (which contains maximilian.h and then a /lib directory with the rest of the .c and .h files) into my include paths leads to linker errors. Am I missing a step?

Thanks to the help above, I was able to get the .lib file by opening the visual studio project and changing the export from .exe to .lib. I then included that in my project and things worked great.

Related

No .lib file generated after building tiny C++ static library project

I decided on adding a tiny extra project to my visual studio solution which includes only a single header file(for now) with a mutex which allows only 1 thread to output to the console at a time. Since this is a functionality which all of my projects in my solution will need so I thought it will be best to add a separate project for it and add references to it on the other projects.
So I created an empty project named Commons, then added an header file logger_mutex.h and wrote the following code inside it.
#pragma once
#ifdef _DEBUG
#include <mutex>
std::mutex loggerMutex;
#endif
I changed the project type in properties from Application(.exe) to Static Library (.lib). Then I added the include path to this file in the other project properties. Also I added this Commons project as a reference to all my other projects. But now when I try to build the solution it gave the error LINK1104 cannot open file ../path/to/my/output/directory/Commons.lib
I investigated on the output directory and there was no file in there named Commons.lib. I tried rebuilding the Commons project separately, and even though visual studio said it built successfully I did not see the Commons.lib file appear on the output directory.
I tried it even without the other projects, in a completely different solution. It still did not generate any .lib file in the output directory. I think this should be verifiable as well.
So what am I missing here, is there some kind of minimum requirement needed to have to get a .lib output file generated? Is my code too small to generate a .lib output? I am using Visual Studio 2022.
Add one empty .cpp file in your lib project and a lib will be generated.
But as far as I am concerned, it will be better to #include the logger_mutex.h to other project's pch.h instead of as a library.

How to include header files of another projects in the same solution?

I have two C++ projects (proj1 and proj2) in the same solution. How to include the header files from proj1 into proj2? I included those header files in proj2 by setting Additional Include Directories, but cannot link those functions - Error: unresolved externals.
you don't need to from the reference of porj2,add proj1,then the compiler will link proj1 when compile proj2.
So your problem is not the actual inclusion of the header files, it's linking to the object files of the other project.
There are basically two solutions to that problem:
Simply pull in the source file from other project into the project where they are needed. This will cause you to build the source files twice, once for each project. Note that I don't mean you should physically copy the files on disk, just drag and drop the source files in the solution side-bar.
Put common code in a third project, as a library. Then both your projects uses this library, and links with it.
I highly recommend the second solution.
While you are getting linking error that means you have compiled your code successfully and that means that you have included your headers correctly. Congrats! However, you are facing unresolved externals error. This is because you have just tell the compiler where to find the .h file but what about the real code? yes the one in the .cpp?
Options:
Put all your code in .h files which could be a fast solution but not an good idea (unless you need portable solution for templated code).
Build your first project as static library and link with the output .lib file (you could find how to do it by quick googling)
Bring your sources (.h and .cpp) to the other project and build them inside your project (Huge redundancy happened here).

Creating a C++ visual studio project based on existing files

I've never worked with C++ or C. I'm trying to create a Visual studio project based on existing files which can be found here: example1.cpp together with the resources. As you can see this is example code of a book for OpenGl. I have opengl and glut present on my computer and they work ( tested it).
Based on the files mentioned above a created an empty C++ project in visual studio 2012 (i also have other versions installed if you can provide a solution in 2010 or so). I included the header files & the source file. Though I still get the following in my IDE:
with errors such as:
cannot open source file "Angle.h"
( Though the file is present in the project)
Can anyone tell me how I get these files to compile and run ?
Make sure that the file angel.h it's in the same path that the .cpp file.
Header files need to be in same directory with source files in order to use #include with quotes.
#include "header.h"
In other words Angel.h must be in same directory with example1.cpp.
However,you can add spesicific paths to your project from Project Settings>VC++ Directories and include header files which exists in those paths using
#include <header.h>

Cannot link to lib file after upgrading to VS10

So I imported this VS9 solution into VS10 and VS10 would convert the whole thing into its new format for solution and project files. However, now it is giving me linker errors.
One project, a native C++ project, is using a set of header files and a .lib file to link to some external library. In the project, this library is specified by being put into a "Library" folder in the project. In VS9, this works fine, in VS10, it fails. The same lib is linked, however, when put into the "Additional Dependencies" setting in the Linker Input panel of the project's options.
I know the technique to drop lib files into the project for more than a decade. Has this stopped working with VS10?
No ,that still works in VS2010 (just tested it to make sure)!

Linking problems with TinyXml++ and Visual C++ Express Edition 2008

I'm trying to use TinyXml++ in my project, and I have tested it successfully in a small program before. I recently decided to use it to read a configuration file in my current project and though the code compiled, I got a ton of linker errors (unresolved external symbols mostly). I read in some forum thread, describing a similar problem, that I had to use the same runtime library as TinyXml++ was compiled with. I opened the accompanying Visual C++ 2008 project and saw it was using Multi-threaded Debug (/MTd).
I have now tested all runtime libraries with and without #define TINYXML_USE_TICPP before I include "ticpp.h". I've gotten from 9 to 80 linker errors (which I why I initially didn't want to post them all, but I will if you want to see them).
I have copied the static library ticppd.lib (found in the download folder) to my project's directory and linked it under Linker->Input->Addtional Dependencies. I have included a directory path to the TinyXml++ source under C/C++->General->Addtional Include Directories. What am I doing wrong? :(
TinyXML is a library with the full source code available; you should not need to include a .lib. You could separate TinyXML into a separate project and mark your project as depending on it, which will allow you to compile both projects with consistent settings for threading and debugging, but the easiest way to get it working should be to just add the TinyXML .cpp and .h files (just not the test one) to your project and compile.