在FreeBSD上构建lxml示例时对glib的未定义引用

时间:2015-01-05 16:35:09

标签: c++ linker freebsd libxml2 glib

我试图在FreeBSD 10.1-RELEASE上从libxml ++构建示例代码,但是我在链接库时遇到undefined reference to Glib::...错误。 在CentOS 6.5和7.0上编译时没有错误。 启用链接器详细模式时,似乎找到了所有glib库。 我尝试重新安装glib库几次,但没有任何改变。

有关编译失败的建议吗?

下面的源代码和makefile。

main.cc:

#include <libxml++/libxml++.h>

#include <iostream>

void print_indentation(unsigned int indentation) {
        for (unsigned int i = 0; i < indentation; ++i)
                std::cout << " ";
}

void print_node(const xmlpp::Node* node, unsigned int indentation = 0) {
        std::cout << std::endl; //Separate nodes by an empty line.

        const xmlpp::ContentNode* nodeContent = dynamic_cast<const xmlpp::ContentNode*>(node);
        const xmlpp::TextNode* nodeText = dynamic_cast<const xmlpp::TextNode*>(node);
        const xmlpp::CommentNode* nodeComment = dynamic_cast<const xmlpp::CommentNode*>(node);

        if (nodeText && nodeText->is_white_space()) //Let's ignore the indenting - you don't always want to do this.
                return;

        Glib::ustring nodename = node->get_name();

        if (!nodeText && !nodeComment && !nodename.empty()) //Let's not say "name: text".
        {
                print_indentation(indentation);
                std::cout << "Node name = " << node->get_name() << std::endl;
                std::cout << "Node name = " << nodename << std::endl;
        } else if (nodeText) //Let's say when it's text. - e.g. let's say what that white space is.
        {
                print_indentation(indentation);
                std::cout << "Text Node" << std::endl;
        }

        //Treat the various node types differently: 
        if (nodeText) {
                print_indentation(indentation);
                std::cout << "text = \"" << nodeText->get_content() << "\"" << std::endl;
        } else if (nodeComment) {
                print_indentation(indentation);
                std::cout << "comment = " << nodeComment->get_content() << std::endl;
        } else if (nodeContent) {
                print_indentation(indentation);
                std::cout << "content = " << nodeContent->get_content() << std::endl;
        } else if (const xmlpp::Element* nodeElement = dynamic_cast<const xmlpp::Element*>(node)) {
                //A normal Element node:

                //line() works only for ElementNodes.
                print_indentation(indentation);
                std::cout << "     line = " << node->get_line() << std::endl;

                //Print attributes:
                const xmlpp::Element::AttributeList& attributes = nodeElement->get_attributes();
                for (xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter) {
                        const xmlpp::Attribute* attribute = *iter;
                        print_indentation(indentation);
                        std::cout << "  Attribute " << attribute->get_name() << " = " << attribute->get_value() << std::endl;
                }

                const xmlpp::Attribute* attribute = nodeElement->get_attribute("title");
                if (attribute) {
                        std::cout << "title found: =" << attribute->get_value() << std::endl;

                }
        }

        if (!nodeContent) {
                //Recurse through child nodes:
                xmlpp::Node::NodeList list = node->get_children();
                for (xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter) {
                        print_node(*iter, indentation + 2); //recursive
                }
        }
}

int main(int argc, char* argv[]) {
        std::string filepath;
        if (argc > 1)
                filepath = argv[1]; //Allow the user to specify a different XML file to parse.
        else
                filepath = "example.xml";

        try {
                xmlpp::DomParser parser;
                parser.set_validate();
                parser.set_substitute_entities(); //We just want the text to be resolved/unescaped automatically.
                parser.parse_file(filepath);
                if (parser) {
                        //Walk the tree:
                        const xmlpp::Node* pNode = parser.get_document()->get_root_node(); //deleted by DomParser.
                        print_node(pNode);
                }
        } catch (const std::exception& ex) {
                std::cout << "Exception caught: " << ex.what() << std::endl;
        }

        return 0;
}

生成文件:

OBJDIR=.obj

OBJS_MAIN = $(OBJDIR)/main.o

OBJS_ALL = $(OBJS_MAIN)

default: ao3

CC = g++48

#CENTOS_VERSION=$(shell sed 's/[^0-9]*\([0-9]*\)\.\([0-9]\).*/\1\2/' < /etc/redhat-release )
CENTOS_VERSION=70
CFLAGS_GS = -DWITH_OPENSSL -DWITH_GZIP -DWITH_CDATA -D CENTOS_VERSION=$(CENTOS_VERSION) -pthread

