title: Building PubNub C++ with CMake
body: <p>I'm trying to compile a sample from the <a href="https://github.com/pubnub/c-core" rel="nofollow">PubNub C++ git repository</a> using CMake to include the library it in one of my projects.</p>
  
  <p>As a test, I chose to compile the sample named 
  <strong>cancel_subscribe_sync_sample</strong> from the <a href="https://github.com/pubnub/c-core/blob/master/cpp/posix.mk" rel="nofollow">provided Makefile</a>.</p>
  
  <p>Using the Makefile, it compiles without any error.</p>
  
  <p>This is the CMakeLists I came up with (I am no expert in CMake) :</p>
  
  <pre><code>cmake_minimum_required(VERSION 3.4)
  project(untitled)
  
  set(CMAKE_CXX_FLAGS "-Wall -std=c++11")
  
  set(SOURCE_FILES cancel_subscribe_sync_sample.cpp)
  
  set(PUBNUB_FILES c-core/core/pubnub_coreapi.c
          c-core/core/pubnub_coreapi_ex.c
          c-core/core/pubnub_ccore.c
          c-core/core/pubnub_netcore.c
          c-core/lib/sockets/pbpal_sockets.c
          c-core/lib/sockets/pbpal_resolv_and_connect_sockets.c
          c-core/core/pubnub_alloc_std.c
          c-core/core/pubnub_assert_std.c
          c-core/core/pubnub_generate_uuid.c
          c-core/core/pubnub_blocking_io.c
          c-core/core/pubnub_timers.c
          c-core/core/pubnub_json_parse.c
          c-core/core/pubnub_helper.c
          c-core/posix/pubnub_version_posix.c
          c-core/posix/pubnub_generate_uuid_posix.c
          c-core/posix/pbpal_posix_blocking_io.c
          c-core/posix/monotonic_clock_get_time_posix.c)
  
  include_directories(c-core/posix)
  include_directories(c-core/cpp)
  include_directories(c-core/core)
  
  add_definitions(-DPUBNUB_THREADSAFE)
  
  add_executable(untitled ${SOURCE_FILES} c-core/core/pubnub_ntf_sync.c c-core/cpp/pubnub_futres_sync.cpp ${PUBNUB_FILES})
  link_libraries(untitled pthread rt)
  </code></pre>
  
  <p>Using it with CLion on Ubuntu, the compilation fails with :</p>
  
  <pre><code>/home/barrauh/clion-2016.1/bin/cmake/bin/cmake --build /home/barrauh/.CLion2016.1/system/cmake/generated/untitled-609ca616/609ca616/Debug --target untitled -- -j 4
  [  4%] Building CXX object CMakeFiles/untitled.dir/cancel_subscribe_sync_sample.cpp.o
  [  9%] Building C object CMakeFiles/untitled.dir/c-core/core/pubnub_ntf_sync.c.o
  [ 14%] Building CXX object CMakeFiles/untitled.dir/c-core/cpp/pubnub_futres_sync.cpp.o
  [ 19%] Building C object CMakeFiles/untitled.dir/c-core/core/pubnub_coreapi.c.o
  [ 23%] Building C object CMakeFiles/untitled.dir/c-core/core/pubnub_coreapi_ex.c.o
  [ 28%] Building C object CMakeFiles/untitled.dir/c-core/core/pubnub_ccore.c.o
  [ 33%] Building C object CMakeFiles/untitled.dir/c-core/core/pubnub_netcore.c.o
  [ 38%] Building C object CMakeFiles/untitled.dir/c-core/lib/sockets/pbpal_sockets.c.o
  [ 42%] Building C object CMakeFiles/untitled.dir/c-core/lib/sockets/pbpal_resolv_and_connect_sockets.c.o
  [ 47%] Building C object CMakeFiles/untitled.dir/c-core/core/pubnub_alloc_std.c.o
  [ 52%] Building C object CMakeFiles/untitled.dir/c-core/core/pubnub_assert_std.c.o
  [ 57%] Building C object CMakeFiles/untitled.dir/c-core/core/pubnub_generate_uuid.c.o
  [ 61%] Building C object CMakeFiles/untitled.dir/c-core/core/pubnub_blocking_io.c.o
  [ 66%] Building C object CMakeFiles/untitled.dir/c-core/core/pubnub_timers.c.o
  [ 71%] Building C object CMakeFiles/untitled.dir/c-core/core/pubnub_json_parse.c.o
  [ 76%] Building C object CMakeFiles/untitled.dir/c-core/core/pubnub_helper.c.o
  [ 80%] Building C object CMakeFiles/untitled.dir/c-core/posix/pubnub_version_posix.c.o
  [ 85%] Building C object CMakeFiles/untitled.dir/c-core/posix/pubnub_generate_uuid_posix.c.o
  [ 90%] Building C object CMakeFiles/untitled.dir/c-core/posix/pbpal_posix_blocking_io.c.o
  [ 95%] Building C object CMakeFiles/untitled.dir/c-core/posix/monotonic_clock_get_time_posix.c.o
  [100%] Linking CXX executable untitled
  CMakeFiles/untitled.dir/cancel_subscribe_sync_sample.cpp.o: In function `pubnub::context::context(std::string, std::string)':
  /home/barrauh/ClionProjects/untitled/c-core/cpp/pubnub_common.hpp:201: undefined reference to `pubnub_alloc()'
  /home/barrauh/ClionProjects/untitled/c-core/cpp/pubnub_common.hpp:205: undefined reference to `pubnub_init(pubnub_*, char const*, char const*)'
  CMakeFiles/untitled.dir/cancel_subscribe_sync_sample.cpp.o: In function `pubnub::context::get() const':
  /home/barrauh/ClionProjects/untitled/c-core/cpp/pubnub_common.hpp:267: undefined reference to `pubnub_get(pubnub_*)'
  CMakeFiles/untitled.dir/cancel_subscribe_sync_sample.cpp.o: In function `pubnub::context::cancel()':
  /home/barrauh/ClionProjects/untitled/c-core/cpp/pubnub_common.hpp:305: undefined reference to `pubnub_cancel(pubnub_*)'
  CMakeFiles/untitled.dir/cancel_subscribe_sync_sample.cpp.o: In function `pubnub::context::subscribe(std::string const&amp;, std::string const&amp;)':
  /home/barrauh/ClionProjects/untitled/c-core/cpp/pubnub_common.hpp:328: undefined reference to `pubnub_subscribe(pubnub_*, char const*, char const*)'
  CMakeFiles/untitled.dir/cancel_subscribe_sync_sample.cpp.o: In function `pubnub::context::set_blocking_io(pubnub::blocking_io)':
  /home/barrauh/ClionProjects/untitled/c-core/cpp/pubnub_common.hpp:537: undefined reference to `pubnub_set_blocking_io(pubnub_*)'
  /home/barrauh/ClionProjects/untitled/c-core/cpp/pubnub_common.hpp:540: undefined reference to `pubnub_set_non_blocking_io(pubnub_*)'
  CMakeFiles/untitled.dir/cancel_subscribe_sync_sample.cpp.o: In function `pubnub::context::~context()':
  /home/barrauh/ClionProjects/untitled/c-core/cpp/pubnub_common.hpp:580: undefined reference to `pubnub_free(pubnub_*)'
  CMakeFiles/untitled.dir/c-core/cpp/pubnub_futres_sync.cpp.o: In function `pubnub::futres::last_result()':
  /home/barrauh/ClionProjects/untitled/c-core/cpp/pubnub_futres_sync.cpp:34: undefined reference to `pubnub_last_result(pubnub_*)'
  CMakeFiles/untitled.dir/c-core/cpp/pubnub_futres_sync.cpp.o: In function `pubnub::futres::end_await()':
  /home/barrauh/ClionProjects/untitled/c-core/cpp/pubnub_futres_sync.cpp:50: undefined reference to `pubnub_await(pubnub_*)'
  CMakeFiles/untitled.dir/c-core/core/pubnub_coreapi.c.o: In function `pubnub_init':
  /home/barrauh/ClionProjects/untitled/c-core/core/pubnub_coreapi.c:20: undefined reference to `pthread_mutexattr_init'
  /home/barrauh/ClionProjects/untitled/c-core/core/pubnub_coreapi.c:20: undefined reference to `pthread_mutexattr_settype'
  collect2: error: ld returned 1 exit status
  make[3]: *** [untitled] Error 1
  make[2]: *** [CMakeFiles/untitled.dir/all] Error 2
  make[1]: *** [CMakeFiles/untitled.dir/rule] Error 2
  make: *** [untitled] Error 2titled/c-core/cpp/pubnub_common.hpp:580: undefined reference to `pubnub_free(pubnub_*)'
      CMakeFiles/untitled.dir/c-core/cpp/pubnub_futres_sync.cpp.o: In function `pubnub::futres::last_result()':
      /home/barrauh/ClionProjects/untitled/c-core/cpp/pubnub_futres_sync.cpp:34: undefined reference to `pubnub_last_result(pubnub_*)'
      CMakeFiles/untitled.dir/c-core/cpp/pubnub_futres_sync.cpp.o: In function `pubnub::futres::end_await()':
      /home/barrauh/ClionProjects/untitled/c-core/cpp/pubnub_futres_sync.cpp:50: undefined reference to `pubnub_await(pubnub_*)'
      CMakeFiles/untitled.dir/c-core/core/pubnub_coreapi.c.o: In function `pubnub_init':
      /home/barrauh/ClionProjects/untitled/c-core/core/pubnub_coreapi.c:20: undefined reference to `pthread_mutexattr_init'
      /home/barrauh/ClionProjects/untitled/c-core/core/pubnub_coreapi.c:20: undefined reference to `pthread_mutexattr_settype'
      collect2: error: ld returned 1 exit status
      make[3]: *** [untitled] Error 1
      make[2]: *** [CMakeFiles/untitled.dir/all] Error 2
      make[1]: *** [CMakeFiles/untitled.dir/rule] Error 2
      make: *** [untitled] Error 2
  </code></pre>
  
  <p>I really don't understand why. For exemple, the function <em>pubnub_alloc()</em> is defined in the file <strong>pubnub_alloc_std.c</strong>.</p>
  
  <p>It's driving me nuts... Am I doing something wrong here ?</p>
  
  <p>Thank you !</p>