我尝试创建自己的库以在C / C ++的其他项目中使用它。我的静态库使用xercesc库。 Eclipse尝试使用gcc而非g ++编译xercesc包含的lib。如果我尝试编译代码,则会出现以下错误:
Info: Internal Builder is used for build
g++ "-IC:\\00_Projects\\Ladeplanberechnung\\LadeplanLib\\lib\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\viterbi\\ViterbiAlgorithm.o" "..\\src\\viterbi\\ViterbiAlgorithm.cpp"
In file included from ..\src\viterbi\LocalSuitability.h:11:0,
from ..\src\viterbi\ViterbiAlgorithm.h:8,
from ..\src\viterbi\ViterbiAlgorithm.cpp:8:
gcc "-IC:\\00_Projects\\Ladeplanberechnung\\LadeplanLib\\lib\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o "lib\\include\\xercesc\\util\\RefArrayVectorOf.o" "..\\lib\\include\\xercesc\\util\\RefArrayVectorOf.c"
..\lib\include\xercesc\util\RefArrayVectorOf.c:25:1: error: unknown type name 'XERCES_CPP_NAMESPACE_BEGIN'
XERCES_CPP_NAMESPACE_BEGIN
^~~~~~~~~~~~~~~~~~~~~~~~~~
..\lib\include\xercesc\util\RefArrayVectorOf.c:30:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
template <class TElem>
^
..\lib\include\xercesc\util\RefArrayVectorOf.c:39:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
template <class TElem> RefArrayVectorOf<TElem>::~RefArrayVectorOf()
^
..\lib\include\xercesc\util\RefArrayVectorOf.c:49:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
template <class TElem> void
^
..\lib\include\xercesc\util\RefArrayVectorOf.c:61:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
template <class TElem> void RefArrayVectorOf<TElem>::removeAllElements()
^
..\lib\include\xercesc\util\RefArrayVectorOf.c:74:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
template <class TElem> void RefArrayVectorOf<TElem>::
^
..\lib\include\xercesc\util\RefArrayVectorOf.c:102:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
template <class TElem> void RefArrayVectorOf<TElem>::removeLastElement()
^
..\lib\include\xercesc\util\RefArrayVectorOf.c:112:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
template <class TElem> void RefArrayVectorOf<TElem>::cleanup()
^
..\lib\include\xercesc\util\RefArrayVectorOf.c:122:1: error: expected '=', ',', ';', 'asm' or '__attribute__' at end of input
XERCES_CPP_NAMESPACE_END
^~~~~~~~~~~~~~~~~~~~~~~~
为什么Eclipse会尝试编译xercesc? 我可以强制Eclipse用g ++编译项目吗?
答案 0 :(得分:0)
您需要明确告诉gcc您的源代码为C++
,因为它将假定以.c
结尾的文件是用C
编写的。将-x c++
添加到命令中,它应该可以工作:
gcc "-IC:\\00_Projects\\Ladeplanberechnung\\LadeplanLib\\lib\\include" -O0 -g3 -Wall -c -fmessage-length=0 -x c++ -o "lib\\include\\xercesc\\util\\RefArrayVectorOf.o" "..\\lib\\include\\xercesc\\util\\RefArrayVectorOf.c"