build my own library with Cmake in Qt6
-
thanks for answer,
i have tried to build a small dynamish linked libary called mylib, it is built with Cmake and i got the libmylib.dll and libmylib.dll.a, i try to reuse it in my another program, i include it like "#include "mylib"" but it is not recognized,showing "no such file or directory".
I dont know how to make it recognized. Maybe some path setting in CMakeList.text.
I try to set some path in CMakeText.text, but maybe the setting is not correct. Many tutorials are showd with Qmake, it help litte.my cmake text:
cmake_minimum_required(VERSION 3.14)
project(libPing LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)add_library(libPing SHARED
libPing_global.h
libping.cpp
libping.h
)target_link_libraries(libPing PRIVATE Qt${QT_VERSION_MAJOR}::Core)
target_compile_definitions(libPing PRIVATE LIBPING_LIBRARY)
target_include_directories(libPing INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
-
thanks for answer,
i have tried to build a small dynamish linked libary called libPing, it is built with Cmake and i got the liblibPing.dll and liblibPing.dll.a, i try to reuse it in my another program, i include it like "#include "libPing"" but it is not recognized,showing "no such file or directory".
I dont know how to make it recognized. Maybe some path setting in CMakeList.text.
I try to set some path in CMakeText.text, but maybe the setting is not correct. Many tutorials are showd with Qmake, it help litte.my cmake text:
cmake_minimum_required(VERSION 3.14)project(libPing LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)add_library(libPing SHARED
libPing_global.h
libping.cpp
libping.h
)target_link_libraries(libPing PRIVATE Qt${QT_VERSION_MAJOR}::Core)
target_compile_definitions(libPing PRIVATE LIBPING_LIBRARY)
target_include_directories(libPing INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
-
@withwind I wanted to see your CMakeLists.txt where you are ADDING your library to the project, not the one to build library itself. So, please show CMakeLists.txt from the project which USES the library. In that CMakeLists.txt you need to link your library to your project using https://cmake.org/cmake/help/latest/command/target_link_libraries.html
-
@jsulm
thanks again!
that means, for using the custom library, man have to set the CMakeLists.txt in the project. The CMakeLists.txt is:cmake_minimum_required(VERSION 3.14)
project(demoPing LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)add_executable(demoPing
main.cpp
)
target_link_libraries(demoPing Qt${QT_VERSION_MAJOR}::Core)install(TARGETS demoPing
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) -
@withwind said in build my own library with Cmake in Qt6:
target_link_libraries(demoPing Qt${QT_VERSION_MAJOR}::Core)
No wonder it does not work: you do not link your lib to your executable...
-
@withwind I already did above: "you need to link your library to your project using https://cmake.org/cmake/help/latest/command/target_link_libraries.html"