title: Getting "unresolved external symbol" error with CMake and Visual Studio
body: <p>I'm trying to use Allegro5 on Windows using CMake. My "CMakeLists.txt" file is</p>
  
  <pre><code>cmake_minimum_required (VERSION 3.8)
  
  project("My Project")
  
  set(SOURCE_FILES "main.cpp")
  add_executable(core ${SOURCE_FILES})
  
  set(ALLEGRO_INCLUDE ".\\dependencies\\allegro\\include")
  set(ALLEGRO_LIB ".\\dependencies\\allegro\\lib")
  set(ALLEGRO_DYLIB ".\\dependencies\\allegro\\bin\\*.dll")
  
  include_directories(${ALLEGRO_INCLUDE})
  link_directories(${ALLEGRO_LIB})
  file(GLOB LIBRARIES ${ALLEGRO_DYLIB})
  
  target_link_libraries(core ${LIBRARIES} ${ALLEGRO_DYLIB})
  </code></pre>
  
  <p>My directory structure is:</p>
  
  <pre><code>root
  |--CMakeLists.txt
  |--main.cpp
  |--build # this is where VS project files are generated.
  |--dependencies
        |--allegro
             |--include
             |--lib
             |--bin
  </code></pre>
  
  <p>My <code>main.cpp</code>:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;allegro5/allegro.h&gt;
  
  int main(int argc, char *args[])
  {
      const int SCREEN_WIDTH = 640;
      const int SCREEN_HEIGHT = 480;
  
      ALLEGRO_DISPLAY *window = al_create_display(SCREEN_WIDTH, SCREEN_HEIGHT);
      std::system("pause");
      return 0;
  }
  </code></pre>
  
  <p>The error I'm getting is</p>
  
  <pre><code>1&gt;------ Build started: Project: core, Configuration: Debug Win32 ------
  1&gt;main.obj : error LNK2019: unresolved external symbol __imp__al_create_display referenced in function _main
  1&gt;~\root\build\Debug\core.exe : fatal error LNK1120: 1 unresolved externals
  1&gt;Done building project "core.vcxproj" -- FAILED.
  2&gt;------ Skipped Build: Project: ALL_BUILD, Configuration: Debug Win32 ------
  2&gt;Project not selected to build for this solution configuration 
  ========== Build: 0 succeeded, 1 failed, 1 up-to-date, 1 skipped ==========
  </code></pre>
  
  <p>In case if it's useful, full linker progress logs:</p>
  
  <pre><code>     1&gt;------ Build started: Project: core, Configuration: Debug Win32 ------
  1&gt;
  1&gt;Starting pass 1
  1&gt;Processed /DEFAULTLIB:msvcprtd
  1&gt;Processed /DEFAULTLIB:MSVCRTD
  1&gt;Processed /DEFAULTLIB:OLDNAMES
  1&gt;
  1&gt;Searching libraries
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\kernel32.lib:
  1&gt;    Searching C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\msvcprtd.lib:
  1&gt;      Found __RTC_CheckEsp
  1&gt;        Referenced in main.obj
  1&gt;        Loaded MSVCRTD.lib(stack.obj)
  1&gt;      Found ___xi_a
  1&gt;        Referenced in MSVCRTD.lib(exe_main.obj)
  1&gt;        Loaded MSVCRTD.lib(initializers.obj)
  1&gt;Processed /DEFAULTLIB:kernel32.lib
  1&gt; Processed /DISALLOWLIB:msvcrt.lib
  1&gt; Processed /DISALLOWLIB:libucrtd.lib
  1&gt;      Found ___guard_check_icall_fptr
  1&gt;        Referenced in MSVCRTD.lib(exe_main.obj)
  1&gt;        Loaded MSVCRTD.lib(guard_support.obj)
  1&gt;      Found ___security_cookie
  1&gt;        Referenced in MSVCRTD.lib(gs_support.obj)
  1&gt;        Loaded MSVCRTD.lib(gs_cookie.obj)
  1&gt;      Found "int __cdecl _RTC_GetSrcLine(unsigned char *,wchar_t *,unsigned long,int *,wchar_t *,unsigned long)" (?_RTC_GetSrcLine@@YAHPAEPA_WKPAH1K@Z)
  1&gt;        Referenced in MSVCRTD.lib(error.obj)
  1&gt;        Loaded MSVCRTD.lib(gs_report.obj)
  1&gt;    Searching C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\OLDNAMES.lib:
  1&gt;    Searching C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\vcruntimed.lib:
  1&gt;      Found ___std_type_info_destroy_list
  1&gt;        Referenced in MSVCRTD.lib(tncleanup.obj)
  1&gt;        Loaded vcruntimed.lib(VCRUNTIME140D.dll)
  1&gt;      Found __IMPORT_DESCRIPTOR_VCRUNTIME140D
  1&gt;        Referenced in vcruntimed.lib(VCRUNTIME140D.dll)
  1&gt;        Referenced in vcruntimed.lib(VCRUNTIME140D.dll)
  1&gt;        Referenced in vcruntimed.lib(VCRUNTIME140D.dll)
  1&gt;        Referenced in vcruntimed.lib(VCRUNTIME140D.dll)
  1&gt;        Referenced in vcruntimed.lib(VCRUNTIME140D.dll)
  1&gt;        Referenced in vcruntimed.lib(VCRUNTIME140D.dll)
  1&gt;        Loaded vcruntimed.lib(VCRUNTIME140D.dll)
  1&gt;      Found __NULL_IMPORT_DESCRIPTOR
  1&gt;        Referenced in vcruntimed.lib(VCRUNTIME140D.dll)
  1&gt;        Loaded vcruntimed.lib(VCRUNTIME140D.dll)
  1&gt;      Found VCRUNTIME140D_NULL_THUNK_DATA
  1&gt;        Referenced in vcruntimed.lib(VCRUNTIME140D.dll)
  1&gt;        Loaded vcruntimed.lib(VCRUNTIME140D.dll)
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\ucrt\x86\ucrtd.lib:
  1&gt;      Found __imp__system
  1&gt;        Referenced in main.obj
  1&gt;        Loaded ucrtd.lib(ucrtbased.dll)
  1&gt;      Found KERNEL32_NULL_THUNK_DATA
  1&gt;        Referenced in kernel32.lib(KERNEL32.dll)
  1&gt;        Loaded kernel32.lib(KERNEL32.dll)
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\user32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\gdi32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\winspool.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\shell32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\ole32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\oleaut32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\uuid.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\comdlg32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\advapi32.lib:
  1&gt;    Searching C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\msvcprtd.lib:
  1&gt;    Searching C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\MSVCRTD.lib:
  1&gt;    Searching C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\OLDNAMES.lib:
  1&gt;    Searching C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\vcruntimed.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\ucrt\x86\ucrtd.lib:
  1&gt;
  1&gt;Finished searching libraries
  1&gt;
  1&gt;Searching libraries
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\kernel32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\user32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\gdi32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\winspool.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\shell32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\ole32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\oleaut32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\uuid.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\comdlg32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\advapi32.lib:
  1&gt;    Searching C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\msvcprtd.lib:
  1&gt;    Searching C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\MSVCRTD.lib:
  1&gt;      Found ___scrt_stub_for_acrt_initialize
  1&gt;        Loaded MSVCRTD.lib(ucrt_stubs.obj)
  1&gt;    Searching C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\OLDNAMES.lib:
  1&gt;    Searching C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\vcruntimed.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\ucrt\x86\ucrtd.lib:
  1&gt;
  1&gt;Finished searching libraries
  1&gt;
  1&gt;Finished pass 1
  1&gt;
  1&gt;
  1&gt;Searching libraries
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\kernel32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\user32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\gdi32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\winspool.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\shell32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\ole32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\oleaut32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\uuid.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\comdlg32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\advapi32.lib:
  1&gt;    Searching C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\msvcprtd.lib:
  1&gt;    Searching C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\MSVCRTD.lib:
  1&gt;      Found __load_config_used
  1&gt;        Loaded MSVCRTD.lib(loadcfg.obj)
  1&gt;    Searching C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\OLDNAMES.lib:
  1&gt;    Searching C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\vcruntimed.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\ucrt\x86\ucrtd.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\kernel32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\user32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\gdi32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\winspool.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\shell32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\ole32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\oleaut32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\uuid.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\comdlg32.lib:
  1&gt;    Searching C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\advapi32.lib:
  1&gt;    Searching C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\msvcprtd.lib:
  1&gt;
  1&gt;Finished searching libraries
  1&gt;
  1&gt;Invoking rc.exe:
  1&gt; /v
  1&gt; /x
  1&gt; /fo
  1&gt; "C:\Users\xxxxx\AppData\Local\Temp\lnk{EE34E5F7-CFF6-4E0A-B531-A9BB467BAB4C}.tmp"
  1&gt; "C:\Users\xxxxx\AppData\Local\Temp\lnk{2C99769D-323C-4CED-9784-2C6DC54A8A80}.tmp"
  1&gt;Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
  1&gt;
  1&gt;Copyright (C) Microsoft Corporation.  All rights reserved.
  1&gt;
  1&gt;
  1&gt;Creating C:\Users\xxxxx\AppData\Local\Temp\lnk{EE34E5F7-CFF6-4E0A-B531-A9BB467BAB4C}.tmp
  1&gt;
  1&gt;Using codepage 1252 as default
  1&gt;
  1&gt;C:\Users\xxxxx\AppData\Local\Temp\lnk{2C99769D-323C-4CED-9784-2C6DC54A8A80}.tmp.
  1&gt;Writing 24:1, lang:0x409, size 381
  1&gt;
  1&gt;Invoking cvtres.exe:
  1&gt; /machine:x86
  1&gt; /verbose
  1&gt; /out:"C:\Users\xxxxx\AppData\Local\Temp\lnk{78C2B88C-BF43-4FC2-B0ED-A99EAE9D6EFC}.tmp"
  1&gt; /readonly
  1&gt; "C:\Users\xxxxx\AppData\Local\Temp\lnk{EE34E5F7-CFF6-4E0A-B531-A9BB467BAB4C}.tmp"
  1&gt;Microsoft (R) Windows Resource To Object Converter Version 14.16.27030.1
  1&gt;Copyright (C) Microsoft Corporation.  All rights reserved.
  1&gt;
  1&gt;adding resource. type:MANIFEST, name:1, language:0x0409, flags:0x30, size:381
  1&gt;
  1&gt;main.obj : error LNK2019: unresolved external symbol __imp__al_create_display referenced in function _main
  1&gt;
  1&gt;Unused libraries:
  1&gt;  C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\user32.lib
  1&gt;  C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\gdi32.lib
  1&gt;  C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\winspool.lib
  1&gt;  C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\shell32.lib
  1&gt;  C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\ole32.lib
  1&gt;  C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\oleaut32.lib
  1&gt;  C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\uuid.lib
  1&gt;  C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\comdlg32.lib
  1&gt;  C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x86\advapi32.lib
  1&gt;  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\msvcprtd.lib
  1&gt;  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x86\OLDNAMES.lib
  1&gt;
  1&gt;C:\Users\xxxxx\xxxxx\root\build\Debug\core.exe : fatal error LNK1120: 1 unresolved externals
  1&gt;Done building project "core.vcxproj" -- FAILED.
  2&gt;------ Skipped Build: Project: ALL_BUILD, Configuration: Debug Win32 ------
  2&gt;Project not selected to build for this solution configuration 
  ========== Build: 0 succeeded, 1 failed, 1 up-to-date, 1 skipped ==========
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>Updated CMake file:</p>
  
  <pre><code>set(SOURCE_FILES "main.cpp")
  add_executable(core ${SOURCE_FILES})
  
  add_library(Allegro DYNAMIC IMPORTED)
  set_target_properties(Allegro PROPERTIES
      IMPORTED_LOCATION "${DEPENDENCIES_DIR}/allegro/bin/allegro.dll.a"
      IMPORTED_LOCATION "${DEPENDENCIES_DIR}/allegro/lib/allegro.lib"
  )
  
  target_include_directories(Allegro PUBLIC "${DEPENDENCIES_DIR}/allegro/include")
  target_link_libraries(core Allegro)
  </code></pre>