Reputation: 165
I am completely new to C++ and am working on a piece of code that will be inserted into a larger program. The piece of code will use the xercesc library to read an XML file. I wrote a very basic main function to test things out. But I cannot get it compiled. Help will be much appreciated.
Test1.cpp
#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMNodeList.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <string>
#include <iostream>
#include <map>
using namespace std;
using namespace xercesc;
int main() {
string scRes = "scRes.xml";
XercesDOMParser* parser = new XercesDOMParser;
parser->parse(scRes.c_str());
DOMNodeList* nodeList = parser->getDocument()->getDocumentElement()->getChildNodes();
DOMNode* root = nodeList->item(0);
std::cout << root->getNodeName() << endl;
for (unsigned int i = 0; i < nodeList->getLength(); i++) {
DOMNode* curr = root->getChildNodes()->item(i);
std::cout << curr << endl;
}
}
My Makefile is like:
CXX = g++
LIBDIR = -L/usr/local/lib -L$(XERCES_LIB) -L$(PWD)
ROOT = $(PROJDIR)
XERCES_INCLUDE = $(ROOT)/libs/xercesc/include
XERCES_LIB = $(ROOT)/libs/xercesc/lib
INCLUDE = -I$(XERCES_INCLUDE) -I${HOME}/include
CXXFLAGS = $(INCLUDE) -MMD -std=c++14 -Wno-deprecated
LDFLAGS = $(LIBDIR) -Wl,-rpath,$(XERCES_LIB)
LDLIBS = -lxerces-c -lm -Wl,-rpath
AR = ar ru
all: Test1
Test1: Test1.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $^
Test1.o: Test1.cpp
$(CXX) -c $(CXXFLAGS) $^
clean:
rm *.d *.o
If I type make, I receive the following errors.
/bin/ld: warning: libicui18n.so.68, needed by /some/server/dir/libs/xercesc/lib/libxerces-c.so, not found (try using -rpath or -rpath-link)
/bin/ld: warning: libicudata.so.68, needed by /some/server/dir/libs/xercesc/lib/libxerces-c.so, not found (try using -rpath or -rpath-link)
/lib/../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
/some/server/dir/libs/xercesc/lib/libxerces-c.so: undefined reference to `uset_setSerializedToOne_68'/bin/ld: warning: libicuuc.so.68, needed by /some/server/dir/libs/xercesc/lib/libxerces-c.so, not found (try using -rpath or -rpath-link)
Upvotes: 1
Views: 916
Reputation: 165
As Frank commented, I did not realize it is necessary to include the ICU library in the Makefile. I also made a few other mistakes in the Makefile, so I will post the now-working version here for other people's reference.
CXX = g++
LIBDIR = -L/usr/local/lib -L$(XERCES_LIB) -L$(ICU_LIB)
ROOT = $(PROJDIR)
XERCES_INCLUDE = $(ROOT)/libs/xercesc/include
XERCES_LIB = $(ROOT)/libs/xercesc/lib
ICU_INCLUDE = $(ROOT)/libs/icu/include/unicode
ICU_LIB = $(ROOT)/libs/icu/lib
INCLUDE = -I${HOME}/include -I$(XERCES_INCLUDE) -I$(ICU_INCLUDE)
CXXFLAGS = $(INCLUDE) -MMD -std=c++14 -Wno-deprecated -Wall
LDFLAGS = $(LIBDIR) -Wl,-rpath,$(ICU_LIB) -Wl,-rpath,$(XERCES_LIB)
LDLIBS = -lxerces-c -lm
AR = ar ru
all: Test1
Test1: main.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $<
main.o: main.cpp
$(CXX) $(CXXFLAGS) -c $<
clean:
rm *.d *.o
Upvotes: 2