# Library not found (Windows)

**URL:** <https://discourse.cmake.org/t/library-not-found-windows/574>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [February 4, 2020, 10:32am UTC](https://discourse.cmake.org/t/library-not-found-windows/574 "2020-02-04T10:32:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lander](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lander/32/331_2.png) [@Lander](https://discourse.cmake.org/u/Lander)\
**Post date:** [February 4, 2020, 10:32am UTC](https://discourse.cmake.org/t/library-not-found-windows/574/1 "2020-02-04T10:32:42Z")

</div>

Hello! This is my first post here!

I am trying to do my first project with CMake and I am stuck. I am working with windows.

Please, can you help me?

Currently, there are two issues:

- I am trying to include an external library called GCLib, but CMake does not find it.
- If I copy the library to the output folder then a message appears telling me that there are undefined symbols. I included gc.h but (I suppose) the linker is not linking them properly:

> Severity Code Description Project File Line Suppression State  
> Error LNK1120 2 unresolved externals C:\multiDimIndex\out\build\x64-Debug\multiDimIndex C:\multiDimIndex\out\build\x64-Debug\multiDimIndex.exe 1   
> Error LNK2019 unresolved external symbol \_\_imp\_GC\_init referenced in function main C:\multiDimIndex\out\build\x64-Debug\multiDimIndex C:\multiDimIndex\out\build\x64-Debug\multiDimIndex.cpp.obj 1   
> Error LNK2019 unresolved external symbol \_\_imp\_GC\_malloc referenced in function main C:\multiDimIndex\out\build\x64-Debug\multiDimIndex C:\multiDimIndex\out\build\x64-Debug\multiDimIndex.cpp.obj 1

My current file list:

 ![image](https://discourse.cmake.org/uploads/default/original/1X/4417de768d62a25c207e4604aeeeffb2d6602841.png)

My current CMakeList is:

> # CMakeList.txt : CMake project for multiDimIndex, include source and define
> 
> # project specific logic here.
> 
> # 
> 
> project(multiDimIndex)  
> cmake\_minimum\_required (VERSION 3.8)  
> message(STATUS “--------------------- Testing”)
> 
> # Add source to this project’s executable.
> 
> message("---- CMAKE\_SOURCE\_DIR = " ${CMAKE\_SOURCE\_DIR})
> 
> include\_directories(${CMAKE\_SOURCE\_DIR}/gclib)  
> link\_directories(${CMAKE\_SOURCE\_DIR}/gclib)  
> find\_path(GCLIB\_INCLUDE\_DIR ${CMAKE\_SOURCE\_DIR}/gclib/gc.h)  
> find\_library(GCLIB\_LIBRARY gc-lib)
> 
> message (“-- " ${CMAKE\_SOURCE\_DIR}/gclib/gc.h)  
> message(”-- " ${GCLIB\_INCLUDE\_DIR})  
> message("-- " ${GCLIB\_LIBRARY})  
> set(YOUR\_LIBRARIES)
> 
> if (GCLIB\_INCLUDE\_DIR AND GCLIB\_LIBRARY)  
> # you may need that if further action in your CMakeLists.txt depends  
> # on detecting your library  
> set(GCLIB\_FOUND TRUE)
> 
> ```
> # you may need that if you want to conditionally compile some parts
> # of your code depending on library availability
> add_definitions(-DHAVE_GCLIB=1)
> 
> # those two, you really need
> include_directories(${GCLIB_INCLUDE_DIR})
> set(YOUR_LIBRARIES ${YOUR_LIBRARIES} ${GCLIB_LIBRARY})
> 
> ```
> 
> endif ()
> 
> configure\_file(multiDimIndex.config.h.in multiDimIndex.config.h) #fichero donde poner configuraciones para el proyecto ()
> 
> add\_library(format format.cpp)
> 
> add\_executable (multiDimIndex “multiDimIndex.cpp” “multiDimIndex.h” ) #“…/PruebaGC/include/gc.h”) “./gc-lib/gc.h”  
> #target\_link\_libraries(multiDimIndex ${YOUR\_LIBRARIES})  
> set(YOUR\_LIBRARIES ${YOUR\_LIBRARIES} format)  
> message ("=== libraries " ${YOUR\_LIBRARIES})  
> target\_link\_libraries(multiDimIndex ${YOUR\_LIBRARIES})  
> #target\_link\_libraries(multiDimIndex gc-lib format)
> 
> target\_include\_directories(multiDimIndex PUBLIC  
> “${PROJECT\_BINARY\_DIR}”  
> )

When CMake is run, this is the output:

> 2\> CMake generation started for configuration: ‘x64-Debug’.  
> 2\> Command line: “cmd.exe” /c ““C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe” -G “Ninja” -DCMAKE\_INSTALL\_PREFIX:PATH=“C:\multiDimIndex\out\install\x64-Debug” -DCMAKE\_CXX\_COMPILER:FILEPATH=“C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/HostX64/x64/cl.exe” -DCMAKE\_C\_COMPILER:FILEPATH=“C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/HostX64/x64/cl.exe” -DCMAKE\_BUILD\_TYPE=“Debug” -DCMAKE\_MAKE\_PROGRAM=“C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe” “C:\multiDimIndex” 2\>&1”  
> 2\> Working directory: C:\multiDimIndex\out\build\x64-Debug  
> 2\> [CMake] – --------------------- Testing  
> 2\> [CMake] ---- CMAKE\_SOURCE\_DIR = C:/multiDimIndex  
> 2\> [CMake] – C:/multiDimIndex/gclib/gc.h  
> **2\> [CMake] – GCLIB\_INCLUDE\_DIR-NOTFOUND**  
> **2\> [CMake] – GCLIB\_LIBRARY-NOTFOUND**  
> 2\> [CMake] === librerías format  
> 2\> [CMake] – Configuring done  
> 2\> [CMake] – Generating done  
> 2\> [CMake] – Build files have been written to: C:/multiDimIndex/out/build/x64-Debug  
> 2\> [CMake]  
> 2\> Extracted includes paths.  
> 2\> Extracted CMake variables.  
> 2\> Extracted source files and headers.  
> 2\> Extracted code model.  
> 2\> CMake generation finished.

Thank in advance!

---

<div class="post-metadata">

**Author:** ![Lander](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lander/32/331_2.png) [@Lander](https://discourse.cmake.org/u/Lander)\
**Post date:** [February 4, 2020, 10:33am UTC](https://discourse.cmake.org/t/library-not-found-windows/574/2 "2020-02-04T10:33:15Z")

</div>

![image](https://discourse.cmake.org/uploads/default/original/1X/d3f7b5130282eb512666a23afd98c7826cbeb5ab.png)

---

<div class="post-metadata">

**Author:** ![Lander](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lander/32/331_2.png) [@Lander](https://discourse.cmake.org/u/Lander)\
**Post date:** [February 4, 2020, 10:35am UTC](https://discourse.cmake.org/t/library-not-found-windows/574/3 "2020-02-04T10:35:02Z")

</div>

I am not sure what I am doing wrong to include the gc.h.

![image](https://discourse.cmake.org/uploads/default/original/1X/a3347899f4079fd905f318e0d4ccdd91d5f92c1a.png)

---

<div class="post-metadata">

**Author:** ![Lander](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lander/32/331_2.png) [@Lander](https://discourse.cmake.org/u/Lander)\
**Post date:** [February 4, 2020, 1:40pm UTC](https://discourse.cmake.org/t/library-not-found-windows/574/4 "2020-02-04T13:40:09Z")

</div>

WTF… after installing the SDKs as suggested [here](https://stackoverflow.com/questions/9356135/link-fatal-error-lnk-1104-cannot-open-file-libcmt-lib) the CMake output is longer.

So with the next CMakeList.txt…

> # CMakeList.txt : CMake project for multiDimIndex, include source and define
> 
> # project specific logic here.
> 
> # 
> 
> project(multiDimIndex)  
> cmake\_minimum\_required (VERSION 3.8)  
> message(STATUS “--------------------- Testing”)
> 
> # Add source to this project’s executable.
> 
> message("---- CMAKE\_SOURCE\_DIR = " ${CMAKE\_SOURCE\_DIR})
> 
> include\_directories(${CMAKE\_SOURCE\_DIR}/gclib)  
> link\_directories(${CMAKE\_SOURCE\_DIR}/gclib)  
> find\_path(GCLIB\_INCLUDE\_DIR ${CMAKE\_SOURCE\_DIR}/gclib/gc.h)  
> find\_library(GCLIB\_LIBRARY “.\gc-lib”)
> 
> message (“-- " ${CMAKE\_SOURCE\_DIR}/gclib/gc.h)  
> message(”–=== " ${GCLIB\_INCLUDE\_DIR})  
> message("–=== " ${GCLIB\_LIBRARY})  
> set(YOUR\_LIBRARIES)
> 
> if (GCLIB\_INCLUDE\_DIR AND GCLIB\_LIBRARY)  
> # you may need that if further action in your CMakeLists.txt depends  
> # on detecting your library  
> set(GCLIB\_FOUND TRUE)
> 
> ```
> # you may need that if you want to conditionally compile some parts
> # of your code depending on library availability
> add_definitions(-DHAVE_GCLIB=1)
> 
> # those two, you really need
> include_directories(${GCLIB_INCLUDE_DIR})
> set(YOUR_LIBRARIES ${YOUR_LIBRARIES} ${GCLIB_LIBRARY})
> 
> ```
> 
> endif ()
> 
> configure\_file(multiDimIndex.config.h.in multiDimIndex.config.h) #fichero donde poner configuraciones para el proyecto ()
> 
> add\_library(format format.cpp)
> 
> add\_executable (multiDimIndex “multiDimIndex.cpp” “multiDimIndex.h” “${CMAKE\_SOURCE\_DIR}/gclib/gc.h”) #“…/PruebaGC/include/gc.h”) “./gc-lib/gc.h”  
> #target\_link\_libraries(multiDimIndex ${YOUR\_LIBRARIES})  
> set(YOUR\_LIBRARIES ${YOUR\_LIBRARIES} format)  
> message ("========= libraries = " ${YOUR\_LIBRARIES})  
> target\_link\_libraries(multiDimIndex ${YOUR\_LIBRARIES})  
> #target\_link\_libraries(multiDimIndex gc-lib format)
> 
> target\_include\_directories(multiDimIndex PUBLIC  
> “${PROJECT\_BINARY\_DIR}”  
> )

… we obtain:

> 1\> CMake generation started for configuration: ‘x64-Debug’.  
> 1\> Command line: “cmd.exe” /c ““C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe” -G “Ninja” -DCMAKE\_INSTALL\_PREFIX:PATH=“C:\multiDimIndex\out\install\x64-Debug” -DCMAKE\_CXX\_COMPILER:FILEPATH=“C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/HostX64/x64/cl.exe” -DCMAKE\_C\_COMPILER:FILEPATH=“C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/HostX64/x64/cl.exe” -DCMAKE\_BUILD\_TYPE=“Debug” -DCMAKE\_MAKE\_PROGRAM=“C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe” “C:\multiDimIndex” 2\>&1”  
> 1\> Working directory: C:\multiDimIndex\out\build\x64-Debug  
> 1\> [CMake] – --------------------- Testing  
> 1\> [CMake] ---- CMAKE\_SOURCE\_DIR = C:/multiDimIndex  
> 1\> [CMake] – C:/multiDimIndex/gclib/gc.h  
> 1\> [CMake] --=== GCLIB\_INCLUDE\_DIR-NOTFOUND  
> 1\> [CMake] --=== GCLIB\_LIBRARY-NOTFOUND  
> 1\> [CMake] ========= libraries = format  
> 1\> [CMake] – Configuring done  
> 1\> [CMake] – Generating done  
> 1\> [CMake] – Build files have been written to: C:/multiDimIndex  
> 1\> [CMake]  
> 1\> Extracted includes paths.  
> 1\> Extracted CMake variables.  
> 1\> Extracted source files and headers.  
> 1\> Extracted code model.  
> 1\> CMake generation finished.

But still…  
 ![image](https://discourse.cmake.org/uploads/default/original/1X/fb697037c5da33d36e6c74f6ac5a0ad06edbd7d8.png)

---

<div class="post-metadata">

**Author:** ![Lander](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lander/32/331_2.png) [@Lander](https://discourse.cmake.org/u/Lander)\
**Post date:** [February 4, 2020, 3:25pm UTC](https://discourse.cmake.org/t/library-not-found-windows/574/5 "2020-02-04T15:25:49Z")

</div>

Ok, I found that CMakeSettings.json is needed. I found it just by chance in VS. After setting there the values it finds the library but it still says unresolved external symbol GC\_init.

---

<div class="post-metadata">

**Author:** ![Lander](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lander/32/331_2.png) [@Lander](https://discourse.cmake.org/u/Lander)\
**Post date:** [February 4, 2020, 5:40pm UTC](https://discourse.cmake.org/t/library-not-found-windows/574/6 "2020-02-04T17:40:06Z")

</div>

Now trying with a different CMakeList.txt I obtain a different result (I have added spaces before and after @):

> cmake\_minimum\_required (VERSION 3.8)  
> project(multiDimIndex)
> 
> ADD\_DEFINITIONS(-DGC\_NOT\_DLL)  
> add\_executable (multiDimIndex WIN32 “multiDimIndex.cpp” “multiDimIndex.h” “${CMAKE\_SOURCE\_DIR}/gclib/gc.h”) #“…/PruebaGC/include/gc.h”) “./gc-lib/gc.h”  
> TARGET\_LINK\_LIBRARIES(multiDimIndex gc-lib)

> Severity Code Description Project File Line Suppression State  
> Error LNK2019 unresolved external symbol “class std::basic\_string\<char,struct std::char\_traits,class std::allocator \> \_\_cdecl binary(unsigned \_\_int64)” (?binary@@YA?AV?$basic\_string@DU?$char\_traits @ D @ std @ @ V?$allocator @ D @ 2 @ @ std @ @ \_K @ Z) referenced in function main C:\multiDimIndex\out\build\x64-Debug\multiDimIndex C:\multiDimIndex\out\build\x64-Debug\multiDimIndex.cpp.obj 1   
> Error LNK2019 unresolved external symbol WinMain referenced in function “int \_\_cdecl invoke\_main(void)” (?invoke\_main @ @ YAHXZ) C:\multiDimIndex\out\build\x64-Debug\multiDimIndex C:\multiDimIndex\out\build\x64-Debug\MSVCRTD.lib(exe\_winmain.obj) 1

 ![image](https://discourse.cmake.org/uploads/default/original/1X/e4885864bdf26019b90a0cae953949cbc21bc957.png)

---

<div class="post-metadata">

**Author:** ![Lander](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lander/32/331_2.png) [@Lander](https://discourse.cmake.org/u/Lander)\
**Post date:** [February 7, 2020, 3:39pm UTC](https://discourse.cmake.org/t/library-not-found-windows/574/7 "2020-02-07T15:39:45Z")

</div>

ok, it ended working on windows with the next CMakeList.txt:

> cmake\_minimum\_required (VERSION 3.8)  
> project(multiDimIndex)
> 
> add\_library(format format.cpp)  
> ADD\_DEFINITIONS(-DGC\_NOT\_DLL)  
> add\_executable (multiDimIndex “multiDimIndex.cpp” “multiDimIndex.h” “${CMAKE\_SOURCE\_DIR}/gclib/gc.h”) #“…/PruebaGC/include/gc.h”) “./gc-lib/gc.h”  
> TARGET\_LINK\_LIBRARIES(multiDimIndex gc-lib format)
