我尝试创建自己的库,以便在 C/C++ 的其他项目中使用它。我的静态库使用库 xercesc。 Eclipse 尝试使用 gcc 而不是 g++ 编译 xercesc 包含的库。如果我尝试编译我的代码,我收到以下错误:
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++ 编译项目吗?
最佳答案
您需要明确告诉 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"
关于c++ - 如何在我自己的staticLib中使用staticLib?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51709502/