# Importing libraries on Windows and Linux

**URL:** <https://discourse.cmake.org/t/importing-libraries-on-windows-and-linux/9810>\
**Category:** Code\
**Tags:** os:linux, os:windows\
**Created:** [January 10, 2024, 7:05am UTC](https://discourse.cmake.org/t/importing-libraries-on-windows-and-linux/9810 "2024-01-10T07:05:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bobrov88](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bobrov88/32/4151_2.png) [@Bobrov88](https://discourse.cmake.org/u/Bobrov88)\
**Post date:** [January 10, 2024, 7:05am UTC](https://discourse.cmake.org/t/importing-libraries-on-windows-and-linux/9810/1 "2024-01-10T07:05:43Z")

</div>

I have CmakeLists.txt that below:

```auto
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

---

<div class="post-metadata">

**Author:** ![dnglaze](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/74df32/32.png) [@dnglaze](https://discourse.cmake.org/u/dnglaze)\
**Post date:** [January 10, 2024, 7:40am UTC](https://discourse.cmake.org/t/importing-libraries-on-windows-and-linux/9810/2 "2024-01-10T07:40:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Bobrov88](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bobrov88/32/4151_2.png) [@Bobrov88](https://discourse.cmake.org/u/Bobrov88)\
**Post date:** [January 10, 2024, 8:25am UTC](https://discourse.cmake.org/t/importing-libraries-on-windows-and-linux/9810/3 "2024-01-10T08:25:38Z")

</div>

> [@Bobrov88](#):
>
> ```auto
> 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()
> 
> ```

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:

```auto
+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](https://discourse.cmake.org/uploads/default/original/2X/b/b154a4b00036c2ed8b39b5f150bbe810fb3e2a88.png)

---

<div class="post-metadata">

**Author:** ![Bobrov88](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bobrov88/32/4151_2.png) [@Bobrov88](https://discourse.cmake.org/u/Bobrov88)\
**Post date:** [January 10, 2024, 8:46am UTC](https://discourse.cmake.org/t/importing-libraries-on-windows-and-linux/9810/4 "2024-01-10T08:46:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dnglaze](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/74df32/32.png) [@dnglaze](https://discourse.cmake.org/u/dnglaze)\
**Post date:** [January 10, 2024, 6:32pm UTC](https://discourse.cmake.org/t/importing-libraries-on-windows-and-linux/9810/5 "2024-01-10T18:32:08Z")

</div>

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.
