# Difficulty importing a library

**URL:** https://discourse.cmake.org/t/difficulty-importing-a-library/13663
**Category:** Code
**Created:** [March 2, 2025, 6:29pm UTC](https://discourse.cmake.org/t/difficulty-importing-a-library/13663 "2025-03-02T18:29:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![CBreak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/8c91f0/32.png) [@CBreak](https://discourse.cmake.org/u/CBreak)
#### Post date: [March 2, 2025, 6:29pm UTC](https://discourse.cmake.org/t/difficulty-importing-a-library/13663/1 "2025-03-02T18:29:58Z")

</div>

Hi, as will be apparent I am new to using CMake. I’m using CLion in Windows with the visual studio 2019 toolchain, and I’m trying to import a library to use and I’m having trouble.

The library is copied to the top of the project, in the folder next to main. The project structure looks like this:

```
CMakeLists.txt
main.cpp
testClass/testClass.h
testClass/testClass.cpp
libName/DLL/THE_LIB.dll
libName/Lib/THE_LIB.lib
libName/Include/THE_LIB.h
libName/Include/VariousOthers1.h
libName/Include/VariousOthers2.h

```

The Cmake file looks like this:

```
cmake_minimum_required(VERSION 3.30)
project(untitled)

set(CMAKE_CXX_STANDARD 20)

add_executable(untitled main.cpp
    testClass/testClass.cpp
    testClass/testClass.h)

target_link_libraries(untitled C:/path/to/lib/libName/Lib/THE_LIB.lib)

```

main:

```
#include "testClass/testClass.h"

#include "libName/Include/THE_LIB.h"
#include "libName/Include/VariousOthers1.h"
#include "libName/Include/VariousOthers2.h"

int main() {
    libNameClass instance = libNameClass();
    testClass greeter = testClass();
    greeter.greet();
    return 0;
}

```

If I comment out the libNameClass and the #includes relating to it, it works fine (testClass prints hello world). If I leave them in, I get an error and a warning:

“error LNK2019: unresolved external symbol” relating to the libNameClass  
“warning LNK4272: library machine type ‘x86’ conflicts with target machine type ‘x64’”

Have I made an error with my CMake file, or is the error due to the warning, and is there an obvious way to get around the warning? I would have thought 64 bit machines oculd run 32 bit libraries (and I’m not sure why this warning is coming up, as the library is relatively recent).

Thanks

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [March 2, 2025, 9:02pm UTC](https://discourse.cmake.org/t/difficulty-importing-a-library/13663/2 "2025-03-02T21:02:28Z")

</div>

> [@CBreak](#):
>
> “error LNK2019: unresolved external symbol” relating to the libNameClass  
> “warning LNK4272: library machine type ‘x86’ conflicts with target machine type ‘x64’”
> 
> Have I made an error with my CMake file, or is the error due to the warning, and is there an obvious way to get around the warning? I would have thought 64 bit machines oculd run 32 bit libraries

You are linking a 32bit library but you are building a 64bit program. You can run x86 **programs** on a x64 Windows but the parts of a program must match.

---

<div class="post-metadata">

### Author: ![CBreak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/8c91f0/32.png) [@CBreak](https://discourse.cmake.org/u/CBreak)
#### Post date: [March 2, 2025, 10:34pm UTC](https://discourse.cmake.org/t/difficulty-importing-a-library/13663/3 "2025-03-02T22:34:29Z")

</div>

> [@hsattler](#):
>
> You are linking a 32bit library but you are building a 64bit program. You can run x86 **programs** on a x64 Windows but the parts of a program must match.

Ok, so if the lilbrary were 64 bit then the CMake commands I’ve used should work, I’ve just got the wrong version of a library? That’s good to know, thank you for your help!

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [March 2, 2025, 10:51pm UTC](https://discourse.cmake.org/t/difficulty-importing-a-library/13663/4 "2025-03-02T22:51:09Z")

</div>

You should also not use Windows-style path in cmake.

---

<div class="post-metadata">

### Author: ![CBreak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/8c91f0/32.png) [@CBreak](https://discourse.cmake.org/u/CBreak)
#### Post date: [March 2, 2025, 11:00pm UTC](https://discourse.cmake.org/t/difficulty-importing-a-library/13663/5 "2025-03-02T23:00:30Z")

</div>

In favour of:

```
${PROJECT_SOURCE_DIR}/libName/Lib/THE_LIB.lib

```

presumably? I had been trying to use that, but either way it doesn’t work for the more fundamental x86 vs x64 reason you outlined above. Thanks again for your help!
