尝试构建xerces c ++解析器。 Netbeans和命令行构建错误未定义对xercesc_3_2…的引用

问题描述 投票:0回答:1

我正在尝试在基于Linux RedHat构建的NetBeans项目中Xerces c ++解析器库。

我遵循了构建指南(https://xerces.apache.org/xerces-c/build-3.html#UNIX

1)下载tar.gz“ xerces-c-3.2.2.tar.gz”

2)使用“ tar xvzf”作为xerces-c-3.2.2提取到tar用户my / home / myuser / projects

3)导航到/ home / myuser / projects / xerces-c-3.2.2并在Linux上的命令行中发布

./ configure --disable-shared --disable-static

有很多输出,但没有错误,下一个:

4)我在同一目录中运行了[[make]。创建了许多.o和.lo文件...

输出是这样的:

CXX src/SEnumVal/SEnumVal.o CXXLD SEnumVal CXX src/StdInParse/StdInParse.o CXX src/StdInParse/StdInParseHandlers.o CXXLD StdInParse CXX src/XInclude/XInclude.o CXXLD XInclude make[2]: Leaving directory `/home/myUser/projects/xerces-c-3.2.2/samples' make[2]: Entering directory `/home/myUser/projects/xerces-c-3.2.2' make[2]: Leaving directory `/home/myUser/projects/xerces-c-3.2.2' make[1]: Leaving directory `/home/myUser/projects/xerces-c-3.2.2'

没有错误,下一个:

5)cd / src和ls -a显示已建立.libs目录。

进入/home/myUser/projects/xerces-c-3.2.2/src/.libs的CD显示:

libxerces-c.a libxerces-c.la libxerces-c.lai

6)根据编程指南(http://xerces.apache.org/xerces-c/program-3.html),尝试运行示例代码:

#include <xercesc/util/PlatformUtils.hpp> // Other include files, declarations, and non-Xerces-C++ initializations. using namespace xercesc; int main(int argc, char* argv[]) { try { XMLPlatformUtils::Initialize(); } catch (const XMLException& toCatch) { // Do your failure processing here return 1; } // Do your actual work with Xerces-C++ here. XMLPlatformUtils::Terminate(); // Other terminations and cleanup. return 0; }

在按下项目属性之前,c ++编译器,包括目录并添加了以下路径

1)../../ projects / xerces-c-3.2.2 / src / xercesc

2)../../ projects / xerces-c-3.2.2 / src

3)../../ projects / xerces-c-3.2.2 / src / .libs

并包含标题的路径:

1)../../ projects / xerces-c-3.2.2 / src / xercesc / util / PlatformUtils.hpp

2)../../ projects / xerces-c-3.2.2 / src / xercesc / util / XMLUni.hpp

3)../../ projects / xerces-c-3.2.2 / src / xercesc / util / XMLException.hpp

我也转到项目属性,链接器并添加了“其他库目录”和“运行时搜索目录”

1)../../ projects / xerces-c-3.2.2 / src / xercesc

2)../../ projects / xerces-c-3.2.2 / src

3)../../ projects / xerces-c-3.2.2 / src / .libs

最后我按下了NetBeans的clean&build,报告了编译器命令和错误:

cd '/home/myUser/NetBeansProjects/SOFF_test' /usr/bin/gmake -f Makefile CONF=Debug clean "/usr/bin/gmake" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf gmake[1]: Entering directory `/home/myUser/NetBeansProjects/SOFF_test' rm -f -r build/Debug gmake[1]: Leaving directory `/home/myUser/NetBeansProjects/SOFF_test' CLEAN SUCCESSFUL (total time: 209ms) cd '/home/myUser/NetBeansProjects/SOFF_test' /usr/bin/gmake -f Makefile CONF=Debug "/usr/bin/gmake" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf gmake[1]: Entering directory `/home/myUser/NetBeansProjects/SOFF_test' "/usr/bin/gmake" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/soff_test gmake[2]: Entering directory `/home/myUser/NetBeansProjects/SOFF_test' mkdir -p build/Debug/GNU-Linux rm -f "build/Debug/GNU-Linux/newmain.o.d" g++ -c -g -I../../projects/xerces-c-3.2.2/src/xercesc -I../../projects/xerces-c-3.2.2/src -include ../../projects/xerces-c-3.2.2/src/xercesc/util/PlatformUtils.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/util/XMLUni.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/util/XMLException.hpp -MMD -MP -MF "build/Debug/GNU-Linux/newmain.o.d" -o build/Debug/GNU-Linux/newmain.o newmain.cpp mkdir -p dist/Debug/GNU-Linux g++ -o dist/Debug/GNU-Linux/soff_test build/Debug/GNU-Linux/newmain.o -L../../projects/xerces-c-3.2.2/src/ -L../../projects/xerces-c-3.2.2/src/xercesc/ -L../../projects/xerces-c-3.2.2/src/.libs -Wl,-rpath,'../../projects/xerces-c-3.2.2/src/' -Wl,-rpath,'../../projects/xerces-c-3.2.2/src/xercesc/util/' build/Debug/GNU-Linux/newmain.o: In function `main': /home/myUser/NetBeansProjects/SOFF_test/newmain.cpp:26: undefined reference to `xercesc_3_2::XMLUni::fgXercescDefaultLocale' /home/myUser/NetBeansProjects/SOFF_test/newmain.cpp:26: undefined reference to `xercesc_3_2::XMLPlatformUtils::Initialize(char const*, char const*, xercesc_3_2::PanicHandler*, xercesc_3_2::MemoryManager*)' /home/myUser/NetBeansProjects/SOFF_test/newmain.cpp:36: undefined reference to `xercesc_3_2::XMLPlatformUtils::Terminate()' build/Debug/GNU-Linux/newmain.o:(.gcc_except_table+0x10): undefined reference to `typeinfo for xercesc_3_2::XMLException' collect2: error: ld returned 1 exit status gmake[2]: *** [dist/Debug/GNU-Linux/soff_test] Error 1 gmake[2]: Leaving directory `/home/myUser/NetBeansProjects/SOFF_test' gmake[1]: *** [.build-conf] Error 2 gmake[1]: Leaving directory `/home/myUser/NetBeansProjects/SOFF_test' gmake: *** [.build-impl] Error 2 BUILD FAILED (exit value 2, total time: 456ms)

如果您参考g ++编译命令:

g++ -c -g -I../../projects/xerces-c-3.2.2/src/xercesc -I../../projects/xerces-c-3.2.2/src -include ../../projects/xerces-c-3.2.2/src/xercesc/util/PlatformUtils.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/util/XMLUni.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/util/XMLException.hpp -MMD -MP -MF "build/Debug/GNU-Linux/newmain.o.d" -o build/Debug/GNU-Linux/newmain.o newmain.cpp g++ -o dist/Debug/GNU-Linux/soff_test build/Debug/GNU-Linux/newmain.o -L../../projects/xerces-c-3.2.2/src/ -L../../projects/xerces-c-3.2.2/src/xercesc/ -L../../projects/xerces-c-3.2.2/src/.libs -Wl,-rpath,'../../projects/xerces-c-3.2.2/src/' -Wl,-rpath,'../../projects/xerces-c-3.2.2/src/xercesc/util/' build/Debug/GNU-Linux/newmain.o:

您可以看到包含代码示例的标题:

-include ../../projects/xerces-c-3.2.2/src/xercesc/util/PlatformUtils.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/util/XMLUni.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/util/XMLException.hpp

还为链接程序提供了.libs&src(可能不是必需的)文件夹

-L../../projects/xerces-c-3.2.2/src/ -L../../projects/xerces-c-3.2.2/src/xercesc/ -L../../projects/xerces-c-3.2.2/src/.libs
NetBeans能够看到#include <xercesc/util/PlatformUtils.hpp>&我什至可以单击进入xerces PlatformUtils.hpp并通过IDE来查看函数实现。 

1)为什么即使IDE可以解析标头,NetBeans也无法编译和查找Xerces库?

