title: How to link multiple libraries using CMake
body: <p>I have some code to do with DCMTK. I can successfully build and run it if I use g++ from the command line. This is the code:</p>
  
  <pre><code>#include "dcmtk/config/osconfig.h"
  #include "dcmtk/dcmdata/dctk.h"
  
  int main()
  {
  DcmFileFormat fileformat;
  OFCondition status = fileformat.loadFile("test.dcm");
  if (status.good())
  {
     OFString patientsName;
     if (fileformat.getDataset()-&gt;findAndGetOFString(DCM_PatientsName, patientsName).good())
     {
        cout &lt;&lt; "Patient's Name: " &lt;&lt; patientsName &lt;&lt; endl;
     } else
       cerr &lt;&lt; "Error: cannot access Patient's Name!" &lt;&lt; endl;
  } else
  cerr &lt;&lt; "Error: cannot read DICOM file (" &lt;&lt; status.text() &lt;&lt; ")" &lt;&lt; endl;
  return 0;
  }
  </code></pre>
  
  <p>This is the build command:</p>
  
  <pre><code>g++ testeapp.cxx -DHAVE_CONFIG_H -I/path_to_dcmtk/include -L/path_to_dcmtk/lib -pthread -ldcmdata -lz -loflog -lofstd -o main
  </code></pre>
  
  <p>I want to make a CMakeLists.txt to build it in Kdevelop.  This is what I currently have:</p>
  
  <pre><code>    # Configure toplevel directories
      SET( PREFIX     ${CMAKE_INSTALL_PREFIX} CACHE PATH "Top level.")
      SET( INCLUDEDIR ${PREFIX}/include       CACHE PATH "Include files.")
      SET( LIBDIR     ${PREFIX}/lib           CACHE PATH "Libraries.")
      FIND_PACKAGE ( Threads REQUIRED )
      # Configure DCMTK
      FIND_PATH( DINIFTI_DCMTK_INCLUDE dcmtk
                 PATHS ${INCLUDEDIR}
                 PATH_SUFFIXES dcmtk
                 DOC "Path to the DCMTK headers." )
      FIND_LIBRARY(DINIFTI_DCMTK_LIB NAMES dcmdata ofstd oflog 
                   HINTS ${LIBDIR} ${LIBDIR})
  TARGET_LINK_LIBRARIES( dinifti ${DINIFTI_DCMTK_LIB}
                                 ${DINIFTI_ZNZ_LIB}
                                 ${CMAKE_THREAD_LIBS_INIT}
                                 z )             
  </code></pre>
  
  <p>But when I build it, it has this error:</p>
  
  <pre><code>/usr/local/lib/libdcmdata.a(dcfilefo.o): In function `DcmFileFormat::remove(DcmItem*)':
  dcfilefo.cc:(.text+0x1788): undefined reference to `log4cplus::Logger::forcedLog(int, OFString const&amp;, char const*, int, char const*) const'
  </code></pre>
  
  <p>Can you help me to fix the error? Thank you.</p>