Linking CodeBlocks to Poppler Library - c++

I'm relatively new to programming in C++ and while I have some experience in general coding practices, conventions etc... Recently I have come to precipice of my (limited) knowledge.
Basically I wish to write a program that will allow me to extract the annotations from a PDF file. With some research I discovered that the Poppler library would allow me to do this. So I downloaded it and began the arduous process of building it for CodeBlocks (MinGW) on Windows Vista.
For those interested, the following site provided invaluable information with regards to the building of Poppler with Cmake:
http://www.seppemagiels.com/blog/building-poppler-windows-using-mingw>
Anyway, onto my current dilemma. Having followed the out of source conventions of Cmake I have a file structure like so:
...\Work\
..............poppler-0.22.2
..............poppler-0.22.2_Build
In the "poppler-0.22.2_Build" folder there is a " libpoppler.dll.a " file which i have been led to believe is a Library folder. I have then followed the instructions as described here:
http://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/
I then linked to the libpoppler.dll.a file in the "poppler-0.22.2_Build" directory and the .h files which were in the original source directory (i.e. poppler-0.22.2).
Now my question is what do i need to write in my main.cpp such that i can use the Poppler functionality. At first i just wrote:
#include "poppler.h"
However, this returned with a "No such file or directory" error.
Then i tried:
#include "poppler-qt4.h"
This then executed however I was informed later in my code that "poppler" has not been declared.
Then I tried:
#include "poppler-qt4.h"
#include "C:\Users\...\poppler-0.22.2\cpp\poppler-document.h"
Which then returned a "undefined reference to 'imp_ZN7poppler8document14load_from_fileERKsS2_S2_'" error...
So that's where I am right now, I have absolutely no idea how I should continue and I was hoping someone could walk me through the steps I need to take to get Poppler to work i.e. as in how do I get the library to link, if that is indeed the problem, or how do I overcome the "imp_" error. I really am at my wits end with this problem...
Thanks in advance for any help you can supply.
P.S. My main.cpp so far:
#include <iostream>
//#include "poppler.h"
#include "poppler-qt4.h"
#include "C:\Users\...\poppler-0.22.2\cpp\poppler-document.h"
using namespace std;
int main()
{
const string dir = "C:\\Users\\...\\TestPDF.pdf";
poppler::document *doc = poppler::document::load_from_file(dir)
return 0;
}

In Code::Blocks, right-click the name of your project and select "Build Options...". Select the option in the left-most menu that says the name of your project (should be the first option) and click "Linker Settings". Now press the "Add" button and browse to your DLL file, then press "Ok".
To allow including the header files of your library (without writing down the full path in your source code), you should tell add their location to the compiler's include path. You can do this on the "Search Directories" tab in the same window. Make sure the "Compiler" sub-tab is selected and press "Add". Browse to the the directory containing the header files and press "Ok".
Hope this helps.

Related

C++ Same include line in 2 files in the same folder: one works, another can't find the file

Windows 10
Eclipse IDE for C/C++ Developers
Version: Kepler Service Release 2
Build id: 20140224-0627
I'm trying to use imgui. Unfortunately, documentation is pretty shady about how to get it working.
So, in order to get it working, I think I need something called "glad". Whatever it is, the only source of it seems to be some shady-looking one-pager that generates the files for you (found a link to it here).
Anyway, I checked all the boxes I needed (copied from the screenshot from the provided link). I don't understand much about what it is (very roughly), I simply want to get imgui running (ha-ha on me, imgui also needs some other stuff scattered around internet, but it's my next problem, not current).
Anyway, in my new C++ project in eclipse I created a folder "include" and added its path into "C/C++ General -> Paths and Symbols". So when I write "#include "glad/glad.h" in my "test3.cpp" (file with main function, project called test3), I'm ok. But I can't build it because glad.c, which is located in the SAME folder as test3.cpp, has the identical include line, but it gives an error that it can't find it. Sounds like some nonsense to me.
#include "glad/glad.h"
#include <iostream>
using namespace std;
//for those who wanted to copy default hello world program
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
How is this even possible? Looks like a total nonsense to me. They're in the same folder. Test3 sees the file, glad.c doesn't. I tried replacing "<>" in include in glad.c with quotes like in test3.c, same thing. One file works, another doesn't.
What can I do about it?
Eclipse separates the include paths for C and C++ files. If you have a program combining both C and C++ files, the correct include paths need to be set for both languages.
Navigate to the C/C++ General -> Paths and Symbols -> Includes tab. You will see both languages (and probably Assembly) listed under Languages. Pick the correct language or when adding the path, check the Add to all languages box.

Codeblocks can't find header files

So a few hours ago I started learning c++ in codelite but I was getting frustated with, so I just got codeblocks and imported the project. But now whenever I try to compile it returns:
fatal error: imports.h: No such file or directory
This is my project hierarchy in codeblocks:
And this is what the project folder looks like:
What am I doing wrong?
I know this is years later, but I've recently seen students following what I deem is frankly bad advice such as what is given above. For those learning c++ this functionality is NOT for you. To add headers you should simply check that you are using double quotes, instead of angled brackets i.e.
#include "myheader.h"
and NOT
#include <myheader.h>
Angled brackets are meant for libraries (informally) and adding a simple header file for you basic classes does not require you to change default search directories. The problem comes when someone else tries to run your code (assuming you're doing this for uni) and their IDE isn't setup to search for a "library" (your header) where it shouldn't be. Double quotes tells the compiler the files exist in your current relative directory. This way you can keep your main, headers and header implementation in one directory. Fiddling with your IDE should only be done when necessary. KISS
You have to tell Codeblocks where to find the header files that you include. Try adding the full path to your '/Headers' in the include directories of codeblocks
Goto 'Codeblocks menu > Settings > Compiler > Search directories > Add'.
EDIT: Since your issue, however, is quite irrelevant to learning the C++ language itself, I suggest that you start with simpler programs, then move on to more complex ones. That, of course, unless you have previous experience with other programming languages
Since I haven't found any Makro for
#define 'hostname of device where compiler is located' // which is unique and not to be copied !
I have now successfully used and included
#include "myCompileEnv.h"
as a workaround with the comments above, which is located more central - above the project directories in CodeBlocks.

Netbeans and Boost libraries in OSX

So far I have downloaded the boost libraries using brew and found their location and copied them to my home folder.
I've tried to follow closely how to add these libraries from windows tutorials, but I seem to be missing something. Upon compiling this...
#include <iostream>
#include <string>
#include <boost/regex.hpp>
using namespace std;
using namespace boost;
int main() {
string s = "This is my simple sample text, really.";
regex re(",|:|-|\s+");
sregex_token_iterator my_iter(s.begin( ), s.end( ), re, -1);
sregex_token_iterator my_end;
while (my_iter != my_end)
cout << *my_iter++ << 'n';
return (EXIT_SUCCESS);
}
I simply get an error stating that #include <boost/regex.hpp> file not found
Using
Netbeans 8.0.1
Mac OS 10.9.5
Most tutorials show how to set up using cygwin, which doesn't apply to me since I'm on windows and there are no helpful or easy to follow tutorials for Mac OS.
Please and Thank you for any help on this matter.
After trial and error i have figured it out!
So in Netbeans 8.0.1 what you want to do to set up for regex is:
Under Netbeans>Preferences select the C/C++ tab, then in this window tap on "Code Assistance" then "C++ Compiler"
In the "Include Directories" you are going to add the location where you saved your boost libraries and header files, on my machine it install to
/usr/local/Cellar/boost/1.56.0
yours may be different.
Once you've done that, hit "Apply" and you can close this window.
I then used the code from my original post to create a new c++ project.
Once you can compile a "Hello World" go ahead and replace your code with the once from my original post.
On the left hand side (default) where your project folder is, right-click the folder and select "Properties". You should then get this window. Navigate to "C++ Compiler" under the "Build" option.
Remember how we located the folder where both the include files and library files? Do the same in the "Include Directories" section, except this time you will select the folder which contains the .hpp files. In my case it was "/usr/local/Cellar/boost/1.56.0/include"
Hit "Apply".
So that takes care of out header files. Now lets do the library files!
Once that is done, navigate to the "Linker" option within the same option window. We are/were in.
Under the "Addition Library Directories" Locate the folder that contains your dynamic and static libraries. These filetypes should end in .a or .dylib.
Mine were located in "/usr/local/Cellar/boost/1.56.0/lib"
Now all you have to do is select the "Libraries" and the "..." on the right which will give you a new window.
Here you will select "Add Library File" and add the following...
they should be labelled:
"libboost_program_options-mt.dylib"
"libboost_regex-mt.dylib"
Once this is done, build and run and your result when using the code above should be:
"Thin in my nimple nample textn really.n"
Hope this help anyone else!

error C1083: Cannot open include file: 'FL/Fl.h': No such file or directory

First of all I'm still new here and therefore have no idea how to format the code so it looks neat in this question, I hope this is acceptable.
I am following the programming principles and practice from Stroustrup. You might guess what the problem is...yes FLTK instalation. I have followed all the steps carefully to build the project in VS C++ 2013; pages 1204-1206. (I've done appendix C successfully, having to do with std_lib_facilities.h).
I was trying to build the following win32 project, as shown in the book:
#include <FL/Fl.h>
#include <FL/Fl_Box.h>
#include <FL/Fl_Window.h>
int main()
{
Fl_Window window(200, 200, "Window title");
Fl_Box box(0, 0, 200, 200, "Hey, I mean, Hello, World!");
window.show();
return Fl::run();
}
After building solution, I receive an error which reads: Error 1 error C1083: Cannot open include file: 'FL/Fl.h': No such file or directory
I have also followed the steps to copy across some lib files from the FLTK lib directory into c:\users\pablo\desktop\c++ course files\visual c++\win32project1\source.cpp which is the file I created for Visual Studio Express 2013.
Can somebody help me? Where do I find this missing file? Is the problem perhaps having to do with the fact that the FLTK version is a bit outdated to be used in VS 2013? (When I compiled the FLTK library, I got some errors having to do with backup file and some warnings.)
I have researched this long an hard. I found some questions having to do with this in this forum but not exactly related to the above mentioned problem. Thanks very much in advance.
PS Well, there was one question having to do with the same error. I've followed some of the tricks mentioned as an answer to the same question but to no avail.
("A neat trick you can do for these types of errors is to place your cursor into the file name of the #include statement and press Ctrl+Shift+G. It will fail and display a message box showing what the include paths are. The solution is to simply add additional include paths to the SDK by right clicking your project and going to Properties>C/C++>General and setting "Additional Include Directories".")
The other suggestion shown didn't work either: ("Make sure the include directory is not the FL directory, but its parent. The reason for this is when you say #include "FL/Fl.h", you're asking the compiler to step into a folder called FL to find Fl.h, which will reside in FL's parent. If you specify FL as an include directory then you need only say #include "Fl.h"").
The other answer isn't remotely true (I have literally just compiled an FLTK program with all headers in the form #include <FL/xxx.H>). When you download FLTK you get a directory (say fltk-1.3.2) which has this structure
/fltk-1.3.2/
FL/
GL/
src/
lib/
examples/
+ other stuff
The sub directory FL contains all the header files. As such if wherever you've placed the fltk-1.3.2 directory is located at \foo\ then you need to add \foo\fltk-1.3.2\ to your additional include headers field. Do be careful, you might have accidentally chosen the wrong directory (it happens) or you might have extracted the contents of a zipped version of the file into a nested version of itself meaning you might have something like \foo\fltk-1.3.2\fltk-1.3.2\ So have a look.
If it can't find the headers you almost certainly have got the additional include directories field looking in the wrong place or in the wrong format. Click on the drop down button, click edit and manually click the new folder button and navigate to it.
What you will find next is that you have to point the linker in the right direction. In the above the default place to install the library files (.lib static should be default for FLTK) so you need to add \foo\fltk-1.3.2\lib\ to configuration properties -> Linker -> General -> Additional library directories
THEN you need to link to the specific libraries. Since the linker now knows where to look you down need to specify the path, but just name them. To do so go to configuration properties -> Linker -> Input -> Additional dependencies, click the drop down option, click edit and add on separate lines (and without these commas) fltkd.lib, fltkformsd.lib, fltkzlib.lib,wsock32.lib
This is because there is no header file named #include <FL/Fl.h> what they mean by this is to include either #include <FL> or #include <FL.h> depending on what program your making, but the former is most likely what you want to do since it's the standard version. #include <FL.h> is an old library, and is not even included in the standard. It is also not even included in every platform. You should not use the .h version in this example.
The same can be said for the other two header files as well.
The original question was about Windows, and the direct answer to the question is to add the directory above the FL directory (note: uppercase) to the include paths of the Visual Studio settings.
Since this is about windows, spelling of the header files may not matter, but such programs as shown by the OP are not portable because other systems use case sensitive file systems. For portability almost all FLTK header files must be written with uppercase ".H" to be found on case sensitive file systems (there are some exceptions). The correct example program - tested on case sensitive Linux with current development version FLTK 1.4.0 - would be:
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>
int main() {
Fl_Window window(200, 200, "Window title");
Fl_Box box(0, 0, 200, 200, "Hey, I mean, Hello, World!");
window.show();
return Fl::run();
}
Note that this still needs the correct include path to compile and build.
this works !!!
On your own Linux/Mac: Download the source for fltk 1.1.10 and unpack it in a directory of your choice. You should be able to execute "configure", "make", and "sudo make install" to install fltk in /usr/local/lib and /usr/local/include.

Xcode cannot find #Include<> header

I'm trying to get Xcode to import the header file for Irrlicht.
#include <irrlicht.h>
It says "Irrlicht.h. No such file or directory". Yes Irrlicht.h with a capital I, even though the #include is lowercase.
Anyway I added "/lib/irrlicht-1.6/include" in the header search paths for the Xcode project, yet it still doesn't find it.
The only thing I've tried that does work is:
#include "/lib/irrlicht-1.6/include/irrlicht.h"
This is a bit ridiculous though, #include should work, I don't understand why it isn't working.
Update (here are more details on the error):
/lib/PAL/pal_benchmark/palBenchmark/main.h:31:0
/lib/PAL/pal_benchmark/palBenchmark/main.h:31:22: error: irrlicht.h: No such file or directory
I figured this out. Perhaps someone can comment as to why this is the case.
The Header was located in this directory:
/lib/irrlicht-1.6/include/
If I added that path to: "Header Search Paths" Xcode still wouldn't find the path when I built the project.
Solution: Add the header path to: "User Header Search Paths" instead.
It boggles me why I had to do this, as I frequently add my header paths to "Header Search Paths" and then #includes just work. Hopefully this can help someone else who gets this same issue.
Both
#include <irrlicht.h>
#include "irrlicht.h"
should work as long as the "-I" argument to gcc includes the path of the directory enclosing the header file. If irrlicht.h is part of /usr/include the "-I" option is no longer required.
Rather than explicitly adding include paths to your project settings, an easier and more convenient solution for this kind of situation is to just drag the directory containing your .h files (/lib/irrlicht-1.6/include in this case) into the project files pane. This adds the headers to your project of course, and makes it easy to browse them and search for symbols, etc, and it also adds the directory path to gcc compiles, so that you don't have to manage include paths explicitly.
and furthermore, a flat file hierarchy isn't what you want. Dragging files into Xcode flattens your hierarchy. What about for example when you want to have multiple Targets, with a "TargetName/settings.h" file for that target. you'll have many settings.h files that you need to keep unique via its folder name.
I understand that this is an old post, but it does rank quite high on Google, so I thought I would add some information
Under XCode 3.2.6, I had an issue where XCode could not find a header file. It turns out that one of the filepaths included a space in it, and XCode interpreted it improperly.
For example: With a path like "Users/Username/Desktop/Project/Some Headers"
Here was the excerpt from the GCC Commandline: "-I/Users/Username/Desktop/Project/Some" "-I/Headers"
To see your build log provided by XCode, there is a good tutorial here: How do you show Xcode's build log? (Trying to verify if iPhone distribution build zip was created correctly.)