对.dll库中函数的未定义引用 P>序:我使用代码::在Windows 10机器上的BASIC软件和C++编程。我正在使用普林斯顿仪器科学CCD相机的库

对.dll库中函数的未定义引用 P>序:我使用代码::在Windows 10机器上的BASIC软件和C++编程。我正在使用普林斯顿仪器科学CCD相机的库,c++,dll,codeblocks,C++,Dll,Codeblocks,在这里,我将尽可能具体地说。我正在尝试使用多个控制普林斯顿仪器相机(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

在这里,我将尽可能具体地说。我正在尝试使用多个控制普林斯顿仪器相机(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 Camera\n" );
    }
}
但是编译器在我编译代码后给了我错误。它声称我调用的每个函数都是未定义的引用,即使在我成功地在Code::Blocks中链接了库之后也是如此

我知道我的库链接正确。所有这些函数都位于库Picam.lib中,我知道它链接正确。以下是显示它的生成日志代码:

mingw32-g++.exe -shared -Wl,--output-def=bin\Debug\libSampleDLL.def -Wl,--out-implib=bin\Debug\libSampleDLL.a -Wl,--dll -LC:\Users\Philip\Documents\CppProjects\SampleDLL obj\Debug\main.o  -o bin\Debug\SampleDLL.dll  -lPicam -luser32 -lPicam C:\Users\Philip\Documents\CppProjects\SampleDLL\Picam.lib
obj\Debug\main.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: bin\Debug\libSampleDLL.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
结尾

我知道我的库链接正确

那你就准备好了,不是吗


但是,如果您愿意保持开放的心态并真正理解链接过程,您应该知道gcc(您正在使用的)不知道如何处理
.lib
文件,它们是Microsoft库文件。gcc的库文件以
.a
结尾。因此

有趣的是,这不会从链接器生成“无法读取该库格式”错误消息。因此,如果g++无法处理.lib文件,那么为什么它们一开始就可用?这是否不可能让任何C++编译器即使在.SO格式中不可用也不可能使用库文件?“我知道它们链接正确”,我的意思是我花了一个小时解决了“库未连接”的问题,然后最终解决了它。我不明白你的问题,我已经说过它们使用
cl
。有趣的是,这不会从链接器生成“无法读取该库格式”的错误消息。因此,如果g++不能处理.lib文件,那么为什么它们一开始就可用呢?这是否不可能让任何C++编译器即使在.SO格式中不可用也不可能使用库文件?我所说的“我知道它们链接正确”,是指我花了一个小时解决了“库未连接”问题,然后最终解决了它。我不理解你的问题,我已经说过它们与
cl
一起工作。