【问题标题】:Error LNK2019: external symbol错误 LNK2019:外部符号
【发布时间】:2015-02-07 21:36:53
【问题描述】:

我是elastix 的新手,并且停留在最开始。我正在尝试用 C++ 编译一个非常基本的程序,它将对使用 elastix 库进行实例化。当我试图编译程序时,我得到了一个链接器错误:

错误 LNK2019:外部符号“公共:虚拟 __cdecl elastix ELASTIX :: :: ~ ELASTIX (void)" (?? 1ELASTIX @ elastix FALU@@@XZ) unresolved 中提到的“公共函数:virtual void * __cdecl elastix eLASTIX :: :: `标量删除析构函数'(unsigned int)" (?? _@elastix GELASTIX UEAAPEAXI@@@Z)

我做了一些谷歌搜索,发现它实际上是一个流行的链接器问题:see this topicand this oneand this particular elastix mail chain。我尝试使用这些链接修复它,但没有成功。我想知道你们是否可以帮助我。您可以在下面找到我的源文件(CMakeList.txt 和 C++ 代码)和一些附加信息:我运行 windows 7,Cmake 版本是 3.0.2,ITK 版本是 4.6,elastix 版本是 4.7 和 Microsoft VS 2008。提前致谢

CmakeList.txt # 使用来自外部项目的 elastix 代码的示例项目。 项目(elxExternalProject)

CMAKE_MINIMUM_REQUIRED( VERSION 2.8 )

# Find TIK
FIND_PACKAGE( ITK REQUIRED )
INCLUDE( ${ITK_USE_FILE} )

# find elastix
SET( ELASTIX_BINARY_DIR "" CACHE PATH "Path to elastix binary folder" )
SET( ELASTIX_USE_FILE ${ELASTIX_BINARY_DIR}/UseElastix.cmake )
IF( EXISTS ${ELASTIX_USE_FILE} )
 MESSAGE( STATUS "Including Elastix settings." )
 INCLUDE( ${ELASTIX_USE_FILE} )
ENDIF()

# Build a small test executable (this test is basically the same as
# the one found in the <elastix-dir>/src/Testing dir.
ADD_EXECUTABLE( elxtimertest itkTimerTest.cxx )

# Link to some libraries
TARGET_LINK_LIBRARIES( elxtimertest
  ITKCommon elxCommon elastix )

C++ 代码

#include "elastixlib.h"
using namespace elastix;

int main( int argc, char *argv[] )
{

    ELASTIX* el = new ELASTIX();
    std::cerr << "elastix created" << std::endl;

    delete el;
    return 0;
}

【问题讨论】:

  • 可能没有链接 elastix 库,因为它没有在链接器标志中指定,或者指定不正确。如果您使用 GNU make,我建议您运行 make VERBOSE=1 之类的东西来查看实际的链接器标志,但是由于您可能使用的是 nmake,所以这个 SO question 可能会帮助您调查实际的链接器标志。标志是。
  • 我使用的是cmake-gui,我手动设置路径,然后重新配置。

标签: c++ cmake itk cmake-gui elastix


【解决方案1】:

所以我解决了。我回溯了整个事情,似乎 CMake 没有应用我在 GUI 中所做的更改。所以我手动修改了 CMakeLists。之后,像魅力一样工作

【讨论】:

    猜你喜欢
    • 2014-05-12
    • 2014-05-14
    • 2012-10-31
    • 2012-08-31
    相关资源
    最近更新 更多