首页 文章

在Visual Studio 2010中使用PCL和OpenCV进行静态构建

提问于
浏览
1

我在Visual Studio 2010中使用OpenCV 2.49和Point Cloud Library 1.6运行项目 . 我正在尝试制作一个独立的可执行文件,因此我不需要在其他计算机上安装OpenCV和PCL来使其运行 . OpenCV和PCL使用预编译的二进制文件安装,PCL还包括boost(1.49)和vtk(5.8)库等 .

为了进行静态构建,我将VS中的运行时库更改为/ MT . 然后,一些Boost静态库丢失,所以我再次安装了boost(版本1.56,我相信我需要带有's'的库) .

然后我有错误,如:

1>MSVCRT.lib(MSVCR100.dll) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)

所以我将msvcrt.lib,msvcprt.lib添加到“Ignore Specific Defaul Libraries”部分 .

现在我有错误:

1>vtkCommon.lib(vtkVoidArray.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(void const *)" (__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@PBX@Z)

1>vtkCommon.lib(vtkVariantArray.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(void const *)" (__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@PBX@Z)

1>vtkCommon.lib(vtkTimerLog.obj) : error LNK2001: unresolved external symbol __imp__strncpy

1>vtkCommon.lib(vtkMath.obj) : error LNK2001: unresolved external symbol __imp__modf

1>vtksys.lib(SystemTools.obj) : error LNK2001: unresolved external symbol __imp___utime64

1>OLDNAMES.lib(unlink.obi) : error LNK2001: unresolved external symbol __imp__unlink

vtk库的包含方式与非静态发布版本中的方式完全相同 . 而且,如果我理解正确,.lib是静态库的扩展 .

我究竟做错了什么?

EDIT: 我尝试过使用CMake,但我遇到了同样的错误(还有很多):

2>vtksys.lib(SystemTools.obj) : error LNK2019: unresolved external symbol __imp___time64 referenced in function _time

2>vtkCommon.lib(vtkVariant.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_istream<char,struct std::char_traits<char> > & __thiscall std::basic_istream<char,struct std::char_traits<char> >::operator>>(short &)" (__imp_??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAF@Z) referenced in function "short __cdecl vtkVariantStringToNumeric<short>(class vtkStdString,bool *,short *)" (??$vtkVariantStringToNumeric@F@@YAFVvtkStdString@@PA_NPAF@Z)

这是我的CMakeList.txt:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(3DVisualizerCM)

set(BUILD_SHARED_LIBS OFF)

SET(CMAKE_EXE_LINKER_FLAGS "/NODEFAULTLIB:msvcrt.lib
                            /NODEFAULTLIB:msvcprt.lib")

find_package(PCL 1.4 REQUIRED)
find_package(OpenCV REQUIRED)

include_directories(${PCL_INCLUDE_DIRS} )
link_directories(${PCL_LIBRARY_DIRS} )
add_definitions(${PCL_DEFINITIONS} )

add_executable (3D_v4 
        3D_v4.cpp
        C3DVisualizer.cpp
        C3DVisualizerMultiple.cpp
        C3DVisualizerSingle.cpp
        CCameraParameters.cpp
        CImageTrack.cpp
        CImg.cpp
        CImgMultiple.cpp
        CImgSingle.cpp
        helpers.cpp
)

target_link_libraries (3D_v4 ${PCL_LIBRARIES} ${OpenCV_LIBS})

1 回答

  • 1

    您在PCL中使用的预编译vtk库必须使用Visual Studio中的/ MD标志(多线程DLL)进行编译 . 您需要使用/ MT标志(多线程静态链接)重新编译它们 .

相关问题