用Eclipse编译xerces-c++程序
compiling xerces-c++ program with Eclipse
我正在尝试在windows上使用xerces-c进行编程。
我已经成功地建立了这个库,并成功地编译了一个简单的程序,barebone,只需cmd和记事本。然而,当我试图将事情转移到eclipse时,事情有点失控了。
通过简单地拥有一个c++helloworld示例,然后将include文件包含到项目路径中并进行构建,eclipse拒绝构建项目,从而产生了很多错误,我认为这些错误主要与命名空间有关。
错误如下:
Info: Internal Builder is used for build
g++ -I...blablabla -O3 -Wall -c -fmessage-length=0 -o "src\helloworld.o" "..\src\helloworld.cpp"
gcc -O3 -Wall -c -fmessage-length=0 -o "src\includes\xercesc\util\RefStackOf.o" "..\src\includes\xercesc\util\RefStackOf.c"
..srcincludesxercescutilRefStackOf.c:30:1: error: unknown type name 'XERCES_CPP_NAMESPACE_BEGIN'
XERCES_CPP_NAMESPACE_BEGIN
..srcincludesxercescutilRefStackOf.c:35:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
template <class TElem>
^
..srcincludesxercescutilRefStackOf.c:44:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
template <class TElem> RefStackOf<TElem>::~RefStackOf()
..srcincludesxercescutilRefStackOf.c:...
...this and that, this and that.... and finally...
..srcincludesxercescutilRefStackOf.c:160:1: error: expected '=', ',', ';', 'asm' or '__attribute__' at end of input
XERCES_CPP_NAMESPACE_END
如果我错误地删除了文件,错误就会弹出到另一个相同格式的文件中,开头是"我不知道XERCES_CPP_NAMESPACE_BEGIN的意思">
我也尝试过使用另一个构建器,比如mingw32-make,但它也会生成相同格式的错误。只是稍微更改一下标题,也许文件是按照不同的顺序编译的,从以下开始:
mingw32-make all
'Building file: ../src/includes/xercesc/util/BaseRefVectorOf.c'
'Invoking: GCC C Compiler'
gcc -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/includes/xercesc/util/BaseRefVectorOf.d" -MT"src/includes/xercesc/util/BaseRefVectorOf.o" -o "src/includes/xercesc/util/BaseRefVectorOf.o" "../src/includes/xercesc/util/BaseRefVectorOf.c"
../src/includes/xercesc/util/BaseRefVectorOf.c:24:1: error: unknown type name 'XERCES_CPP_NAMESPACE_BEGIN'
XERCES_CPP_NAMESPACE_BEGIN
我猜构建程序不知道如何替换
XERCES_CPP_NAMESPACE_BEGIN,带
命名空间XERCES_CPP_namespace{}
命名空间xercesc=XERCES_CPP_namespace;
但我不知道如何教建设者如何做到这一点,也不确定我是否以正确的方式编译了库。
有人能给我指个方向,告诉我如何解决这个问题吗?我只需使用cmd就可以编译一个简单的程序,所以我当然应该能够在Eclipse中完成它。
背景:
- 操作系统:Windows 8 64位
- 编译器:mingw-w64 5.3.0 posix-seh-rev0
- 用msys编译的lib
- lib编译命令:
- /configure--prefix=/specific location--host=x86_64-w64-mingw32--启用netaccessor winsock--启用转码器窗口--禁用漂亮的make
- make LDFLAGS=-无未定义
- 进行检查
- 进行安装
cmd编译命令:g++-Lib-Iinclude-o b.exe test.cpp
因此,您可以看到,我还使用-Iinclude命令将每个xerces-c头都包含在编译器中,因此我认为g++在Eclipse中调用时不会产生错误,也不知道它的gcc。
使用cmd:简单编译时运行的简单程序
//test.cpp
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/sax/HandlerBase.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <iostream>
using namespace std;
using namespace xercesc;
int main (int argc, char* args[]) {
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Error during initialization! :n"
<< message << "n";
XMLString::release(&message);
return 1;
}
XercesDOMParser* parser = new XercesDOMParser();
parser->setValidationScheme(XercesDOMParser::Val_Always);
parser->setDoNamespaces(true); // optional
ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
parser->setErrorHandler(errHandler);
char* xmlFile = "x1.xml";
try {
parser->parse(xmlFile);
DOMDocument* xmlDoc = parser->getDocument();
DOMElement* elementRoot = xmlDoc->getDocumentElement();
if( !elementRoot ) throw(std::runtime_error( "empty XML document" ));
DOMNodeList* children = elementRoot->getChildNodes();
const XMLSize_t nodeCount = children->getLength();
cout << nodeCount << " nodesn";
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Exception message is: n"
<< message << "n";
XMLString::release(&message);
return -1;
}
catch (...) {
cout << "Unexpected Exception n" ;
return -1;
}
delete parser;
delete errHandler;
return 0;
}
@编辑
经过进一步的研究,XERCES_CPP_NAMESPACE_BEGIN似乎是在预处理器中处理的,但它只在文件util/XercesDefs.hpp
中定义
在有编译错误的文件中,它们总是以开头
#if defined(XERCES_TMPLSINC)
#include <xercesc/util/RefStackOf.hpp> //or include anything else blablabla, which ultimately leads to XercesDefs.hpp
#endif
我在整个构建目录中搜索了字符串XERCES_TMPLSINC,它包含在44.c或.hpp文件中,但每个文件都是#if !defined(XERCES_TMPLSINC)
<=====错误,就像XERCES_TMPLSINC从未真正定义过一样。
根据一些论坛帖子,XERCES_TMPLSINC是一些旧的c编译器所必需的,所以有人知道如何在我的构建中解决这个问题吗?如何在项目中定义XERCES_TMPLSINC?我已经尝试将#define XERCES_TMPLSINC
添加到helloworld文件中,但它仍然不起作用。
@编辑
糟糕的是,实际上所有的.c文件都包含#if defined(XERCES_TMPLSINC)
,所有的hpp文件都是#if !defined(XERCES_TMPLSINC)
,这看起来肯定是c和c++的事情吗?
通过在g++
中添加以下preprocessor defs
,我能够在Eclipse(在Linux上(中编译它:
-DXERCESC_INCLUDE_GUARD_WEAVEPATH_CPP -DXERCES_HAVE_STDINT_H -DXERCES_TMPLSINC.
在Windows上,我认为你应该用代替
-DXERCES_HAVE_STDINT_H -DXERCES_HAVE_CSTDINT
- Mongodb c++驱动程序:如何查询元素的数组
- C++,系统无法执行指定的程序
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 重载操作程序时出错>>用于类中的字符串 memebr
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 试图在visual studio上用C++创建一个桌面应用程序
- 模板元程序查找相似的连续类型名称
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 如何通过cpp程序运行shell脚本
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- IPC使用多个管道和分支进程来运行Python程序
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 基于boost的程序的静态链接——zlib问题
- 程序崩溃并显示"std::out_of_range"错误
- 在C应用程序中运行C++(带有STL)函数
- 使用mongocxx驱动程序时包含头文件问题
- 用Eclipse编译xerces-c++程序