Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

TangoOversway

macrumors newbie
Original poster
Mar 6, 2013
4
0
While I've worked with a number of different languages and even used assembler back when 8 bit machines were all around, I'm new to C++. I've run into something that is way beyond my depth for someone just starting to deal with issues like linking and 64 bit vs. 32 bit binaries and so on.

I'm using an iMac running Mountain Lion (10.8.2). I'm using Eclipse as an IDE (let's leave it at that and not discuss changing the IDE if possible) and it's V. 4.2.1. The version string from gcc is this:

Code:
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I'm compiling a simple program. I'm still getting used to C++ and the syntax and all the features I haven't dealt with in Perl or Java. I'm using Poppler, a library to work with PDF files. I believe the library is in C, but the includes are in a folder named cpp. The code for the program is below. (Please - if there's other errors, don't warn me - let me find them and debug them on my own - I'll learn and remember more that way.)

The Poppler includes are in /usr/local/includes and the library files are in /usr/local/lib. When I try to build the program in Eclipse, I am getting this error:

make all
Building file: ../hReaderControl.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"hReaderControl.d" -MT"hReaderControl.d" -o "hReaderControl.o" "../hReaderControl.cpp"
Finished building: ../hReaderControl.cpp

Code:
Building target: TestReaderControl
Invoking: MacOS X C++ Linker
g++  -o "TestReaderControl"  ./tReaderControl.o   
Undefined symbols for architecture x86_64:
  "poppler::document::load_from_file(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char,
  std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)",
  referenced from:
      addPDFs(std::list<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char,
      std::char_traits<char>, std::allocator<char> > > >)in hReaderControl.o
  "poppler::document::pages() const", referenced from:
      addPDFs(std::list<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char,
      std::char_traits<char>, std::allocator<char> > > >)in hReaderControl.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [TestReaderControl] Error 1

I've noticed this error has been discussed multiple times on this forum, but, in most cases, the answer is specific to the situation. But I have noticed that several times the issue has been that the library binaries might be 32 bit instad of 64 bit. I ran file on the Poppler library files. Here is the output:

Code:
lib/libpoppler-cpp.0.dylib: Mach-O 64-bit dynamically linked shared library x86_64
lib/libpoppler-cpp.a:       current ar archive random library
lib/libpoppler-cpp.dylib:   Mach-O 64-bit dynamically linked shared library x86_64
lib/libpoppler-cpp.la:      libtool library file
lib/libpoppler.34.dylib:    Mach-O 64-bit dynamically linked shared library x86_64
lib/libpoppler.a:           current ar archive random library
lib/libpoppler.dylib:       Mach-O 64-bit dynamically linked shared library x86_64
lib/libpoppler.la:          libtool library file

While this is all new to me, from what I've seen elsewhere, and from the X86_64, I figure these are clearly 64 bit files. (I built the library on my iMac with ./configure && make && sudo make install.)

The other issue has been the routine not being in the compiled code, but as best I can tell, both missing routines are in there, so that makes me think that the compiler and/or linker is having a problem finding the needed files. As I said, the headers are in /usr/local/includes - and Eclipse finds them there automatically. The libs - all for those to match headers in /usr/lcoal/includes - are all in /usr/local/lib. But I'm still getting used to Eclipse and building C++ programs and make files, so it's quite possible I am missing a setting.

Any ideas what I'm doing wrong or what's causing the error?

Here's the program code:

Code:
#include <iostream>
#include <list>
#include "poppler/cpp/poppler-document.h"
using namespace std;


void addPDFs(list<string> fList) {

	list<string>::iterator iList;
	int x = 1;
	int pNum = -1;
	for (iList = fList.begin(); iList != fList.end(); iList++) {
		poppler::document* pDoc = poppler::document::load_from_file(*iList);
		pNum = pDoc->pages();
		cout << "Item : " << x << " : " << *iList << ", Total Pages: " << pNum << endl;
	}
}

int main(int argc, char* argv[]) {
	list<string> inFiles;
	int i;
	cout << "Command given: " << argv[0] << endl << endl;
	for (i = 1; i < argc; i++) {
		cout << "Adding argument " << i << ": " << argv[i] << endl;
		inFiles.push_back(argv[i]);
	}
	cout << "-----------------------------" << endl << endl;
	addPDFs(inFiles);
	return 0;
}
 

jhiesey

macrumors newbie
Mar 6, 2013
17
16
From the g++ command you posted it looks like the compiler is never being told to link against libpoppler, even though Eclipse automatically found the header files.

I've never used Eclipse for c/c++ development, but somehow you need to make sure something like

-llpoppler-cpp

gets added to the g++ command line. I'm also not sure what the default library search path on the mac is set to, so you might also need to put the path first, i.e.

-L/usr/local/lib -llpoppler-cpp

Hope that helps.
 

TangoOversway

macrumors newbie
Original poster
Mar 6, 2013
4
0
Actually, that's a big help. It points me where to go and it makes sense. I don't know if it's a search path for OS X or if it's setting that up in the CDT in Eclipse, but that would explain it.

I'll see what I can find and give an update when I find out how well it's working.
 

TangoOversway

macrumors newbie
Original poster
Mar 6, 2013
4
0
I got it to work.

I right clicked on the project and picked "Properties." Then I clicked on the C/C++ Build item in the list of settings and that opened up to provide more topics or panel names. Under C/C++ Build, I picked "Settings."

In my case, it did not list a linker other than MacOS X C++ Linker, so that made the choice easy. (I'm going to have to look at that and add one for GCC that I can use when I am on a different platform - for continuity.)

Then, in the top area to the right, where the title was "Libraries (-l)" I clicked the add button and added "poppler-cpp" and saved that. Backed out of the preferences panel and built the project and it worked perfectly. I ran it and got the filenames, as expected, and it gave me the correct number of pages - telling me that it was using Poppler and opening each PDF file and checking the total number of pages. (My way to confirm I had Poppler working and was actually opening the PDF files and referencing them quickly.)

Thank you.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.