Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
playing with poppler how to link c++?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
turtles
Veteran
Veteran


Joined: 31 Dec 2004
Posts: 1658

PostPosted: Wed Mar 27, 2024 8:20 pm    Post subject: playing with poppler how to link c++? Reply with quote

Greeting fellow Gentoo's
I am messing around with poppler and learning some c++, just a experimental project
I have a small bit of c++ that I call get-txt that begins like so:
Code:
 
#include <iostream>
#include <algorithm>
#include <poppler-document.h>
#include <poppler-page.h>

using namespace std;

Now I can make a object file with:

Code:
g++ -I/usr/include/poppler/cpp/ -c get-txt.cpp


But for the last part I think I need .a files:
libpoppler-cpp.a
libpoppler.a
liblcms2.so
libfontconfig.a
libjpeg.a
libfreetype.a
libexpat.a
libz.a

On my Gentoo system I have some similar .so files under /usr/lib64/ is there a good way to use these files off my system in my project?
Thanks in advance
_________________
Donate to Gentoo
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 1660

PostPosted: Wed Mar 27, 2024 8:27 pm    Post subject: Reply with quote

Use the -l option. e.g. -lpoppler for libpoppler.so

If a package has a pkgconfig file (.pc), try use pkgconfig with the --libs options when possible.
Back to top
View user's profile Send private message
turtles
Veteran
Veteran


Joined: 31 Dec 2004
Posts: 1658

PostPosted: Wed Mar 27, 2024 8:58 pm    Post subject: Reply with quote

Ok thanks

this runs fine:
Code:
g++ -I/usr/include/poppler/cpp/ -c src/get-txt.cpp -o build/get-txt.o

when i run this
Code:
g++ -lpoppler build/get-txt.o -o build/get-txt

I get
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: build/get-txt.o: in function `main':
get-txt.cpp:(.text+0x23e): undefined reference to `poppler::document::load_from_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: get-txt.cpp:(.text+0x287): undefined reference to `poppler::document::pages() const'
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: get-txt.cpp:(.text+0x2f1): undefined reference to `poppler::document::create_page(int) const'
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: get-txt.cpp:(.text+0x319): undefined reference to `poppler::page::text(poppler::rectangle<double> const&) const'
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: get-txt.cpp:(.text+0x32c): undefined reference to `poppler::ustring::to_latin1[abi:cxx11]() const'
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: get-txt.cpp:(.text+0x374): undefined reference to `poppler::ustring::~ustring()'
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: get-txt.cpp:(.text+0x48c): undefined reference to `poppler::ustring::~ustring()'
collect2: error: ld returned 1 exit status

My entire c++ file is here:
https://pastebin.com/r61ugdC1
Its not much

Its not part of a package or anything I am just mucking around learning c++
_________________
Donate to Gentoo
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21637

PostPosted: Wed Mar 27, 2024 9:13 pm    Post subject: Reply with quote

That looks expected. First g++ searches libpoppler.so for symbols to satisfy undefined references. It has no undefined references, so it doesn't pull anything from libpoppler.so. Then it processes your .o file, which adds new undefined references. You never go back to libpoppler.so, so they remain undefined. To solve this, put -lpoppler in the standard position for LINKFLAGS, at the end of the line, not the standard position of LDFLAGS, the start of the line.
Back to top
View user's profile Send private message
turtles
Veteran
Veteran


Joined: 31 Dec 2004
Posts: 1658

PostPosted: Wed Mar 27, 2024 9:23 pm    Post subject: Reply with quote

Hu wrote:
That looks expected. First g++ searches libpoppler.so for symbols to satisfy undefined references. It has no undefined references, so it doesn't pull anything from libpoppler.so. Then it processes your .o file, which adds new undefined references. You never go back to libpoppler.so, so they remain undefined. To solve this, put -lpoppler in the standard position for LINKFLAGS, at the end of the line, not the standard position of LDFLAGS, the start of the line.


Thanks Hu!
Do you mean like this?
Code:
g++ build/get-txt.o -lpoppler -o build/get-txt

I get the same error also.
_________________
Donate to Gentoo
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21637

PostPosted: Wed Mar 27, 2024 10:48 pm    Post subject: Reply with quote

That is the correct position, yes. You also need to use the correct library, though. Your original message did not state what symbols you need, so grknight pointed you to the main library. On review of your current error, it seems like you need to link to a different library. Based on a dump of the symbols offered by each of the poppler libraries, I think you need poppler-cpp. The poppler documentation may be worth checking on this point.
Back to top
View user's profile Send private message
turtles
Veteran
Veteran


Joined: 31 Dec 2004
Posts: 1658

PostPosted: Thu Mar 28, 2024 12:06 am    Post subject: Reply with quote

Ahh duh of course my list of .a files needs to be all in there:
Code:
g++ -lpoppler -lpoppler-cpp -llcms2 -lfontconfig -ljpeg -lfreetype -lexpatw -lz build/get-txt.o -o build/get-txt


grknight hu thank you both, my program works!

If I was going to make a CMakeLists.txt would I just put them all on a line like so
Code:
add_library(poppler poppler-cpp lcms2 fontconfig jpeg freetype expatw z)

?
_________________
Donate to Gentoo
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum