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:
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
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:
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:
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;
}