MinGW ld 链接错误 - 未定义参考

问题描述 投票:0回答:1

我希望在人工智能时代,至少有一些人类仍然可以帮助解决“无所不知”的GPT无法解决的问题。

问题

我正在尝试为 C++ 库创建 Python 接口,一些模块给我链接错误。错误详细信息如下。

错误详情

2024-03-14 18:26:40,630 - ERROR - 
        ------------------------------
        Error compiling stepper_motor:
        
        Error code: 1
        Error: C:/SysGCC/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\User\AppData\Local\Temp\ccfElxip.o:stepper_motor_wrap.cxx:(.text+0x178a4): undefined reference to `SBC_RequestTriggerSwitches'collect2.exe: error: ld returned 1 exit status

        g++ command: ['g++', '-shared', '-o', 'd:\\CZI_scope\\code\\pymodules\\thorlabs_kinesis\\motion_control\\benchtop\\_stepper_motor.pyd', 'd:\\CZI_scope\\code\\pymodules\\thorlabs_kinesis\\motion_control\\benchtop\\stepper_motor_wrap.cxx', '-Ic:\\Users\\User\\mambaforge\\envs\\rich\\include', '-Id:\\CZI_scope\\code\\pymodules\\thorlabs_kinesis\\__include', '-Lc:\\Users\\User\\mambaforge\\envs\\rich', '-Ld:\\CZI_scope\\code\\pymodules\\thorlabs_kinesis\\__lib', '-lpython39', '-lThorlabs.MotionControl.Benchtop.StepperMotor', '-Wno-error']        
        ------------------------------

有问题的符号是在头文件中定义的(因此是链接错误而不是编译)。我已经使用

dumpbin
转储了 .lib 文件的导出,从输出来看,该名称已被破坏。我知道这是 C++ 库的标准,所以我不确定这就是问题所在。

转储箱输出

?RequestTriggerSwitches@CBenchtopStepperMotorChannel@StepperMotor@Benchtop@MotionControl@Thorlabs@@QEBAFXZ (public: short __cdecl Thorlabs::MotionControl::Benchtop::StepperMotor::CBenchtopStepperMotorChannel::RequestTriggerSwitches(void)const )

标头定义

#ifdef BENCHTOPSTEPPERMOTORDLL_EXPORTS
/// <summary> Gets the Benchtop Stepper API. </summary>
#define BENCHTOPSTEPPERMOTOR_API __declspec(dllexport)
#else
#define BENCHTOPSTEPPERMOTOR_API __declspec(dllimport)
#endif
extern "C"
{
BENCHTOPSTEPPERMOTOR_API short __cdecl SBC_RequestTriggerSwitches(char const * serialNo, short channel);
...
}

SWIG 接口文件


%module stepper_motor

// Remove calling convention macros compatibility with SWIG
#define __cdecl
#define __stdcall
#define __declspec(x) 
#define WINAPI

%{
#include <windows.h>
#include <stdbool.h>
#define BENCHTOPSTEPPERMOTORDLL_EXPORTS 
#include "Thorlabs.MotionControl.Benchtop.StepperMotor.h"
%}
%include "Thorlabs.MotionControl.Benchtop.StepperMotor.h"
python c++ mingw swig
1个回答
0
投票

使用

dependencies.exe
,我查看了相关 DLL 的导出,我发现的唯一两个与头文件中的函数签名接近匹配的导出是

717 (0x02cd),  (0x), public: short __cdecl Thorlabs::MotionControl::Benchtop::StepperMotor::CBenchtopStepperMotorChannel::RequestTriggerSwitches(void)const __ptr64, 0x000156a0, Microsoft
718 (0x02ce),  (0x), public: short __cdecl Thorlabs::MotionControl::Benchtop::StepperMotor::CStepperMotorCtrlBase::RequestTriggerSwitches(short) __ptr64, 0x0002b160, Microsoft

由于两者都不匹配头文件中的内容,并且考虑到 Crime_Affair 和其他人指出的内容,我能想到的唯一解释是,尽管有头文件和文档,但该函数并未在 DLL 中导出。

谢谢大家的帮助。

© www.soinside.com 2019 - 2024. All rights reserved.