title: CMAKE link external c library
body: <p>Hi basicly i am trying to use the svm from <a href="http://www.cs.cornell.edu/People/tj/svm_light/svm_light_faq.html" rel="nofollow">here</a> . It is written in C and gives instructions how to use it in c++:</p>
  
  <blockquote>
    <ul>
    <li>Compile "svm_learn.c",    "svm_common.c", and "svm_hideo.c" as<br>
    C code.</li>
    <li><p>The C++ program you want to call svm_learn/8 and    classify_example/2
    (or    classify_example_linear/2) from
    needs    to include the following
    headers:</p>
    
    <p>extern "C" {
     # include "svm_common.h"
     # include "svm_learn.h"
     }</p></li>
    <li><p>Link "svm_learn.o", "svm_common.o", and "svm_hideo.o" to    your program.</p></li>
    </ul>
  </blockquote>
  
  <p>So i compiled the mentioned files and got the needed .o files.
  Than i added:</p>
  
  <pre><code>SET( svm_lib_light_obj
      E:\framework\svm_light\build\svm_learn.o
      E:\framework\svm_light\build\svm_common.o
      E:\framework\svm_light\build\svm_hideo.o
  )
  
  ADD_LIBRARY(
      svm_lib_light
      STATIC
      EXCLUDE_FROM_ALL
      ${svm_lib_light_obj}
  )
  
  SET_SOURCE_FILES_PROPERTIES(
    ${svm_lib_light_obj}
    PROPERTIES
    EXTERNAL_OBJECT true # to say that "this is actually an object file, so it should not be compiled, only linked"
    GENERATED true       # to say that "it is OK that the obj-files do not exist before build time"
    )
  
  SET_TARGET_PROPERTIES(
    svm_lib_light
    PROPERTIES
    LINKER_LANGUAGE C # Or else we get an error message, because cmake can't figure out from the ".o"-suffix that it is a C-linker we need.
    ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib
    )
  </code></pre>
  
  <p>So now i just need to include the .h files mentioned. I added them to my other source files in:</p>
  
  <pre><code>ADD_EXECUTABLE ( MYProgramm
              ...
              #other source files
              ...
              src/svm_common.h
              src/svm_learn.h
  )
  </code></pre>
  
  <p>Unfortunatly it doesnt work. Calling any function from these .h files leads to an linker error LNK2001, LNK1120.
  I am guessing i have to tell cmake that these .h files are frontends for the .o files. But how?</p>