title: cmake multiple definition issue
body: <p>i just use cmake for compile c++ code with tbb , openCv and i have an error after ran make command the error its</p>
  
  <pre><code>  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(pngerror.c.o): In function `png_warning':
  pngerror.c:(.text.png_warning+0x0): multiple definition of `png_warning'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-pngerror.o):(.text+0x2f0): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(pngerror.c.o): In function `png_chunk_warning':
  pngerror.c:(.text.png_chunk_warning+0x0): multiple definition of `png_chunk_warning'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-pngerror.o):(.text+0x4b0): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(pngerror.c.o): In function `png_error':
  pngerror.c:(.text.png_error+0x0): multiple definition of `png_error'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-pngerror.o):(.text+0xf0): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(pngerror.c.o): In function `png_chunk_error':
  pngerror.c:(.text.png_chunk_error+0x0): multiple definition of `png_chunk_error'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-pngerror.o):(.text+0x470): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(pngerror.c.o): In function `png_set_error_fn':
  pngerror.c:(.text.png_set_error_fn+0x0): multiple definition of `png_set_error_fn'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-pngerror.o):(.text+0x510): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(pngerror.c.o): In function `png_get_error_ptr':
  pngerror.c:(.text.png_get_error_ptr+0x0): multiple definition of `png_get_error_ptr'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-pngerror.o):(.text+0x530): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_zalloc':
  png.c:(.text.png_zalloc+0x0): multiple definition of `png_zalloc'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x110): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_zfree':
  png.c:(.text.png_zfree+0x0): multiple definition of `png_zfree'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x190): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_set_sig_bytes':
  png.c:(.text.png_set_sig_bytes+0x0): multiple definition of `png_set_sig_bytes'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x0): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_sig_cmp':
  png.c:(.text.png_sig_cmp+0x0): multiple definition of `png_sig_cmp'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x40): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_reset_crc':
  png.c:(.text.png_reset_crc+0x0): multiple definition of `png_reset_crc'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x1a0): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_calculate_crc':
  png.c:(.text.png_calculate_crc+0x0): multiple definition of `png_calculate_crc'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x1c0): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_create_info_struct':
  png.c:(.text.png_create_info_struct+0x0): multiple definition of `png_create_info_struct'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x270): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_destroy_info_struct':
  png.c:(.text.png_destroy_info_struct+0x0): multiple definition of `png_destroy_info_struct'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x920): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_info_init_3':
  png.c:(.text.png_info_init_3+0x0): multiple definition of `png_info_init_3'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x210): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_data_freer':
  png.c:(.text.png_data_freer+0x0): multiple definition of `png_data_freer'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x310): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_free_data':
  png.c:(.text.png_free_data+0x0): multiple definition of `png_free_data'
  /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x350): first defined here
  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_get_io_ptr':
  </code></pre>
  
  <p>from the error its seems another shared library was linked and made those problem but i want to use the opencv library all library static that's what i try to do </p>
  
  <p>now my cmake</p>
  
  <pre><code>cmake_minimum_required (VERSION 2.8)
  project (wordxx)
  
  
  set(TBB_BUILD_STATIC ON CACHE BOOL " " FORCE)
  set(TBB_BUILD_SHARED OFF CACHE BOOL " " FORCE)
  set(TBB_BUILD_TBBMALLOC OFF CACHE BOOL " " FORCE)
  set(TBB_BUILD_TBBMALLOC_PROXY OFF CACHE BOOL " " FORCE)
  set(TBB_BUILD_TESTS OFF CACHE BOOL " " FORCE)
  
  
  
  
  
  
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/)
  set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
  set(CMAKE_CONFIG_DIR /home/medo/xx/wordxx)
  set(CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_CONFIG_DIR}")
  
  
  
  
  add_definitions(-DCONFIG_DIR="${CONFIG_DIR}")
  
  find_package( OpenCV REQUIRED )
  
  
  
  
  MESSAGE("  OpenCV information:") 
  MESSAGE("  OpenCV_INCLUDE_DIRS: ${OpenCV_INCLUDE_DIRS}") 
  MESSAGE("  OpenCV_LIBRARIES: ${OpenCV_LIBRARIES}") 
  MESSAGE("  OpenCV_LIBRARY_DIRS: ${OpenCV_LIBRARY_DIRS}") 
  include_directories( ${OpenCV_INCLUDE_DIRS} )
  
  
  add_definitions( -DBOOST_ALL_NO_LIB )
  set(Boost_USE_STATIC_LIBS ON)
  unset(Boost_INCLUDE_DIR CACHE)
  unset(Boost_LIBRARY_DIRS CACHE)
  set(Boost_INCLUDE_DIR /home/medo/build/boost)
  set(Boost_LIBRARY_DIRS /home/medo/build/boost/stage/lib)
  set(BOOST_ROOT /home/medo/build/boost)
  
  
  
  
  find_package( Boost 1.5.9 REQUIRED COMPONENTS  filesystem system)  
  MESSAGE("Boost information:") 
  MESSAGE("  Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}") 
  MESSAGE("  Boost_LIBRARIES: ${Boost_LIBRARIES}") 
  MESSAGE("  Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}") 
  
  
  
  
  if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
      #execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
      if (GCC_VERSION VERSION_LESS 4.7)
          #set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -msse -msse2 -msse3")
      else ()
          #set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -msse -msse2 -msse3")
      endif ()
  else ()
      #set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -msse -msse2 -msse3")
  endif ()
  
  # Boost
  if(WIN32)
      include_directories(lib/boost)
      include_directories(lib/boost/boost)
      link_directories( ${PROJECT_SOURCE_DIR}/lib/boost/lib )
  else()
       INCLUDE_DIRECTORIES(${BOOST_INCLUDE_DIR})
  
  endif()
  
  
  set(CMAKE_EXE_LINKER_FLAGS "-lboost_thread -lpthread ")
  
  
  #Set Linker flags
  set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
  
  
  
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -msse -msse2 -msse3")
  
  
  include_directories(${Boost_INCLUDE_DIR})
  link_directories(${Boost_LIBRARY_DIR})
  
  
  
  
  
  add_subdirectory(lib/tbb)
  set_property(TARGET tbb_static tbb_def_files PROPERTY FOLDER "dependencies")
  include_directories(tbb_static PUBLIC lib/tbb/include)
  
  
  
  # dlib
  include_directories(lib/dlib/include)
  
  
  
  
  # dlib library
  add_subdirectory(lib/dlib)
  
  ADD_EXECUTABLE(wordxx Source.cpp) 
  
  
  
  
  target_link_libraries(wordxx dlib   ${OpenCV_LIBS} ${Boost_LIBRARIES} )
  TARGET_LINK_LIBRARIES (wordxx ${tbb_static_LIBS})  
  target_link_libraries(wordxx PUBLIC tbb_static)
  </code></pre>
  
  <p>now when i remove </p>
  
  <blockquote>
    <p>set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")</p>
  </blockquote>
  
  <p>its work but some of openCv library not linked static like this error i got after run my program ./wordxx  </p>
  
  <blockquote>
    <p>wordxx: error while loading shared libraries: libjpeg.so.8: cannot open shared object file: No such file or directory</p>
  </blockquote>
  
  <p>this library in opencv and i must use </p>
  
  <blockquote>
    <p>set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")</p>
  </blockquote>
  
  <p>to avoid this problem but this made <code>multiple definition</code> issue any idea</p>