c++ - xerces c++ 和 cmake

标签 c++ cmake xerces

我尝试使用 xerces c++ 3.1 和 cmake 构建一个 Xerces 的小示例,但我只遇到链接问题。 这是我的 cmkelists.txt:

//============================================================================
project(ConfiguradorXerces)
cmake_minimum_required(VERSION 2.8)
include_directories (/home/ricardo/Desktop/librerias/xerces/xerces-c-3.1.1/src)
link_directories (/home/ricardo/Desktop/librerias/xerces/xerces-c-3.1.1/src/.libs)
link_directories (/home/ricardo/Desktop/librerias/xerces/xerces-c-3.1.1/src/)
set ( XercesLib  xerces-c )
aux_source_directory(. SRC_LIST)

add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${XercesLib})
//==============================================

//=========================================== ==

#include <iostream>
#include <xercesc/util/PlatformUtils.hpp>
using namespace xercesc;
using namespace std;
int main()
{
    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;
}

//=========================================== =

这是我的控制台输出:

CMakeFiles/ConfiguradorXerces.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x25): undefined reference to `xercesc_3_1::XMLUni::fgXercescDefaultLocale'
main.cpp:(.text+0x2a): undefined reference to `xercesc_3_1::XMLPlatformUtils::Initialize(char const*, char const*, xercesc_3_1::PanicHandler*, xercesc_3_1::MemoryManager*)'
main.cpp:(.text+0x2f): undefined reference to `xercesc_3_1::XMLPlatformUtils::Terminate()'
CMakeFiles/ConfiguradorXerces.dir/main.cpp.o:(.gcc_except_table+0x10): undefined reference to `typeinfo for xercesc_3_1::XMLException'
collect2: error: ld returned 1 exit status
make[2]: *** [ConfiguradorXerces] Error 1
make[1]: *** [CMakeFiles/ConfiguradorXerces.dir/all] Error 2
make: *** [all] Error 2
16:28:55: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project ConfiguradorXerces (target: Desktop)
When executing step 'Make'

// 我在想我的 cmakeLsits.txt 不完整,必须完成一个特殊的设置? 提前谢谢

最佳答案

我很确定 target_link_libraries() 宏接受一个目标作为它的第一个参数:

  target_link_libraries(<target> [item1 [item2 [...]]]
                        [[debug|optimized|general] <item>] ...)

而且您忘记指定它。因此,不要使用 target_link_libraries(${XercesLib}),而是尝试使用 target_link_libraries(${PROJECT_NAME} ${XercesLib})

希望这能解决问题。

关于c++ - xerces c++ 和 cmake,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14466571/

相关文章:

在 ofstream 的文件名括号内输入代码中的值(如循环中的 i)的 C++ 语法

c++ - PeekMessage() 抛出未处理的异常(访问冲突)

cmake ExternalProject缓存被覆盖

c++ - boost Asio 和 OpenSSL 1.1.0

java - 尝试在 java 中构建 Apache Xerces 时出现编译错误

c++ - 隐藏符号时 dynamic_cast 失败

c++ - 是否可以在 Visual Studio 2012 C++ 中为 "Step Into Specific"分配快捷方式?

c++ - 使用调用约定 fastcall 的任何实际用例?

makefile - SDL2 库在 Make 中找不到,但在 CMake 中找到

c++ - 在Dom解析器中找不到作者