[英]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 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
結尾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.