简体   繁体   中英

Undefined Reference to Functions from .dll Library

Preface: I am using Code::Blocks software on a Windows 10 Machine and programming in C++. I am using libraries for the Princeton Instruments Scientific CCD camera.

I will try to be a specific as possible here. I am attempting to create a .dll file using multiple functions that control a Princeton Instruments Camera (PIcam). I am making this .dll because I want to embed this code (which is in C++) in a different Python program. Here is my current relevant main.cpp code:

#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" );
    }
}

But the compiler gives me these errors after I build my code. It claims that every single function I called is an undefined reference, even after I successfully linked the libraries in Code::Blocks.

I know that my libraries are linked correctly. All of these functions lie in the library Picam.lib, which I know is linked correctly. Here is the build-log code to show it:

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))

I do not know what else to do to fix this. It seems like everything is right but the functions still cannot be identified in the library. Does anyone have any ideas?

I know that my libraries are linked correctly.

Well then you're set, aren't you!

However if you're willing to keep an open mind and actually understand the linking process, you should probably know that gcc (which you're using) doesn't know what to do with .lib files, they're Microsoft library files. gcc's library files end with .a or .so .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM