title: Linker error in Meson & Ninja when trying to add custom dependency
body: <p>I am trying to add source-based library to my project using Meson. But when I try doing that, I get object file linking errors.</p>
  
  <p>I tried adding custom dependency to project executable, but of course, it says it is undefined(<code>srclibdep</code> in code ahead), since it is defined after project executable. But if I define before Project executable, then I can't link.</p>
  
  <p>This is my ./meson.build</p>
  
  <pre class="lang-rb prettyprint-override"><code>project('ProjectName', 'cpp', version: '0.1', default_options: ['warning_level=3', 'cpp_std=c++14'])
  
  srclibinc = include_directories('SourceLibraryName')
  cpp = meson.get_compiler('cpp')
  add_languages('cpp')
  proj = executable('ProjectName', 'main.cpp', install: true, include_directories: srclibinc)
  srclibdep = declare_dependency(include_directories: srclibinc, link_with: proj)
  </code></pre>
  
  <p>And ./SourceLibraryName/meson.build</p>
  
  <pre class="lang-rb prettyprint-override"><code>files = run_command('files.sh').stdout().strip().split('\n')
  
  foreach f: files
          install_headers(f)
  endforeach
  
  srclib = shared_library('SourceLibrary', files, install: true)
  pkg_mod = import('pkgconfig')
  pkg_mod.generate(libraries: srclib, version: '0.1', name: 'libsrc', description: 'Source-based library.')
  </code></pre>
  
  <p>I am getting hundreds of linking errors saying that <code>x::Y</code> reference doesn't exist, but compiler compiled the code as if dependency is already there.</p>