2)最终,如何解决此问题? (我的包含正确吗?)

更新:

上面提到的原始错误“未定义引用”根据用户“ jww”的建议得到解决,请参见注释。

1)I ch

将#include更改为#include“ xercesc / util / PlatformUtils.hpp”2)还通过“项目属性”,“链接器,库”菜单添加了libxerces-c.a。

这些是NetBeans生成的更新的构建命令:

g++ -c -g -I../../projects/xerces-c-3.2.2/src/xercesc -I../../projects/xerces-c-3.2.2/src -I../../projects/xerces-c-3.2.2/src/.libs -include ../../projects/xerces-c-3.2.2/src/xercesc/util/PlatformUtils.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/util/XMLUni.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/util/XMLException.hpp -MMD -MP -MF "build/Debug/GNU-Linux/newmain.o.d" -o build/Debug/GNU-Linux/newmain.o newmain.cpp mkdir -p dist/Debug/GNU-Linux g++ -o dist/Debug/GNU-Linux/soff_test build/Debug/GNU-Linux/newmain.o -L../../projects/xerces-c-3.2.2/src/ -L../../projects/xerces-c-3.2.2/src/xercesc/ -L../../projects/xerces-c-3.2.2/src/.libs -Wl,-rpath,'../../projects/xerces-c-3.2.2/src/.libs' -Wl,-rpath,'../../projects/xerces-c-3.2.2/src' -Wl,-rpath,'../../projects/xerces-c-3.2.2/src/xercesc' -lxerces-c

