title: g++ not linking wayland methods
body: <p>I was trying to create a Wayland window, and I keep getting these strange linkers errors.</p>
  <blockquote>
  <p>Header:</p>
  </blockquote>
  <pre><code>#include &lt;wayland-client.h&gt;
  #include &lt;wayland-client-protocol.h&gt;
  
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  
  namespace dmaf
  {
  
          class WINDOW
          {
  
          private:
                  bool Init();
  
          public:
                  void Run();
  
                  WINDOW();
                  ~WINDOW();
  
          };
  
          WINDOW::WINDOW()
          {
          }
  
          WINDOW::~WINDOW()
          {
          }
  
          bool WINDOW::Init()
          {
  
                  return 1;
  
          }
  
          void WINDOW::Run()
          {
  
                  if (Init())
                  {
  
                          wl_display* display = wl_display_connect(0);
  
                          if (display)
                                  printf(&quot;h\n&quot;);
                          else
                                  printf(&quot;g\n&quot;);
  
                          if (!display)
                                  return;
  
                          wl_display_disconnect(display);
  
                  }
  
          }
  
  }
  </code></pre>
  <blockquote>
  <p>Main:</p>
  </blockquote>
  <pre><code>#include &quot;WAYDMAF.h&quot;
  using namespace dmaf;
  
  int main()
  {
  
          WINDOW window;
          window.Run();
  
  }
  </code></pre>
  <blockquote>
  <p>Errors:</p>
  </blockquote>
  <pre><code>Package wayland-client-protocol was not found in the pkg-config search path.
  Perhaps you should add the directory containing `wayland-client-protocol.pc'
  to the PKG_CONFIG_PATH environment variable
  No package 'wayland-client-protocol' found
  /usr/bin/ld: /tmp/ccImUDBz.o: in function `dmaf::WINDOW::Run()':
  dmaf_program.cxx:(.text+0x5a): undefined reference to `wl_display_connect'
  /usr/bin/ld: dmaf_program.cxx:(.text+0x92): undefined reference to `wl_display_disconnect'
  collect2: error: ld returned 1 exit status
  </code></pre>
  <blockquote>
  <p>Hello Wayland (more below)</p>
  </blockquote>
  <pre><code>@pop-os: gcc hello_wayland.c helpers.c helpers.h $(pkg-config --cflags --libs=lwayland-client) -o hello_wayland
  
  Must specify package names on the command line
  /usr/bin/ld: /tmp/ccx8fSIO.o: warning: relocation against `wl_surface_interface' in read-only section `.text'
  /usr/bin/ld: /tmp/ccVVuR6n.o: in function `main':
  hello_wayland.c:(.text+0xe4): undefined reference to `wl_display_dispatch'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_display_get_registry':
  helpers.c:(.text+0x18): undefined reference to `wl_registry_interface'
  /usr/bin/ld: helpers.c:(.text+0x2a): undefined reference to `wl_proxy_marshal_constructor'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_registry_add_listener':
  helpers.c:(.text+0x5f): undefined reference to `wl_proxy_add_listener'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_registry_destroy':
  helpers.c:(.text+0x79): undefined reference to `wl_proxy_destroy'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_registry_bind':
  helpers.c:(.text+0xc5): undefined reference to `wl_proxy_marshal_constructor_versioned'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_compositor_destroy':
  helpers.c:(.text+0xeb): undefined reference to `wl_proxy_destroy'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_compositor_create_surface':
  helpers.c:(.text+0x10a): undefined reference to `wl_surface_interface'
  /usr/bin/ld: helpers.c:(.text+0x11c): undefined reference to `wl_proxy_marshal_constructor'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shm_pool_set_user_data':
  helpers.c:(.text+0x149): undefined reference to `wl_proxy_set_user_data'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shm_pool_get_user_data':
  helpers.c:(.text+0x164): undefined reference to `wl_proxy_get_user_data'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shm_pool_create_buffer':
  helpers.c:(.text+0x1af): undefined reference to `wl_buffer_interface'
  /usr/bin/ld: helpers.c:(.text+0x1c1): undefined reference to `wl_proxy_marshal_constructor'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shm_pool_destroy':
  helpers.c:(.text+0x1f1): undefined reference to `wl_proxy_marshal'
  /usr/bin/ld: helpers.c:(.text+0x1fd): undefined reference to `wl_proxy_destroy'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shm_destroy':
  helpers.c:(.text+0x218): undefined reference to `wl_proxy_destroy'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shm_create_pool':
  helpers.c:(.text+0x249): undefined reference to `wl_shm_pool_interface'
  /usr/bin/ld: helpers.c:(.text+0x25b): undefined reference to `wl_proxy_marshal_constructor'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_buffer_destroy':
  helpers.c:(.text+0x287): undefined reference to `wl_proxy_marshal'
  /usr/bin/ld: helpers.c:(.text+0x293): undefined reference to `wl_proxy_destroy'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shell_destroy':
  helpers.c:(.text+0x2ae): undefined reference to `wl_proxy_destroy'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shell_get_shell_surface':
  helpers.c:(.text+0x2d8): undefined reference to `wl_shell_surface_interface'
  /usr/bin/ld: helpers.c:(.text+0x2ea): undefined reference to `wl_proxy_marshal_constructor'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shell_surface_add_listener':
  helpers.c:(.text+0x31f): undefined reference to `wl_proxy_add_listener'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shell_surface_set_user_data':
  helpers.c:(.text+0x344): undefined reference to `wl_proxy_set_user_data'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shell_surface_get_user_data':
  helpers.c:(.text+0x35f): undefined reference to `wl_proxy_get_user_data'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shell_surface_destroy':
  helpers.c:(.text+0x379): undefined reference to `wl_proxy_destroy'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shell_surface_pong':
  helpers.c:(.text+0x3a4): undefined reference to `wl_proxy_marshal'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_shell_surface_set_toplevel':
  helpers.c:(.text+0x3c9): undefined reference to `wl_proxy_marshal'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_surface_set_user_data':
  helpers.c:(.text+0x3ef): undefined reference to `wl_proxy_set_user_data'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_surface_get_user_data':
  helpers.c:(.text+0x40a): undefined reference to `wl_proxy_get_user_data'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_surface_destroy':
  helpers.c:(.text+0x42e): undefined reference to `wl_proxy_marshal'
  /usr/bin/ld: helpers.c:(.text+0x43a): undefined reference to `wl_proxy_destroy'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_surface_attach':
  helpers.c:(.text+0x476): undefined reference to `wl_proxy_marshal'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_surface_commit':
  helpers.c:(.text+0x49b): undefined reference to `wl_proxy_marshal'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_seat_destroy':
  helpers.c:(.text+0x4b6): undefined reference to `wl_proxy_destroy'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_seat_get_pointer':
  helpers.c:(.text+0x4d5): undefined reference to `wl_pointer_interface'
  /usr/bin/ld: helpers.c:(.text+0x4e7): undefined reference to `wl_proxy_marshal_constructor'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_pointer_add_listener':
  helpers.c:(.text+0x51c): undefined reference to `wl_proxy_add_listener'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_pointer_set_user_data':
  helpers.c:(.text+0x541): undefined reference to `wl_proxy_set_user_data'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_pointer_get_user_data':
  helpers.c:(.text+0x55c): undefined reference to `wl_proxy_get_user_data'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_pointer_destroy':
  helpers.c:(.text+0x576): undefined reference to `wl_proxy_destroy'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `wl_pointer_set_cursor':
  helpers.c:(.text+0x5bc): undefined reference to `wl_proxy_marshal'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `hello_setup_wayland':
  helpers.c:(.text+0x5d5): undefined reference to `wl_display_connect'
  /usr/bin/ld: helpers.c:(.text+0x638): undefined reference to `wl_display_roundtrip'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `hello_cleanup_wayland':
  helpers.c:(.text+0x6a9): undefined reference to `wl_display_disconnect'
  /usr/bin/ld: /tmp/ccx8fSIO.o: in function `registry_global':
  helpers.c:(.text+0x6d2): undefined reference to `wl_compositor_interface'
  /usr/bin/ld: helpers.c:(.text+0x704): undefined reference to `wl_compositor_interface'
  /usr/bin/ld: helpers.c:(.text+0x71f): undefined reference to `wl_shm_interface'
  /usr/bin/ld: helpers.c:(.text+0x74c): undefined reference to `wl_shm_interface'
  /usr/bin/ld: helpers.c:(.text+0x767): undefined reference to `wl_shell_interface'
  /usr/bin/ld: helpers.c:(.text+0x794): undefined reference to `wl_shell_interface'
  /usr/bin/ld: helpers.c:(.text+0x7ac): undefined reference to `wl_seat_interface'
  /usr/bin/ld: helpers.c:(.text+0x7de): undefined reference to `wl_seat_interface'
  /usr/bin/ld: warning: creating DT_TEXTREL in a PIE
  collect2: error: ld returned 1 exit status
  </code></pre>
  <p><em>^there may be some errors as I didn't try to add all necessary headers^</em></p>
  <p>I've tried a few g++ settings, but nothing.</p>
  <blockquote>
  <p>g++:</p>
  </blockquote>
  <pre><code>g++ program.cxx $(pkg-config --cflags wayland-client-protocol) -o program
  g++ program.cxx $(pkg-config --cflags wayland-client) -o program
  </code></pre>
  <blockquote>
  <p>usr/include:</p>
  </blockquote>
  <pre><code>wayland-egl
  wayland-server-protocol
  wayland-client
  wayland-server-core
  wayland-util
  wayland-version
  wayland-egl-core
  wayland-cursor
  wayland-client-protocol
  wayland-server
  wayland-client-core
  </code></pre>
  <p>I've also tried compiling Hello-Wayland, but I got a mountain of the same errors. I'm using Pop!_os, and I don't remember having any problems with X when I was on Ubuntu (Haven't tried X on Pop,and I don't remember using Wayland on Ubuntu).
  It seems to only do this to wl_display_connect, wl_display_disconnect, and wl_display_connect_to_fd, so I checked in all of my header files and none of them had wl_display_connect (didn't try the other methods). Is it possible I need some other header files? If so, what do I need?</p>
  <p>-Thanks del</p>