How to use zxing in c++ project? - c++

I'm just started doing things on c++, and I'm interested in barcode reader /writer, so I've chosen zxing for those purpose. Problem is that I don;t know how to use it since it has only .cpp and .h files. I've used opencv and it was easy to join it to my proj cuz it has .lib files. But ZXing does not.
So, can u please explain me, how to use .cpp "libraries" (are they?) in my project (if it isnt hard, do it on zxing example please).

first you need to know if your library needs compilation or no. mostly you need link precompiled libraries to your project and add the path to header files. if it's no, you can simply move your .cpp and .h files to your project directory, in your IDE you add these files to your project and then you use #include with doublequotes. I mean you need to include only header files.

Related

C++ copy only needed header file for dll from separate project

My C++ project is dependent on a huge project. My project uses many dll's from huge project. It take about few hours to install the huge project and I want to remove the need to install the huge project for someone else.
After research I understand there is two methods to compile and link using dll 1) Using a lib and header.
2) Using loadlibary method.
In loadlibrary method I need to know exactly the methods needed to load. Since I don't know this I went with option 1. Please correct me if I am wrong.
Currently I have included the path to the big project in the compiler additional dependencies configuration option. I want to share the included header with my team. The big project has lot of headers that is not used by my dependency dlls. I tried copying all the headers but some .cpp are directly used without any headers.
Is there any way I can copy only the header files needed from the huge project? Possibly automatically using less manual work. Currently the headers and cpp are about 1gb which I can't share via github. If I can't copy the headers is there anyway I could automatically generate all the dependency definitions to a file and use it? Please let me know whats the standard way of handling situations like this.
You can dynamically build and link to the library (dll).
To do so, you need to
include the folder containing the .h files with the compiler -I argument -IC:\path\
link to the folder including the dll with the linker -L argument -LC:\path\
The lib has to be compiled with the same compiler & same platform

C++ static and shared libraries

I would like to create a static library in C++ to store my functions.
I'm aware this question has been asked on the Cplusplus forums but I could really use a
more accurate description of what to do.
As far as I'm aware you create a new Win32 program and then add the header file (.h) and the
code file (.cpp).
So in fact I have a few questions.
1 - How do I put my code into these files?
Do I use the .cpp?
2 - I did manage to make a simple library with an add function alone, but after compiling
and building it I was unable to #include it in a program. Why is this?
Could someone please write out a step-by-step approach to making this so I can finally do it.
I am aware MSDN has a tutorial for this, and I have looked at it.
The thing is it uses a OOP approach to making the static library, and the calls to the
functions within the library use the :: operator (think its an operator), too often which is what I want to avoid.
Would like to start simple, basically.
Thanks for any help given.
The idea of a static library, is that you write your code as usual, but you compile it as a static library. The users of a static library still need your header files, but they don't need your .CPP files anymore, because the actual implementation is contained in your static library file.
To use a library, you include the header files you need, and then link the library file with your program.
Here is a link to the microsoft walkthrough.
http://msdn.microsoft.com/en-us/library/vstudio/ms235627.aspx
How to create and use a static library using Visual Studio
Here is excactly how you do it in Visual Studio 2012.
To create a library, create a new C++ project. In the wizard, at Application Settings, choose Static library. Uncheck Precompiled header.
Create your library as you want. Don't forget to declare everything in header files.
Compile the project as you usually would. This creates a .lib file in the debug folder of your solution
To use the library, create an application as you usually would.
To link the library with your project, drag the .lib file to your project in visual studio.
To let visual studio find your header files, right click your project. Choose Properties->Configuration properties->C/C++. There is a input box called Additional Include Directories. Here, you have to write the path to the header files of you library.
You can now use the header files as if they where made by your project directly. The implementation of your library is taken from the .lib file, and everything should compile and run well.
Another option, is referencing the whole libary project in your application. To do this, you must get the library project in your solution. Right click your solution in Visual Studio->Add->Existing Project. Then you have to reference the project. Right click your project->References->Common Properties->Framework and References->Add New Reference->Choose your project. Now you can edit your library in this solution and use it directly in your application.

do i need to add this head file "stdafx.h" to run an c++ program in windows

i am new to windows c++ i have created an application in visual studio 2008 and i have created new win32 console and i have compiled an sample c++ program it asked me to add the stdafx header and is it is compulsory to add this header ??? i dont need any windows library....
No, just create an EMPTY project, and add a main .cpp. This will be fine for any very small win32 projects. stdafx is absolutely unnessacery, and to be honest, I don't use it or even know what it is (I have only about a month experience with MSVC).
However, to make win32 applications, you need #include <Windows.h>, which is the windows header file.
To be able to remove the file you have to disable Precompiled headers in project settings. This might increase compilation time, so I'd recommend you just familiarize yourself with the mechanism. Its described on Wikipedia and at MSDN
The wizard will assume that you want something called Precompiled Headers and generate your project based on this assumption. In the new project wizard, make sure that you click "next" rather than "finish" (or similar) and ask for an empty project. With that done, add a new .cpp file and write your code in it. You should no longer need to include stdafx.h in every source file.
Precompiled headers are quite useful in large C++ projects, in that they can significantly reduce compile time. However, for most small to mid-sized projects they are mostly an annoyance. I personally tend to create empty projects -- if I want PCH, I'll add them myself.
This file is not mandatory.
It is created by the Visual Studio Wizard, and has for purpose to be the general include file, that you'll include in all your cpp files, and that'll include all the header files you need. It will serve as being the precompiled header source.
You don't need it, but compilation might break if you selected "use precompiled header" when you created your project and you don't turn off the corresponding "create/use precompiled header" compiler option.
A precompiled header is one that, as the name suggests, is partially pre-processed or compiled, so as to speed up the rest of compilation. Typically, if you were to use this feature, you'd put a bunch of #include statements in stdafx.h, for system headers that (virtually) all of the files in your project use. Things like <windows.h> are commonly put here, as are MFC or ATL GUI libraries. You can also put your own headers in there, but they should be ones that change only quite rarely.

Precompiled headers question

I am right now reorganizing my project and what recently was a simple application now became a pair of C++ projects - static library and real application.
I would like to share one precompiled header between two projects, but face some troubles with setting up the .pdb file paths.
Assume my first project is called Library and builds it's .lib file with a corresponding Library.pdb file. Now, the second project is called Application and builds everything into the same folder (.exe and another Application.pdb file).
Right now my both projects create their own precompiled headers file (Library.pch and Application.pch) based on one actual header file. It works, but I think it's a waste of time and I also think there should be a way to share one precompiled header between two projects.
If in my Application project I try to set the Use Precompiled Header (/Yu) option and set it to Library.pch, it wouldn't work, because of the following error:
error C2858: command-line option 'program database name "Application.pdb" inconsistent with precompiled header, which used "Library.pdb".
So, does anyone know some trick or way to share one precompiled header between two projects preserving proper debug information?
The question is, why do you want to share the precompiled header (PCH) files. Generally I woul d say, that does not make sense. PCH are used to speed up compiling not to share any information between different projects.
Since you also write about the PDB file, you probably want to debug the library code with your applications. This can be achieved by setting the /Fd parameter when compiling the library. When you link the library in your application and the linker finds the corresponding PDB file, you get full debug support.
This sounds complicated and cumbersome to set up. More than that, it may not be possible at all.
Instead, you can include the precompiled header from one application into the second. It will still be compiled once for the second project, but maintenance becomes easy and you do not have to redefine the dependencies in the second project (just include them).

How does visual studio know which cpp files to rebuild when an include file is changed?

In some of my VS 2005 projects, when I change an include file some of the cpp files are not rebuilt, even though they have a simple #include line in them.
Is this a known bug, or something strange about the projects? Is there any information about how VS works out the dependencies and can I view the files for that?
btw I did try some googling but couldn't find anything about this. I probably need the right search term...
I've experienced this problem from time to time, and with other IDEs too, not just VS. It seems thatv their internal dependency tree sometimes gets out of whack with reality. In these cases, I've found deleting pre-compiled headers (this is important) and doing a complete rebuild always solves the problem. Luckily, it doesn't happen often.
To be honest I never faced such a problem using Visual Studio. Your CPP should be rebuild as well if it includes the header. The only reason I can come up with: same include file is taken from 2 different sources.
You can try do debug this at compile time, by enabling the preprocessor to output preprocessed files. Click on the CPP file go to properties and then to C/C++->Preprocessor and select in "Generate Preprocessed File" the item with or without line numbers.
Go to you include file put the pragmas around your newly added definitions like:
#pragma starting_definition_X
...
#pragma ending_definition_X
Now compile everything. There will be a newly created file with the same name as CPP but with extension .I (or .i).
Make a search if your pragmas are there. If not, your include come from another place.
If you use pre-compiled headers, you cpp should rebuild. There is also a pragma once statement in MS VC, which parses the include file only once, but that should still recompiler you cpp-file.
Hope that helps,
Ovanes
Do you have the "Minimal rebuild" option turned on?
Visual studio compares the timestamps on the files. So you might want to check that your system clock is set correctly and also that none of the files has a funny timestamp on it. Look at the include files, the cpp files, the pch files and obj files and make sure all the timestamps look reasonable. In particular, make sure none of them are in the future.
Was the .h files added in the project? If not, then vs maybe unable to find out the dependency.
Thanks for all the answers they have helped point me in the right direction.
I have discovered that deleting the idb file and rebuilding will then allow subsequent modifications of .h files to cause the correct .cpp files to be built. However this causes the entire project to be rebuilt which just brings me back to Neil Butterworth's suggestion of doing a full rebuild. I don't think there is much else I can do about it.
As an aside, looking at the bad and good idb files I can see that the cpp file that was not being built is not in the bad idb, whereas it is in the good idb. The header file that is being changed is mentioned several times in both files.
win_pdbx (download) can extract the idb file and moyix has published some information about the streams in these files.
Stream 4 contains the file paths of the cpp files but I have not been able to determine the format.