I am using Sapera++ (API for a camera) to write a code in Qt. Here is my .pro file (where I define the libraries and path):
#-------------------------------------------------
#
# 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'
The Classes\Basic folder contains all the header files.
The 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;
}
After I run the code, I get the following errors:
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
It seems there are some stuffs not defined regarding to my "Sap" library, although I have included everything in .pro file.
Solution: I have downloaded and installed the MSVC15 version of Qt from its website and also installed Microsoft Visual Studio 2015 (So the Microsoft Visual c++ compilers will be installed too). Then in qt compilers I added the Microsoft Visual c++ compiler as my main compiler. Now it works :)