您可以看到已添加-lxerces-c标志。

现在我自然有新错误,这些错误与示例代码无关,但是深入到xerces库代码中,它们又具有“未定义引用”的性质。

See below: /home/anaim/projects/xerces-c-3.2.2/src/xercesc/util/NetAccessors/Curl/CurlNetAccessor.cpp:70: undefined reference to `curl_global_init' /home/anaim/projects/xerces-c-3.2.2/src/xercesc/util/NetAccessors/Curl/CurlNetAccessor.cpp:70: undefined reference to `curl_global_init' ../../projects/xerces-c-3.2.2/src/.libs/libxerces-c.a(CurlNetAccessor.o): In function `xercesc_3_2::CurlNetAccessor::cleanupCurl()': /home/anaim/projects/xerces-c-3.2.2/src/xercesc/util/NetAccessors/Curl/CurlNetAccessor.cpp:78: undefined reference to `curl_global_cleanup' ../../projects/xerces-c-3.2.2/src/.libs/libxerces-c.a(CurlURLInputStream.o): In function `xercesc_3_2::CurlURLInputStream::readMore(int*)': /home/anaim/projects/xerces-c-3.2.2/src/xercesc/util/NetAccessors/Curl/CurlURLInputStream.cpp:269: undefined reference to `curl_multi_perform' Etc, etc...

我也通过添加-lcurl和-lpthread解决了上述错误以及更多问题>>

这是最新的编译命令(再次生成其NetBeans)

g++ -c -g -I../../projects/xerces-c-3.2.2/src/xercesc -I../../projects/xerces-c-3.2.2/src -include ../../projects/xerces-c-3.2.2/src/xercesc/util/PlatformUtils.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/util/XMLUni.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/util/XMLException.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/util/NetAccessors/Curl/CurlNetAccessor.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/util/NetAccessors/Curl/CurlURLInputStream.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/util/Transcoders/ICU/ICUTransService.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/xinclude/XIncludeDOMDocumentProcessor.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/xinclude/XIncludeLocation.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/xinclude/XIncludeUtils.hpp -MMD -MP -MF "build/Debug/GNU-Linux/newmain.o.d" -o build/Debug/GNU-Linux/newmain.o newmain.cpp mkdir -p dist/Debug/GNU-Linux g++ -o dist/Debug/GNU-Linux/soff_test build/Debug/GNU-Linux/newmain.o -L../../projects/xerces-c-3.2.2/src/ -L../../projects/xerces-c-3.2.2/src/xercesc/ -L../../projects/xerces-c-3.2.2/src/.libs -Wl,-rpath,'../../projects/xerces-c-3.2.2/src' -Wl,-rpath,'../../projects/xerces-c-3.2.2/src/xercesc' -Wl,-rpath,'../../projects/xerces-c-3.2.2/src/.libs' -lxerces-c -lcurl -lpthread

