Importing libraries on Windows and Linux

I have CmakeLists.txt that below:

cmake_minimum_required(VERSION 3.2)
project(scanner CXX)

set(CMAKE_CXX_STANDARD 17)
set(CONAN_DISABLE_CHECK_COMPILER "1")
set(SOURCES
    src/main.cpp
    src/utility.cpp)

set(HEADERS
    src/utility.h)
	
add_subdirectory(src/hidapi)
add_subdirectory(src/utfcpp)

add_library(hidposapi STATIC IMPORTED GLOBAL)
set_property(TARGET hidposapi APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(hidposapi PROPERTIES
	IMPORTED_LINK_INTERAFACE_LANGUAGES_DEBUG "CXX"
	IMPORTED_LOCATION_DEBUG "src/hidposapi/HidPosApi.lib")

#if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
#    include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
#    conan_basic_setup()
#else()
#    message(WARNING "The file conanbuildinfo.cmake doesn't exist, you have to run conan install first")
#endif()

#set(Boost_USE_STATIC_LIBS ON)
set(BUILD_SHARED_LIBS FALSE)
add_compile_definitions(_WIN32_WINNT=0x0601)

#find_package(Boost COMPONENTS filesystem regex json log REQUIRED)
#find_package(Protobuf REQUIRED)

#if(Boost_FOUND)
 #   include_directories(${Boost_INCLUDE_DIRS})
    add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})
 #  target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
    target_link_libraries(${PROJECT_NAME} PRIVATE hidapi::hidapi utf8cpp hidposapi)
 #	target_link_libraries(${PROJECT_NAME} PRIVATE hidposapi)
#endif()

Boost is not used tempoparily

I got an error:
LINK : fatal error LNK1104: не удается открыть файл “src\hidposapi\HidPosApi.lib” [D:\Mertech\scanner\build\scanner.vcx
proj]

What shouild I do to resolve? src/hidposapi/ contains HidPosApi.h, .lib, .dll

Have you tried using an absolute path when specifying the IMPORTED_LOCATION_DEBUG? Most of the time that I use an explicit import target I’m usually using full paths. I would guess the link command may be running from the binary directory which means that a relative path wouldn’t refer to the thing you think it does, at least in this situation.

Good! Thanks! There no more cursing at me from CMAKE, but I forgot to include one. h and now another error. Please, help with this too:

+set(HEADERS
    src/utility.h
	src/hidposapi/HidPosApi.h)

D:\Mertech\scanner\src\utility.h(7,10): fatal error C1083: hidposapi/HidPosApi.h: N
o such file or directory, [D:\Mertech\scanner\build\scanner.vcxproj]

image

UP
Problem solved, but

**main.obj : error LNK2019: reference to an unresolved external character "bool __cdecl GetDeviceSn(char ,int )" (?GetDeviceSn @@YA_NPEADPEAH@Z).
@@YA_NPEADPEAH@Z)。[D:\Mertech\scanner\build\scanner.vcxproj].

It’s likely to see no lib we are talking about

At this point you’d have to look into the generated project files and make sure they look good. Double check that your prebuilt DLL is exporting symbols properly and all that. Beyond that, I can’t help much more.