我正在使用Sapera ++(相机的API)在Qt中编写代码。这是我的.pro文件(我定义了库和路径):
#-------------------------------------------------
#
# Project created by QtCreator 2017-11-08T10:35:39
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test2
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
INCLUDEPATH += 'C:\Program Files\Teledyne DALSA\Sapera\Classes\Basic'
INCLUDEPATH += 'C:\Program Files\Teledyne DALSA\Sapera\Include'
INCLUDEPATH += 'C:\Program Files\Teledyne DALSA\Sapera\Lib'
LIBS += 'C:\Program Files\Teledyne DALSA\Sapera\Lib\Win64\SapClassBasic.lib'
Classes \ Basic文件夹包含所有头文件。
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "SapClassBasic.h"
#include "SapAcquisition.h"
HWND disp;
bool success;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
disp = (HWND) ui->graphicsView->winId();
SapAcquisition *pAcq = new SapAcquisition(SapLocation("Xtium-CLHS_PX4_1", 0), "test.ccf");
SapBuffer *pBuffer = new SapBuffer(1, pAcq);
SapView *pView = new SapView(pBuffer, disp);
}
MainWindow::~MainWindow()
{
delete ui;
}
运行代码后,我收到以下错误:
In function `ZN10MainWindowC2EP7QWidget':
D:\Qt-Projects\build-test2-Desktop_Qt_5_9_2_MinGW_32bit-Debug/../test2/mainwindow.cpp:18: undefined reference to `_imp___ZN11SapLocationC1EPKci'
D:\Qt-Projects\build-test2-Desktop_Qt_5_9_2_MinGW_32bit-Debug/../test2/mainwindow.cpp:18: undefined reference to `_imp___ZN14SapAcquisitionC1E11SapLocationPKcyPFvP18SapAcqCallbackInfoEPv'
D:\Qt-Projects\build-test2-Desktop_Qt_5_9_2_MinGW_32bit-Debug/../test2/mainwindow.cpp:19: undefined reference to `_imp___ZN11SapLocationC1Eii'
D:\Qt-Projects\build-test2-Desktop_Qt_5_9_2_MinGW_32bit-Debug/../test2/mainwindow.cpp:19: undefined reference to `_imp___ZN9SapBufferC1EiP11SapXferNodei11SapLocation'
D:\Qt-Projects\build-test2-Desktop_Qt_5_9_2_MinGW_32bit-Debug/../test2/mainwindow.cpp:20: undefined reference to `_imp___ZN7SapViewC1EP9SapBufferP6HWND__PFvP19SapViewCallbackInfoEPv'
debug/mainwindow.o: In function `ZN11SapLocationD1Ev':
C:/Program Files/Teledyne DALSA/Sapera/Classes/Basic/SapManager.h:38: undefined reference to `_imp___ZTV11SapLocation'
collect2.exe: error: ld returned 1 exit status
似乎有些东西没有定义我的“Sap”库,虽然我已经将所有东西都包含在.pro文件中。
解决方案:我已经从其网站下载并安装了MSV的MSVC15版本,并且还安装了Microsoft Visual Studio 2015(因此也将安装Microsoft Visual c + +编译器)。然后在qt编译器中,我添加了Microsoft Visual c ++编译器作为我的主编译器。现在它工作:)
在您的项目文件(.pro)中添加如下库:
LIBS += -L[path to library] -l[library]
例
LIBS += -L"C:\Program Files\Teledyne DALSA\Sapera\Lib\Win64\" -lSapClassBasic.lib