Error with Poppler implementation with C++ - c++

I'm currently working on project which uses the poppler library. As It stands I have the following:
In the following folder (C:\Users\ ...\Anotation Extraction) I have all the files associated with a Codeblocks C++ project (including the main.cpp) as well as the current version of poppler and its associated documents in a folder called "poppler-0.22.2".
I also have a test pdf in this folder.
(System: Windows 7, 64 bit, Codeblocks using MinGW)
In my main.cpp file I have the following:
#include <iostream>
#include "poppler-0.22.2/cpp/poppler-document.h"
using namespace std;
int main()
{
const string dir = "C:\\Users\\...\\test.pdf";
poppler::document* doc;
doc = poppler::document::load_from_file(dir);
delete doc;
cout << dir << endl;
return 0;
}
However, when I try to build this code, the following errors pop up and I have absolutely no idea why.
obj\Debug\main.o||In function `main':|
C:\Users...\Anotation Extraction\main.cpp|11|undefined reference to `imp__ZN7poppler8document14load_from_fileERKSsS2_S2_'|
C:\Users...\Anotation Extraction\main.cpp|12|undefined reference to `imp__ZN7poppler8documentD1Ev'|
||=== Build finished: 2 errors, 0 warnings (0 minutes, 1 seconds) ===|
Any help you guys could provide would be much appreciated.

Related

My Class.cpp is not being seen by the linker

I am trying to write a C++ class in a separate header and cpp file using VS Code as my IDE with the 'run' and 'C++' extensions.
main.cpp
#include "Fan.h"
int main() {
Fan fan1;
return 0;
}
Fan.h
#ifndef FAN_H
#define FAN_H
class Fan {
public:
Fan();
};
#endif
Fan.cpp
#include "Fan.h"
#include <iostream>
using namespace std;
Fan::Fan() {
cout << "Fan Class" << endl;
}
I really can't seem to find anything popping out as obviously wrong. I am wondering if it is a setup problem with VS Code.
If I change #include "Fan.h" in main.cpp to "Fan.cpp" it works so it makes me think that the code works but that the linker is not setup right.
Would appreciate any help!
EDIT: Ok so I've tried the code in a different IDE and it worked. It's something to do with VS Code. Here is the error:
[Running] cd "c:\Users\<USER>\Desktop\Fan\" && g++ tempCodeRunnerFile.cpp -o tempCodeRunnerFile && "c:\Users\<USER>\Desktop\Fan\"tempCodeRunnerFile
C:\Users\<USER>\AppData\Local\Temp\cclMFKxO.o:tempCodeRunnerFile.cpp:(.text+0x57): undefined reference to `Fan::Fan()'
collect2.exe: error: ld returned 1 exit status
It sounds like the IDE is only compiling main.cpp. You need to find the command that is compiling main.cpp and ensure that it also compiles fan.cpp into fan.obj. You will also need to ensure that both main.obj and fan.obj are passed to the linker (which produces the executable program, main.exe or whatever).
There are two steps involved here:
cpp -> obj (compiling each source file into a matching object file)
obj -> exe (linking many object files into an executable)
I would say to make a CMakeLists.txt file and add main.cpp and fan.cpp into the add_executable section. Then VS can handle and run files through CMake.

How to properly include Armadillo in CLion (without having false errors)?

When I use the header-only Armadillo C++ library in CLion, the IDE indicates (highlights) multiple (false) errors in the code, however the usage of Armadillo is valid and the code builds and runs without any errors.
For example, in a very simple Armadillo test project, the IDE indicates 3 errors, as written in the comments:
#include <iostream>
#include "armadillo"
using namespace std;
using namespace arma;
int main() {
cout << "Armadillo version: " << arma_version::as_string() << endl;
// Returns 5.0.1 (Ankle Biter)
mat A(2,3); // Error: Too many arguments, expected 0
A.fill(99);
A(1,2) += 101.0; // Error: Called object is not a function
A.print("A = ");
A.set_size(4,5); // Error: Too many arguments, expected 1
A.fill(77);
A.print("A = ");
return 0;
}
Since Armadillo is header-only, I did not modify the default CMakeLists.txt file, only included the main header in main.cpp and copied armadillo_bits to the project directory.
I've tried to configure Armadillo with CMake, but on Windows it seems Armadillo's bundled CMakeLists.txt just copies the includes and creates a config.hpp in my working dir.
Is there a way to index symbols in header-only libraries?
CLion version is 1.0 (141.353), Armadillo version is 5.0.1.
My platform is Windows 8.1 x64, and I'm using MinGW v64 4.9.2 (x86_64-4.9.2-win32-seh-rt_v4-rev2)
The CLion project is available in this repository.
Thanks to anyone trying to investigate this issue.

Trouble linking/compiling Libcurl in Eclipse IDE C++ Project

Hi I am having trouble configuring an Eclipse C++ (32bit) project to use libcurl. I am using MinGW. I am on a 64bit windows OS. I have done the following so far:
Add "libcurl.lib" to the project's Libraries
Add the path of libcurl.lib to the Library Paths
Add the path to the curl header files to the Includes path
In source, I included "curl/curl.h"
However, I am seeing the following message:
Info: Internal Builder is used for build
g++ "-LC:\\projectsrc\\Network\\curl-7.34.0-win32\\lib" "-LC:\\projectsrc\\Network\\curl-7.34.0-win32\\dlls" "-LC:\\projectsrc\\Network\\curl-7.34.0-win32\\bin" -o TestLibCurl.exe "src\\TestLibCurl.o" "-lC:\\projectsrc\\Network\\curl-7.34.0-win32\\lib\\libcurl.lib"
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lC:\projectsrc\Network\curl-7.34.0-win32\lib\libcurl.lib
collect2.exe: error: ld returned 1 exit status
Below is the sample source
#include <stdio.h>
#include <curl/curl.h>
#include <curl/easy.h>
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
int main()
{
cout << "test" <<< endl;
return 0;
}
Below is a screenshot of where I added the include path and the library file:
For your reference, I have uploaded my sample C++ eclipse project to dropbox here:
https://www.dropbox.com/s/2jowlkz6qypqe9g/TestingLibCurl.zip
The project file includes main.cpp, the libcurl.lib file, the libcurl header files, and the eclipse project setting files (.cproject, .project, .settings)
Oddly, I am able to get this to work in CodeBlocks IDE, using the same MinGW and using the same computer (Windows 64 bit). Do I need to add linker/options/flags when using Eclipse IDE?

undefined reference to function code blocks

main.cpp
#include <iostream>
#include <string>
using namespace std;
void echo(string);
int main()
{
echo("hello");
cout << "Hello world!" << endl;
return 0;
}
print.cpp
#include <iostream>
#include <string>
void echo(string code){
cout << code;
}
After compiling the code in code blocks 12.11, it gives me that error:
undefined reference to `echo(std::string)
I use windows 7 x64.
I have added the directory; Project>build options > search directories and added the current working directory.
All the files are in one console project in code blocks
I believe you should read up a bit more on namespaces usage. You are missing std in print.cpp.
Generally, while starting to learn cpp or getting a grip of the language you should always try writing full names of the classes along with the namespaces. Eventually with practice and some oversights (like now) you will learn why you really need them. In a nutshell namespaces are great:
When you are writing code over multiple files
Compartmentalize your code into separate blocks.
Also, using namespace std; should be used within cpp files mostly (otherwise headers get mangled up.
Anyways, try changing your code to this:
#include <iostream>
#include <string>
void echo(std::string code){
std::cout << code;
}
Then your results will look like this:
> g++ main.cpp print.cpp -o a.out
> ./a.out
helloHello world!
You should get more than that linker error, since you use string without any namespace in your print.cpp file. And if that source file doesn't compile it can't be linked with, and you will get the linker error you have.
Change to e.g.
void echo(std::string code) { ... }
And you do try to link with the object file created from print.cpp ?
I know this is old, but for anyone looking to solve this issue, the following may be a solution for you. If you have g++ follow c++ 11 under project->build options (check your options anyway) then you must check that box for all files you make in the project for the error to be cleared up. I had that annoying undefined reference thing too but now it is gone!
Try "Project/Properties/Build Targets tab". There you should find "Build target files" field. In that filed find "print.cpp" and click the checkbox (now the compiler will build print.cpp).
Some usefull information on Project management in CB
http://www.codeblocks.org/docs/main_codeblocks_en.html
When dealing with strings in C++ its best to sue std::string and your code seems to be wrong with a changes like using std::cout instead of plain cout another thing you need to be careful is linking your files especially files in different directories you need to tell code blocks were to find this print.cpp by going to build option and go for the search tab directory and point to where print.cpp is other wise the other approach is to just build a project which will have the main.cpp and and then add print.cpp class to current project I hope this will be of some help

Need help in C++ with allegro library....?

I installed CodeBlocks 10.5 with minGW compiler. After setting environment variables for minGW I cheked gcc -v on cmd and it is working fine.
The problem is that, I have made a small program in CodeBlocks project the code is below
#include <iostream>
#include <allegro5/allegro.h>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
There is an error, the build log is:
Compiling: main.cpp
C:\Program Files\CodeBlocks\MinGW\bin\allegro_pract… error: allegro5/allegro.h: No such file or directory
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings
Directory structure for codeblocks is:
C:\Program Files\CodeBlocks
and for minGW:
C:\Program Files\CodeBlocks\mingw
and my project is:
C:\Program Files\CodeBlocks\bin\
i am confused about allegro library where to place it.. as I have not used any external library..
the library is placed now at:
C:\Program Files\CodeBlocks\mingw\allegro\
I am "Googling" for a long time but no tutorial seems to be working..
please give a valid solution.. and where to place allegro library..??
Do not try to "place" libraries in the "right place". Instead, tell the IDE where you put them explicitly. This is called setting the include path.
Code::Blocks should have some setting for include directories. You should point it to the place where Allegro lives.
Set up your IDE to look for Allegro:
(source: allegro.cc)
The complete tutorial is here:
http://wiki.allegro.cc/index.php?title=Windows,_Code::Blocks_10.05_and_Allegro_5
http://www.mingw.org/wiki/IncludePathHOWTO:
The actual search path, for any specific installation of MinGW may be determined, by running the compiler itself, with the "-v" option; typically, for a GCC-3.4.5 installation in c:/mingw:--
defaults appear to be:
c:/mingw/include/c++/3.4.5
c:/mingw/include/c++/3.4.5/mingw32
c:/mingw/include/c++/3.4.5/backward
c:/mingw/include
c:/mingw/lib/gcc/mingw32/3.4.5/include
I don't use mingw, so, read the link.