在 FreeBSD 上构建 lixml++ 示例时对 glib 的未定义引用
Undefined refference to glib when building lixml++ example on FreeBSD
我正在尝试在 FreeBSD 10.1-RELEASE 上从 libxml++ 构建示例代码, 但是在链接库时遇到undefined reference to Glib::...
错误。在 CentOS 6.5 和 7.0 上,代码编译没有错误。启用链接器详细模式时,似乎找到了所有 glib 库。我尝试重新安装 glib 库几次,但没有任何变化。
任何建议为什么编译失败?
源代码和生成文件如下。
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]).*/12/' < /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 " 33[1m$$curr/$$max 33[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
所以问题是 glibmm 是由 clang 编译的,我正在使用 gcc 进行编译。当使用 c++ 而不是 g++48 进行编译时,它可以正常工作。
相关文章:
- 编译C++时未定义的引用
- vscode g++链路故障:体系结构x86_64的未定义符号
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 不知道某个东西是否被忽略会引入未定义的行为吗
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 未定义的引用在哪里
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- c++11评估顺序(未定义的行为)
- 使用mysql c++连接器的未定义引用
- 从python调用openMP共享库时,未定义opnMP函数
- 在 Mac 上使用 CMAKE 将 FFTW 和 FFTWPP 链接到项目中时未定义的符号
- Cmake 链接问题:未定义对 Button::mousePressEvent(QGraphicsSceneMouseE
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 具有外部"c"和程序集的未定义函数
- 此增量后语句是否会导致未定义的行为?
- 尝试调用 .h 文件中定义的变量时出现变量未定义错误
- 在C++中使用内联方法时出现未定义的符号错误
- 在 FreeBSD 上构建 lixml++ 示例时对 glib 的未定义引用