来自.dll库的函数的未定义引用

时间:2015-11-06 21:00:25

标签: c++ dll codeblocks

前言:我在Windows 10机器上使用Code :: Blocks软件并使用C ++编程。我正在使用Princeton Instruments Scientific CCD相机的库。

我会尽量在这里尽可能具体。我正在尝试使用控制普林斯顿仪器相机(PIcam)的多个功能创建.dll文件。我正在制作这个.dll,因为我想在不同的Python程序中嵌入这个代码(在C ++中)。这是我目前相关的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" );
    }
}

但是在构建代码之后编译器给出了these错误。它声称我调用的每个函数都是一个未定义的引用,即使我成功链接了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))

我不知道还有什么可以解决这个问题。似乎一切都是正确的,但功能仍然无法在库中识别。有没有人有任何想法?

1 个答案:

答案 0 :(得分:-1)

  

我知道我的库已正确链接。

那么你好了,不是你!

但是,如果您愿意保持开放的态度并真正理解链接过程,那么您应该知道gcc(您正在使用的)并不知道如何处理{{ 1}}文件,他们是Microsoft库文件。 gcc的库文件以#include <stdio.h> #include <stdlib.h> #define NUM_HILOS 10 //array elements (no threads) struct datos //modified for use as array, no threads { float pi; //PI }; void calcPi (struct datos *d) { struct datos *datos_proceso = d; float pi = datos_proceso[0].pi; int signo = 1; int i; for(i=0;i<NUM_HILOS;i++) { pi = pi + (signo*4.0)/((2*i)+1); signo *= -1; d[i].pi = pi; //change values for NUM_HILOS to see how //values for pi converge here. } } int main() { int error, i; float pi = 0; int j = -1; //your comment: I think that the error... //... (The error you were seeing here was //caused by an uninitialized float *pi; which has been //changed to float pi = 0; in this example) struct datos hilo_datos[NUM_HILOS]; for(i=0; i<NUM_HILOS; i++) { hilo_datos[i].pi = 0; //initialize all to zero } calcPi(hilo_datos);//send array of struct, check all elelments when returned for(i=0; i<NUM_HILOS; i++) { printf("este es pi %f \n", hilo_datos[i].pi); } getchar(); return 0; } .lib结尾。