1

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

Soroor
  • 13
  • 5
  • There are probably some dependent libraries too that define the missing symbols. – vahancho Nov 08 '17 at 10:28
  • I have included everything, I mean there are specific folders when I installed the corresponding software. So that's all I have. – Soroor Nov 08 '17 at 14:46
  • `ld returned 1 exit status` So you're using GNU C++. Was the Sapera++ also compiled with GNU C++? .lib extension could be a hint that it was not. – Matt Nov 08 '17 at 14:59
  • @Matt The demos are written with MFC in visual studio. So what should I do now in Qt? – Soroor Nov 08 '17 at 15:06
  • Either use Qt built for MSVC, or get Sapera++ compiled by/for GNU. – Matt Nov 08 '17 at 15:15
  • How can I get the Qt built for MSVC? Is it another version of Qt or it is just like an add-on or something? – Soroor Nov 08 '17 at 15:25
  • It is a Qt library compiled with Microsoft compiler. You can get it from the Qt official site. In general, you cannot mix C++ modules compiled with different compilers in a single application. (BTW. You'll also need MS Visual Studio with integrated MSVC compiler for application development, as directly stated in Sapera SDK User manual). – Matt Nov 09 '17 at 07:31
  • Thanks for your explanation. So to just make sure that I got your point: There is no possibility to develop an application for Sapera++ in Qt and finally I need to install visual studio. – Soroor Nov 10 '17 at 09:34
  • I have followed this: https://forum.qt.io/topic/40705/qt-creator-using-visual-studio-compiler/6 It was the same problem as mine, so I downloaded the qt version for 64bit Windows with MSVC 2015. But now I get this error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl SapLocation......" – Soroor Nov 10 '17 at 17:29

1 Answers1

0

In your project file (.pro) add library like this:

LIBS += -L[path to library] -l[library]

Example

LIBS += -L"C:\Program Files\Teledyne DALSA\Sapera\Lib\Win64\" -lSapClassBasic.lib
svm
  • 392
  • 3
  • 9
  • Are you sure about the -lSapClassBasic.lib? Because I get error that quote is missing and I cannot run my code. – Soroor Nov 08 '17 at 14:48
  • @Soroor check [documentation](http://doc.qt.io/qt-5/qmake-project-files.html#declaring-other-libraries) – svm Nov 08 '17 at 14:56
  • Try delete quotes from library path and delete extension from library name – svm Nov 08 '17 at 14:59
  • Perhaps problem in spaces for path library. Try `-LC:\Program/ Files\Teledyne/ DALSA\Sapera\Lib\Win64` – svm Nov 08 '17 at 15:11