!呜呼啦呼! 2023-10-25 13:17 采纳率: 70%
浏览 21
已结题

error LNK2019: 无法解析的外部符号

windows系统Visual stdio生成解决方案报错:

4>pytoolbox.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) void * __cdecl boost::python::objects::find_dynamic_type(void *,struct boost::python::type_info,struct boost::python::type_info)" (__imp_?find_dynamic_type@objects@python@boost@@YAPEAXPEAXUtype_info@23@1@Z),该符号在函数 "private: virtual void * __cdecl boost::python::objects::pointer_holder<class std::unique_ptr<class ProjectorInterface2D,struct std::default_delete<class ProjectorInterface2D> >,class ProjectorInterface2D>::holds(struct boost::python::type_info,bool)" (?holds@?$pointer_holder@V?$unique_ptr@VProjectorInterface2D@@U?$default_delete@VProjectorInterface2D@@@std@@@std@@VProjectorInterface2D@@@objects@python@boost@@EEAAPEAXUtype_info@34@_N@Z) 中被引用
4>pytoolbox.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __cdecl boost::python::converter::shared_ptr_deleter::shared_ptr_deleter(struct boost::python::converter::shared_ptr_deleter const &)" (__imp_??0shared_ptr_deleter@converter@python@boost@@QEAA@AEBU0123@@Z),该符号在函数 "public: __cdecl std::_Compressed_pair<struct boost::python::converter::shared_ptr_deleter,void *,0>::_Compressed_pair<struct boost::python::converter::shared_ptr_deleter,void *,0><struct boost::python::converter::shared_ptr_deleter,void * &>(struct std::_One_then_variadic_args_t,struct boost::python::converter::shared_ptr_deleter &&,void * &)" (??$?0Ushared_ptr_deleter@converter@python@boost@@AEAPEAX@?$_Compressed_pair@Ushared_ptr_deleter@converter@python@boost@@PEAX$0A@@std@@QEAA@U_One_then_variadic_args_t@1@$$QEAUshared_ptr_deleter@converter@python@boost@@AEAPEAX@Z) 中被引用
4>  已定义且可能匹配的符号上的提示:
4>    "__declspec(dllimport) public: __cdecl boost::python::converter::shared_ptr_deleter::shared_ptr_deleter(class boost::python::handle<struct _object>)" (__imp_??0shared_ptr_deleter@converter@python@boost@@QEAA@V?$handle@U_object@@@23@@Z)
4>pytoolbox.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __cdecl boost::python::objects::class_base::~class_base(void)" (__imp_??1class_base@objects@python@boost@@QEAA@XZ),该符号在函数 "int `public: __cdecl boost::python::class_<class ProjectorInterface2D,class boost::noncopyable_::noncopyable,struct boost::python::detail::not_specified,struct boost::python::detail::not_specified>::class_<class ProjectorInterface2D,class boost::noncopyable_::noncopyable,struct boost::python::detail::not_specified,struct boost::python::detail::not_specified>(char const *,enum python::class_<class ProjectorInterface2D,class boost::noncopyable_::noncopyable,struct boost::python::detail::not_specified,struct boost::python::detail::not_specified>::no_init_t)'::`1'::dtor$0" (?dtor$0@?0???0?$class_@VProjectorInterface2D@@Vnoncopyable@noncopyable_@boost@@Unot_specified@detail@python@4@U5674@@python@boost@@QEAA@PEBDW4no_init_t@12@@Z@4HA) 中被引用
4>pytoolbox.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) void __cdecl boost::python::objects::register_dynamic_id_aux(struct boost::python::type_info,struct std::pair<void *,struct boost::python::type_info> (__cdecl*)(void *))" (__imp_?register_dynamic_id_aux@objects@python@boost@@YAXUtype_info@23@P6A?AU?$pair@PEAXUtype_info@python@boost@@@std@@PEAX@Z@Z),该符号在函数 "void __cdecl boost::python::objects::register_dynamic_id<class ProjectorInterface2D>(class ProjectorInterface2D *)" (??$register_dynamic_id@VProjectorInterface2D@@@objects@python@boost@@YAXPEAVProjectorInterface2D@@@Z) 中被引用
4>pytoolbox.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) void __cdecl boost::python::objects::add_cast(struct boost::python::type_info,struct boost::python::type_info,void * (__cdecl*)(void *),bool)" (__imp_?add_cast@objects@python@boost@@YAXUtype_info@23@0P6APEAXPEAX@Z_N@Z),该符号在函数 "void __cdecl boost::python::objects::register_conversion<class ProjectorInterface2D,class ProjectorInterface3D>(bool,class ProjectorInterface2D *,class ProjectorInterface3D *)" (??$register_conversion@VProjectorInterface2D@@VProjectorInterface3D@@@objects@python@boost@@YAX_NPEAVProjectorInterface2D@@PEAVProjectorInterface3D@@@Z) 中被引用
4>pytoolbox.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __cdecl boost::python::numpy::ndarray::ndarray(struct boost::python::detail::borrowed_reference_t *)" (__imp_??0ndarray@numpy@python@boost@@QEAA@PEAUborrowed_reference_t@detail@23@@Z),该符号在函数 "public: class boost::python::numpy::ndarray __cdecl boost::python::converter::object_manager_value_arg_from_python<class boost::python::numpy::ndarray>::operator()(void)const " (??R?$object_manager_value_arg_from_python@Vndarray@numpy@python@boost@@@converter@python@boost@@QEBA?AVndarray@numpy@23@XZ) 中被引用
4>pytoolbox.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: class boost::python::numpy::ndarray __cdecl boost::python::numpy::ndarray::copy(void)const " (__imp_?copy@ndarray@numpy@python@boost@@QEBA?AV1234@XZ),该符号在函数 "class boost::python::numpy::ndarray __cdecl backward(class boost::python::numpy::ndarray,class boost::python::numpy::ndarray,class boost::python::numpy::ndarray,double,double,unsigned int,unsigned int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?backward@@YA?AVndarray@numpy@python@boost@@V1234@00NNIIAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 中被引用
4>pytoolbox.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __int64 __cdecl boost::python::numpy::ndarray::shape(int)const " (__imp_?shape@ndarray@numpy@python@boost@@QEBA_JH@Z),该符号在函数 "class boost::python::numpy::ndarray __cdecl forward(class boost::python::numpy::ndarray,class boost::python::numpy::ndarray,class boost::python::numpy::ndarray,double,double)" (?forward@@YA?AVndarray@numpy@python@boost@@V1234@00NN@Z) 中被引用
4>pytoolbox.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: char * __cdecl boost::python::numpy::ndarray::get_data(void)const " (__imp_?get_data@ndarray@numpy@python@boost@@QEBAPEADXZ),该符号在函数 "class boost::python::numpy::ndarray __cdecl forward(class boost::python::numpy::ndarray,class boost::python::numpy::ndarray,class boost::python::numpy::ndarray,double,double)" (?forward@@YA?AVndarray@numpy@python@boost@@V1234@00NN@Z) 中被引用
4>pytoolbox.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __cdecl boost::python::numpy::ndarray::~ndarray(void)" (__imp_??1ndarray@numpy@python@boost@@QEAA@XZ),该符号在函数 "class boost::python::numpy::ndarray __cdecl forward(class boost::python::numpy::ndarray,class boost::python::numpy::ndarray,class boost::python::numpy::ndarray,double,double)" (?forward@@YA?AVndarray@numpy@python@boost@@V1234@00NN@Z) 中被引用
4>pytoolbox.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __cdecl boost::python::numpy::ndarray::ndarray(class boost::python::numpy::ndarray &&)" (__imp_??0ndarray@numpy@python@boost@@QEAA@$$QEAV0123@@Z),该符号在函数 "class boost::python::numpy::ndarray __cdecl forward(class boost::python::numpy::ndarray,class boost::python::numpy::ndarray,class boost::python::numpy::ndarray,double,double)" (?forward@@YA?AVndarray@numpy@python@boost@@V1234@00NN@Z) 中被引用
4>pytoolbox.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) class boost::python::numpy::ndarray __cdecl boost::python::numpy::zeros(int,__int64 const *,class boost::python::numpy::dtype const &)" (__imp_?zeros@numpy@python@boost@@YA?AVndarray@123@HPEB_JAEBVdtype@123@@Z),该符号在函数 "class boost::python::numpy::ndarray __cdecl forward(class boost::python::numpy::ndarray,class boost::python::numpy::ndarray,class boost::python::numpy::ndarray,double,double)" (?forward@@YA?AVndarray@numpy@python@boost@@V1234@00NN@Z) 中被引用
4>pytoolbox.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: static bool __cdecl boost::python::converter::object_manager_traits<class boost::python::numpy::ndarray>::check(struct _object *)" (__imp_?check@?$object_manager_traits@Vndarray@numpy@python@boost@@@converter@python@boost@@SA_NPEAU_object@@@Z),该符号在函数 "public: bool __cdecl boost::python::converter::object_manager_value_arg_from_python<class boost::python::numpy::ndarray>::convertible(void)const " (?convertible@?$object_manager_value_arg_from_python@Vndarray@numpy@python@boost@@@converter@python@boost@@QEBA_NXZ) 中被引用
4>pytoolbox.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: static struct _typeobject const * __cdecl boost::python::converter::object_manager_traits<class boost::python::numpy::ndarray>::get_pytype(void)" (__imp_?get_pytype@?$object_manager_traits@Vndarray@numpy@python@boost@@@converter@python@boost@@SAPEBU_typeobject@@XZ),该符号在函数 "public: static struct _typeobject const * __cdecl boost::python::detail::object_manager_get_pytype<1>::get<class boost::python::numpy::ndarray>(class boost::python::numpy::ndarray const & (__cdecl*)(void))" (??$get@Vndarray@numpy@python@boost@@@?$object_manager_get_pytype@$00@detail@python@boost@@SAPEBU_typeobject@@P6AAEBVndarray@numpy@23@XZ@Z) 中被引用
4>E:\M256test\simulation_toolbox\build\Debug\pytoolbox.pyd : fatal error LNK1120: 14 个无法解析的外部命令

