c++ - 如何在我自己的staticLib中使用staticLib?

标签 c++ c eclipse static-libraries xerces-c

我尝试创建自己的库,以便在 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/

相关文章:

java - 如何在Eclipse中调试乐山代码

android - 如何在 Android 应用程序上为 ImageButton 添加效果?

java - 在 Eclipse 中从 SVN 服务器 checkout GWT 项目?

c++ - 如何使用 C++ 检查 .text 文件中的字符序列?

c++ - 如何通过WebRTC发送ffmpeg AVPacket(使用libdatachannel)

c++ - 帮助理解 C++、模板、operator() 的类示例代码

c - 在 C 中,在声明中使用 ":"运算符而不是条件运算符

c++ - 什么是 C++ 模块权限?

c - 标记结构初始化、函数及其参数

c - 多次调用 char[] 立即返回函数 fprint