新错误:

再次获得“未定义的引用”:

../../ projects / xerces-c-3.2.2 / src / .libs / libxerces-c.a(ICUTransService.o):在函数xercesc_3_2::ICUTransService::upperCase(unsigned short*)': /home/anaim/projects/xerces-c- 3.2.2/src/xercesc/util/Transcoders/ICU/ICUTransService.cpp:358: undefined reference to u_toupper_50']中>

Etc ...

1)因此,我必须重复相同的步骤并将标题添加到路径中,直到这些都解决了吗?

这似乎是NetBeans问题?

如果开发人员提供了到库的写路径(在这种情况下为xerces),并且NetBeans能够看到该库(确实如此),为什么NetBeans不能生​​成正确的编译器/链接器命令,而不是C的全部内容/ C ++ IDE?

我的最新尝试:

我已经开始使用不依赖NetBeans的自定义Makefile。

这里是Makefile:

# vars c++ CXX := g++ CXXFLAGS := -std=c++11 -Wall -g #collect all c++ files $(wildcard *.cpp) SOURCES_CC = newmain.cpp #vars c CC := gcc CFLAGS := -std=c99 -Wall -g #collect all c files SOURCES_C := $(wildcard *.c) #objects OBJECTS_DIR := build #construct objects from .c and .cpp to .o OBJECTS := $(SOURCES_C:%.c=$(OBJECTS_DIR)/%.o) $(SOURCES_CC:%.cpp=$(OBJECTS_DIR)/%.o) #includes INCLUDES := -I../../projects/xerces-c-3.2.2/src/xercesc -I../../projects/xerces-c-3.2.2/src -include ../../projects/xerces-c-3.2.2/src/xercesc/util/PlatformUtils.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/util/XMLUni.hpp -include ../../projects/xerces-c-3.2.2/src/xercesc/util/XMLException.hpp -MMD -MP -MF "build/Debug/GNU-Linux/newmain.o.d" #final executable in dist DIST_DIR := dist PROGRAM := $(DIST_DIR)/main #required libraries LDFLAGS = -lxerces-c debug := CFLAGS .PHONY: all all debug: $(PROGRAM) $(PROGRAM): $(INCLUDES) $(OBJECTS) $(CXX) -o $@ $(OBJECTS) $(LDFLAGS) .PHONY: clean clean: rm -f $(PROGRAM) $(OBJECTS)

这是最新的错误:

cd '/home/myuser/NetBeansProjects/SOFF_test' /usr/bin/gmake -f Makefile CONF=Debug gmake: *** No rule to make target `-I../../projects/xerces-c-3.2.2/src/xercesc', needed by `dist/main'. Stop.

这是我唯一的问题!如何更改此自定义Makefile来构建样本xerces示例以及我自己的源文件(.c和.cpp)?

谢谢百万!

我正在尝试在基于Linux RedHat构建的NetBeans项目中Xerces c ++解析器库。我遵循构建指南(https://xerces.apache.org/xerces-c/build-3.html#UNIX)1)下载tar.gz“ ...

c++ linux netbeans makefile
1个回答
0
投票
如果您不希望使用Make,我建议改用CMake。它更易于使用,并且Netbeans C ++插件对此具有内置支持。

安装程序:

© www.soinside.com 2019 - 2024. All rights reserved.