I hope that in the age of AI, there are at least a few humans who can still help troubleshoot a problem that the "all-knowing" GPT cannot.
The Problem:
I'm trying to create a Python interface for a C++ library, and a few modules give me linking errors. The error details are given below.
Error Details
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']
------------------------------
The symbol in question is defined in the header file (hence linking error not compilation). I have dumped the exports of the .lib file using dumpbin and it looks, from the output, that the name has been mangled. I know this is standard for c++ libraries so I'm not certain that's the issue.
Dumpbin Output
?RequestTriggerSwitches@CBenchtopStepperMotorChannel@StepperMotor@Benchtop@MotionControl@Thorlabs@@QEBAFXZ (public: short __cdecl Thorlabs::MotionControl::Benchtop::StepperMotor::CBenchtopStepperMotorChannel::RequestTriggerSwitches(void)const )
Header Definition
#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 Interface File
%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"
Using
dependencies.exe, I looked at the exports of the DLL in question, and the only two exports I found close to matching the function signature in the header file wereSince neither one matches what's in the header file, and given what Criminal_Affair and others pointed out, the only explanation I can come to is that despite the header file and the documentation, the function isn't exported in the DLL.
Thank you all for your help.