0

I'm making a project Qt + CMake and I want to use an API (cp-library) which was prebuilt and consists of *.h and *.dll files. I've succeeded to include headers, but not the link library itself.

mainwindow.cpp:31: undefined reference to `getStLinkList'

#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <cp-library/CubeProgrammer_API.h>

void MainWindow::on_btnConnect_clicked()
{
    /*
    QStringList arguments;
       arguments << "STM32_Programmer_CLI.exe" <<"-c port=SWD";
    runProgrammer(arguments);
    */
    debugConnectParameters *stLinkList;
    debugConnectParameters debugParameters;
    generalInf* genInfo;

    int getStlinkListNb = getStLinkList(&stLinkList, 0);

}

main CmakeLists.txt

    cmake_minimum_required(VERSION 3.5)
    project(MY_PROJ VERSION 0.1 LANGUAGES CXX)
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_CXX_STANDARD 11)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets LinguistTools REQUIRED)
    find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets LinguistTools REQUIRED)
    
    add_subdirectory(cp-library)
    
    set(PROJECT_SOURCES
            main.cpp
            mainwindow.cpp
            mainwindow.h
            mainwindow.ui
            ${TS_FILES}
    )
    

    add_executable(MY_PROJ 
                ${PROJECT_SOURCES}
            )
        qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
    
    target_link_libraries(MY_PROJ PRIVATE Qt${QT_VERSION_MAJOR}::Widgets cp-library)
    
    
    if(QT_VERSION_MAJOR EQUAL 6)
        qt_finalize_executable(MY_PROJ )
    endif()

CmakeLists.txt for cp-library

    add_library(
    cp-library
    CubeProgrammer_API.h
    DeviceDataStructure.h
    )
    set_target_properties(cp-library PROPERTIES IMPORTED_LOCATION
        CubeProgrammer_API.dll
        HSM_P11_Lib.dll
        mfc120.dll
        stlibp11_SAM.dll
        STLinkUSBDriver.dll
        )

fakamakato
  • 25
  • 5
  • It seems you attempt to create `cp-library` target to incorporate several external libraries, but do it in a wrong way. 1. External (pre-existing) library is wrapped into **IMPORTED** library target. 2. The property [IMPORTED_LOCATION](https://cmake.org/cmake/help/latest/prop_tgt/IMPORTED_LOCATION.html) should contain exactly **one location**. If you want to combine several libraries into one target, then use `INTERFACE` library, like in [that question](https://stackoverflow.com/questions/56568570/how-to-group-multiple-library-targets-into-one-in-cmake). – Tsyvarev Dec 20 '21 at 11:42

0 Answers0