对.dll库中函数的未定义引用
Undefined Reference to Functions from .dll Library
前言:我在Windows 10机器上使用Code::Blocks软件,并用C++编程。我正在使用普林斯顿仪器科学CCD相机的库。
我会尽量在这里具体一点。我正试图使用控制普林斯顿仪器相机(PIcam)的多个功能创建一个.dll文件。我之所以制作这个.dll,是因为我想把这个代码(在C++中)嵌入到另一个Python程序中。这是我当前的相关main.cpp代码:
#include "main.h"
#include "stdio.h"
#include "picam.h"
// a sample exported function
void DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}
void DLL_EXPORT connectCamera()
{
Picam_InitializeLibrary();
PicamHandle camera;
PicamCameraID id;
//const pichar* string;
//PicamAvailableData data;
//PicamAcquisitionErrorsMask errors;
//piint readoutstride = 0;
if (Picam_OpenFirstCamera( &camera ) == PicamError_None )
Picam_GetCameraID( camera, &id );
else {
Picam_ConnectDemoCamera(
PicamModel_Pixis100F,
"0008675309",
&id );
Picam_OpenCamera( &id, &camera );
printf( "No Camera Detected, Creating Demo Cameran" );
}
}
但是编译器在我构建代码后会给我这些错误。它声称我调用的每一个函数都是未定义的引用,即使在我成功链接了Code::Blocks中的库之后也是如此。
我知道我的图书馆链接正确。所有这些函数都位于Picam.lib库中,我知道它的链接是正确的。以下是显示它的构建日志代码:
mingw32-g++.exe -shared -Wl,--output-def=binDebuglibSampleDLL.def -Wl,--out-implib=binDebuglibSampleDLL.a -Wl,--dll -LC:UsersPhilipDocumentsCppProjectsSampleDLL objDebugmain.o -o binDebugSampleDLL.dll -lPicam -luser32 -lPicam C:UsersPhilipDocumentsCppProjectsSampleDLLPicam.lib
objDebugmain.o: In function `Z13connectCamerav':
C:/Users/Philip/Documents/CppProjects/SampleDLL/main.cpp:13: undefined reference to `_imp__Picam_InitializeLibrary@0'
C:/Users/Philip/Documents/CppProjects/SampleDLL/main.cpp:21: undefined reference to `_imp__Picam_OpenFirstCamera@4'
C:/Users/Philip/Documents/CppProjects/SampleDLL/main.cpp:22: undefined reference to `_imp__Picam_GetCameraID@8'
C:/Users/Philip/Documents/CppProjects/SampleDLL/main.cpp:27: undefined reference to `_imp__Picam_ConnectDemoCamera@12'
C:/Users/Philip/Documents/CppProjects/SampleDLL/main.cpp:28: undefined reference to `_imp__Picam_OpenCamera@8'
collect2.exe: error: ld returned 1 exit status
Creating library file: binDebuglibSampleDLL.a
Process terminated with status 1 (0 minute(s), 0 second(s))
5 error(s), 0 warning(s) (0 minute(s), 0 second(s))
我不知道还能做些什么来解决这个问题。看起来一切都是正确的,但函数仍然无法在库中识别。有人有什么想法吗?
我知道我的图书馆链接正确。
那你就做好了,不是吗!
然而,如果你愿意保持开放的心态并真正理解链接过程,你可能应该知道gcc(你正在使用)不知道如何处理.lib
文件,它们是Microsoft库文件。gcc的库文件以.a
或.so
结尾。
相关文章:
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 对 Scalar ::Scalar() 的未定义引用
- 对复制 CTOR 和 CTOR 的未定义引用
- 对显式实例化的模板函数的未定义引用
- TensorRT (C++ API) 对"createNvOnnxParser_INTERNAL"的未定义引用
- 2个模板化类的非模板友元函数未定义引用错误
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 获取对function_name的未定义引用
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- 对结构方法的未定义引用
- 使用内联函数 c++ 的未定义引用
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 对 DLOPEN 的未定义引用
- QT C++中对全局变量的未定义引用
- 快速数学导致对"__pow_finite"的未定义引用
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用