代码原来是ubuntu系统上编写的,跨平台重新编译,cmake没有报错没有waring,生成解决方案一直报“error LNK2019: 无法解析的外部符号”,查看了一些帖子尝试以下方式仍未解决:

  1. 添加库目录和库
    看报错应该是boost:python和boost:nump这两个库相关,将两个库:
    D:\software\boost_1_79_0\boost_1_79_0\lib\libboost_python37-vc142-mt-gd-x64-1_79.lib
    D:\software\boost_1_79_0\boost_1_79_0\lib\libboost_numpy37-vc142-mt-gd-x64-1_79.lib
    添加完链接器、常规、附加库目录和链接器、输入、附加依赖项,未解决;
  2. 修改解决方案配置
    因为cmakelists中指定为degug x64,所以按照要求重新生成,仍报错;
  3. 查看代码具体报错为,看是否定义该函数或符号
    查看所有报错位置,该函数均已经定义
  4. lib文件添加目录可能不对
    查看正确
    给下可能的问题方向,感谢。
    大ge们可以说的清楚一些嘛,不要纯专业术语。
  • 写回答

3条回答 默认 最新

  • !呜呼啦呼! 2023-10-31 10:10
    关注

    问题解决,记录一下过程,也感谢评论区帮助过的老师们。
    问题出在Boost库上,我在windows系统上编译安装的boost库,编译指令为:

    .\b2 --with-python --prefix="D:\software\boost_1_79_0\boost_1_79_0" install toolset=msvc-14.2 link=static address-model=64
    

    其中,link=static是指编译为静态库,之前查到大多数是这样选择,当然也可以选择link=shared,这样就编译为动态库了,因为我的程序cmakeLists.txt文件中都设定了shared,寻找动态库,所以这里就找不到和boost相关的所有引用函数,就会报这个:

    error LNK2019: 无法解析的外部符号
    解决办法:
    在代码中,引用boost之前添加

    #define BOOST_PYTHON_STATIC_LIB
    #define BOOST_NUMPY_STATIC_LIB
    

    如果不想动代码,也可以在cmakeLists.txt文件中,findpackage boost 之前添加

    add_definitions(-DBOOST_PYTHON_STATIC_LIB -DBOOST_NUMPY_STATIC_LIB)
    

    这样生成解决方案的时候就可以找到安装的boost静态库了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 11月8日
  • 已采纳回答 10月31日
  • 修改了问题 10月25日
  • 创建了问题 10月25日

悬赏问题

  • ¥66 关于川崎机器人调速问题
  • ¥15 winFrom界面无法打开
  • ¥15 crossover21 ARM64版本安装软件问题
  • ¥15 mymetaobjecthandler没有进入
  • ¥15 mmo能不能做客户端怪物
  • ¥15 osm下载到arcgis出错
  • ¥15 Dell g15 每次打开eiq portal后3分钟内自动退出
  • ¥200 使用python编写程序,采用socket方式获取网页实时刷新的数据,能定时print()出来就行。
  • ¥15 matlab如何根据图片中的公式绘制e和v的曲线图
  • ¥15 我想用Python(Django)+Vue搭建一个用户登录界面,但是在运行npm run serve时报错了如何解决?