title: cmake library compilation mingw issue
body: <p>Apologies in advance I am beginner in cmake, the answer may be obvious but I didn't find it yet. 
  I am using cmake 3.0.2 and I am trying to build a library and then use that library in a executable (and later more executable). It is currently working (configure, generate, compile, execute) with MSVC (version 2013), however it doesn't work with mingw 4.8.1 nor g++ 4.8 on linux. 
  I only have two directories, the library (with the include) and the executable source. 
  the root CMakeLists.txt is: </p>
  
  <pre><code>IF(NOT MSVC) 
  SET(CMAKE_CXX_FLAGS "-std=c++11") 
  ENDIF() 
  
  include_directories ( 
  ${PROJECT_SOURCE_DIR}/libr-source 
  ${PROJECT_BINARY_DIR}/libr-source 
  ) 
  
  add_subdirectory(libr-source) 
  add_subdirectory(libr-executable)
  </code></pre>
  
  <p>the one in the libr-source is: </p>
  
  <pre><code>project(libr) 
  include (GenerateExportHeader) 
  
  set ( CXX_SRCS 
      codeMessage.cpp 
      codeMessage.hpp 
          libr_export.h 
  ) 
  
  add_library(libr SHARED ${CXX_SRCS}) 
  GENERATE_EXPORT_HEADER (libr) 
  </code></pre>
  
  <p>and in the executable: </p>
  
  <pre><code>set(PROJECT_NAME "librExecutable" ) 
  
  project(${PROJECT_NAME}) 
  
  set (SRCS 
      main.cpp 
  ) 
  
  add_executable(${PROJECT_NAME} ${SRCS}) 
  target_link_libraries (${PROJECT_NAME} libr) 
  </code></pre>
  
  <p>Thank you for your help! </p>
  
  <p>below the results of compilation: </p>
  
  <pre><code>C:\Users\user\dev\libr-buildming&gt;C:\Users\user\dev\MinGW-4.8.1\bin\mingw32-make.exe VERBOSE=1
  "C:\Program Files (x86)\CMake\bin\cmake.exe" -HC:\Users\user\dev\librTest -BC:\Users\user\dev\libr-buildming --check-build-system CMakeFiles\Makefile.cmake 0
  "C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_progress_start C:\Users\user\dev\libr-buildming\CMakeFiles C:\Users\user\dev\libr-buildming\CMakeFiles\progress.marks
  C:/Users/user/dev/MinGW-4.8.1/bin/mingw32-make -f CMakeFiles\Makefile2 all
  mingw32-make[1]: Entering directory 'C:/Users/user/dev/libr-buildming'
  C:/Users/user/dev/MinGW-4.8.1/bin/mingw32-make -f libr-source\CMakeFiles\libr.dir\build.make libr-source/CMakeFiles/libr.dir/depend
  mingw32-make[2]: Entering directory 'C:/Users/user/dev/libr-buildming'
  "C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\user\dev\librTest C:\Users\user\dev\librTest\libr-source C:\Users\user\dev\libr-buildming C:\Users\user\dev\libr-buildming\libr-source C:\Users\user\dev\libr-buildming\libr-source\CMakeFiles\libr.dir\DependInfo.cmake --color=
  Dependee "C:\Users\user\dev\libr-buildming\libr-source\CMakeFiles\libr.dir\DependInfo.cmake" is newer than depender "C:/Users/user/dev/libr-buildming/libr-source/CMakeFiles/libr.dir/depend.internal".
  Dependee "C:/Users/user/dev/libr-buildming/libr-source/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "C:/Users/user/dev/libr-buildming/libr-source/CMakeFiles/libr.dir/depend.internal".
  Scanning dependencies of target libr
  mingw32-make[2]: Leaving directory 'C:/Users/user/dev/libr-buildming'
  C:/Users/user/dev/MinGW-4.8.1/bin/mingw32-make -f libr-source\CMakeFiles\libr.dir\build.make libr-source/CMakeFiles/libr.dir/build
  mingw32-make[2]: Entering directory 'C:/Users/user/dev/libr-buildming'
  "C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_progress_report C:\Users\user\dev\libr-buildming\CMakeFiles 1
  [ 50%] Building CXX object libr-source/CMakeFiles/libr.dir/codeMessage.cpp.obj
  cd /d C:\Users\user\dev\libr-buildming\libr-source &amp;&amp; C:\Users\user\dev\MinGW-4.8.1\bin\g++.exe   -Dlibr_EXPORTS -std=c++11 @CMakeFiles/libr.dir/includes_CXX.rsp   -o CMakeFiles\libr.dir\codeMessage.cpp.obj -c C:\Users\user\dev\librTest\libr-source\codeMessage.cpp
  Linking CXX shared library liblibr.dll
  cd /d C:\Users\user\dev\libr-buildming\libr-source &amp;&amp; "C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_link_script CMakeFiles\libr.dir\link.txt --verbose=1
  "C:\Program Files (x86)\CMake\bin\cmake.exe" -E remove -f CMakeFiles\libr.dir/objects.a
  C:\Users\user\dev\MinGW-4.8.1\bin\ar.exe cr CMakeFiles\libr.dir/objects.a @CMakeFiles\libr.dir\objects1.rsp
  C:\Users\user\dev\MinGW-4.8.1\bin\g++.exe     -shared -o liblibr.dll -Wl,--out-implib,liblibr.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -Wl,--whole-archive CMakeFiles\libr.dir/objects.a -Wl,--no-whole-archive -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi3
  2
  mingw32-make[2]: Leaving directory 'C:/Users/user/dev/libr-buildming'
  "C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_progress_report C:\Users\user\dev\libr-buildming\CMakeFiles  1
  [ 50%] Built target libr
  C:/Users/user/dev/MinGW-4.8.1/bin/mingw32-make -f libr-executable\CMakeFiles\librExecutable.dir\build.make libr-executable/CMakeFiles/librExecutable.dir/depend
  mingw32-make[2]: Entering directory 'C:/Users/user/dev/libr-buildming'
  "C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\user\dev\librTest C:\Users\user\dev\librTest\libr-executable C:\Users\user\dev\libr-buildming C:\Users\user\dev\libr-buildming\libr-executable C:\Users\user\dev\libr-buildming\libr-executable\CMakeFiles\librExecutable.dir\DependInf
  o.cmake --color=
  Dependee "C:\Users\user\dev\libr-buildming\libr-executable\CMakeFiles\librExecutable.dir\DependInfo.cmake" is newer than depender "C:/Users/user/dev/libr-buildming/libr-executable/CMakeFiles/librExecutable.dir/depend.internal".
  Dependee "C:/Users/user/dev/libr-buildming/libr-executable/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "C:/Users/user/dev/libr-buildming/libr-executable/CMakeFiles/librExecutable.dir/depend.internal".
  Scanning dependencies of target librExecutable
  mingw32-make[2]: Leaving directory 'C:/Users/user/dev/libr-buildming'
  C:/Users/user/dev/MinGW-4.8.1/bin/mingw32-make -f libr-executable\CMakeFiles\librExecutable.dir\build.make libr-executable/CMakeFiles/librExecutable.dir/buildmingw32-make[2]: Entering directory 'C:/Users/user/dev/libr-buildming' 
  "C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_progress_report C:\Users\user\dev\libr-buildming\CMakeFiles 2
  [100%] Building CXX object libr-executable/CMakeFiles/librExecutable.dir/main.cpp.obj
  cd /d C:\Users\user\dev\libr-buildming\libr-executable &amp;&amp; C:\Users\user\dev\MinGW-4.8.1\bin\g++.exe    -std=c++11 @CMakeFiles/librExecutable.dir/includes_CXX.rsp   -o CMakeFiles\librExecutable.dir\main.cpp.obj -c C:\Users\user\dev\librTest\libr-executable\main.cpp
  Linking CXX executable librExecutable.exe
  cd /d C:\Users\user\dev\libr-buildming\libr-executable &amp;&amp; "C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_link_script CMakeFiles\librExecutable.dir\link.txt --verbose=1
  "C:\Program Files (x86)\CMake\bin\cmake.exe" -E remove -f CMakeFiles\librExecutable.dir/objects.a
  C:\Users\user\dev\MinGW-4.8.1\bin\ar.exe cr CMakeFiles\librExecutable.dir/objects.a @CMakeFiles\librExecutable.dir\objects1.rsp
  C:\Users\user\dev\MinGW-4.8.1\bin\g++.exe  -std=c++11    -Wl,--whole-archive CMakeFiles\librExecutable.dir/objects.a -Wl,--no-whole-archive  -o librExecutable.e xe -Wl,--out-implib,liblibrExecutable.dll.a -Wl,--major-image-version,0,--minor-image-version,0  ..\libr-source\liblibr.dll.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
  CMakeFiles\librExecutable.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x70): undefined reference to `_imp___ZN11codeMessageC1Ev'
  CMakeFiles\librExecutable.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x9e): undefined reference to `_imp___ZN11codeMessage10getMessageEm'
  C:/Users/user/dev/mingw-4.8.1/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: CMakeFiles\librExecutable.dir/objects.a(main.cpp.obj): bad reloc address 0x0 in section `.ctors'
  C:/Users/user/dev/mingw-4.8.1/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
  collect2.exe: error: ld returned 1 exit status
  libr-executable\CMakeFiles\librExecutable.dir\build.make:87: recipe for target 'libr-executable/librExecutable.exe' failed
  mingw32-make[2]: *** [libr-executable/librExecutable.exe] Error 1
  mingw32-make[2]: Leaving directory 'C:/Users/user/dev/libr-buildming'
  CMakeFiles\Makefile2:124: recipe for target 'libr-executable/CMakeFiles/librExecutable.dir/all' failed
  mingw32-make[1]: *** [libr-executable/CMakeFiles/librExecutable.dir/all] Error 2
  mingw32-make[1]: Leaving directory 'C:/Users/user/dev/libr-buildming'
  Makefile:75: recipe for target 'all' failed
  mingw32-make: *** [all] Error 2
  </code></pre>