#  -Wl,--verbose 
OFLAGS= \
  -Wl,--verbose \
  -L/usr/local/lib \
  -L "/usr/lib64/mysql" \
  -L "/usr/lib/mysql" \
  -L "/usr/local/lib/mysql" \
  -L "/usr/lib64" \
  -L "/usr/lib" \
  -L "/usr/share/axiscpp/lib" \
  -L "/usr/local/axis/lib" \
  -L "/usr/local/lib/amadeus_2_1_39_5" \
  -lboost_iostreams \
  -lboost_date_time \
  -lmysqlclient \
  -lxml++-2.6 \
  -lxml2 \
  -lglibmm-2.4 \
  -lgobject-2.0 \
  -lgmodule-2.0 \
  -lglib-2.0 \
  -lloki \
  -liconv\
  -lpcre \
  -lsigc-2.0 \
  -lSockets \
  -lssl \
  -lintl \
  -lffi \
  -llzma \
  -lpthread \
  -lexpat \
  -lbz2 \
  -lglib \
  -lz \
  -luuid \
  -lthr \
  -lc++ \
  -lm \
  -lcxxrt \
  -lgcc_s \
  -lc

ifeq ($(CENTOS_VERSION),65)
OFLAGS += -lboost_system
endif

ifeq ($(CENTOS_VERSION),70)
OFLAGS += -lboost_system
OFLAGS += -lcrypto
OFLAGS += -lboost_filesystem
endif

EXTCFLAGS := -g

LDFLAGS= -L/usr/local/lib

#  -Weffc++ 
CFLAGS= $(EXTCFLAGS) \
  -Wall \
  -Werror \
  -Wextra \
  -D LARGEFILE64_SOURCE \
  -D FILE_OFFSET_BITS=64 \
  -D _UP_UNIX_ \
  -D CNT_VERSION=2_3 \
  -D LOKI_OBJECT_LEVEL_THREADING \
  -D CENTOS_VERSION=$(CENTOS_VERSION) \
  -isystem"/usr/include/" \
  -isystem"/usr/local/include/" \
  -isystem"/usr/include/libxml++-2.6" \
  -isystem"/usr/local/include/libxml++-2.6" \
  -isystem"/usr/local/include/libxml++-2.6/include" \
  -isystem"/usr/lib/libxml++-2.6/include" \
  -isystem"/usr/local/lib/libxml++-2.6/include" \
  -isystem"/usr/lib64/libxml++-2.6/include" \
  -isystem"/usr/include/glibmm-2.4" \
  -isystem"/usr/local/include/glibmm-2.4" \
  -isystem"/usr/lib/glibmm-2.4/include" \
  -isystem"/usr/local/lib/glibmm-2.4/include" \
  -isystem"/usr/lib64/glibmm-2.4/include" \
  -isystem"/usr/local/include/glib-2.0/" \
  -isystem"/usr/include/glib-2.0/" \
  -isystem"/usr/lib/glib-2.0/include" \
  -isystem"/usr/local/lib/glib-2.0/include" \
  -isystem"/usr/lib64/glib-2.0/include" \
  -isystem"/usr/lib/glib/include" \
  -isystem"/usr/lib64/glib/include" \
  -isystem"/usr/local/include/glib-1.2" \
  -isystem"/usr/include/mysql" \
  -isystem"/usr/local/include/mysql"

$(OBJDIR)/%.o: %.cc
        @mkdir -p $(@D)
        $(CC) -MMD -MP -c $(CFLAGS) $(INCLUDE) -o $@   $<
        @echo -n '.' >>  "$(DOTSFILE)"
        @curr=`wc -c < $(DOTSFILE)`; max=`cat $(MAXFILE)`; echo -e "\033[1m$$curr/$$max\033[0m"

$(OBJDIR)/main.o: main.cc
        @mkdir -p $(OBJDIR)
        $(CC) -MMD -MP -c $(CFLAGS) $(INCLUDE) -o $@   $<

-include $(OBJS_ALL:.o=.d)

DOTSFILE := /dev/null
MAXFILE := /dev/null

help:
        @echo 'ao3, test, profile, clean, cleantest, cleanprofile'
        @echo 'CentOS version: '$(CENTOS_VERSION)

ao3: $(OBJS_ALL)
        $(CC) --verbose -o ao3 -Wl,--start-group $(OBJS_ALL) $(OFLAGS) -Wl,--end-group

test: $(OBJS_TEST_ALL)
        $(CC) -o ao3_test $(OBJS_TEST_ALL) $(OFLAGS)

profile: $(OBJS_PROFILE_ALL)
        $(CC) -o ao3_profile $(OBJS_PROFILE_ALL) $(OFLAGS)

clean:
        rm -f $(wildcard $(OBJS_ALL) ao3 $(OBJS_ALL:.o=.d))
        find $(OBJDIR) -type d -empty -delete

cleantest:
        rm -f $(wildcard $(OBJS_TEST) ao3_test $(OBJS_TEST:.o=.d))
        find $(OBJDIR) -type d -empty -delete

cleanprofile:
        rm -f $(wildcard $(OBJS_PROFILE) ao3_profile $(OBJS_PROFILE:.o=.d))
        find $(OBJDIR) -type d -empty -delete

1 个答案:

答案 0 :(得分:1)

所以问题是glibmm是由clang编译的,而我正在使用gcc进行编译。当使用c ++而不是g ++ 48进行编译时,它可以正常工作。