title: gcc does not link properly against gsoap
body: <p>I'm migrating my C++ application build system to cmake. One dependency is gsoap++, which generates a SOAP service and client. To link against it, I specify</p>
  
  <pre><code>set(CMAKE_CXX_LINK_FLAGS "-lgsoap++ ... [other flags]")
  </code></pre>
  
  <p>in the root <code>CMakeLists.txt</code>. The generated sources are created with</p>
  
  <pre><code>file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/generated/c++/ws)
  set(GEN_WS_SOURCES ws/Bar.h ws/Bar_USCOREBinding.nsmap ws/soapBar_USCOREBindingProxy.h ws/soapBar_USCOREBindingProxy.cpp ws/soapBar_USCOREBindingService.h ws/soapBar_USCOREBindingService.cpp ws/soapH.h ws/soapC.cpp ws/soapStub.h)
  add_custom_command(OUTPUT ${GEN_WS_SOURCES}
                     COMMAND wsdl2h -o ${CMAKE_BINARY_DIR}/src/generated/c++/ws/Bar.h -t wsdl/typemap.dat wsdl/bar.wsdl
                     COMMAND soapcpp2 -Lwxi -I/usr/include/gsoap ${CMAKE_BINARY_DIR}/src/generated/c++/ws/Bar.h -d ${CMAKE_BINARY_DIR}/src/generated/c++/ws
                     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  )
  add_library(GEN_WS ${GEN_WS_SOURCES})
  </code></pre>
  
  <p>Everything seems to work properly, the sources get created. But when linking the application, I get lots of errors like</p>
  
  <pre><code>undefined reference to `soap_end'
  undefined reference to `soap_sender_fault'
  more undefined references to `soap_sender_fault' follow
  </code></pre>
  
  <p>If I compile with <code>make VERBOSE=1</code>, I see that <code>-lgsoap++</code> is passed to <code>/usr/bin/c++</code> when linking. Other libraries I link against don't throw any errors, but for some reason, the linker does not seem to find gsoap's functions. The library is present and there is no error that the linker can't find it.</p>
  
  <p>The old, custom build script worked as expected; it also just passed <code>-lgsoap++</code> to the linker. The only real difference I see is that my cmake build groups the sources into static libraries before attempting to link everything together. But I don't see how this can lead to all the symbols from the library not being found.</p>
  
  <p>What's the problem here? Why can't the linker find gsoap's symbols?</p>
  
  <p>Host OS is debian.</p>
  
  <p><strong>Edit:</strong> This is the complete linker command executed by cmake:</p>
  
  <pre><code>/usr/bin/c++   -w -Wall -pedantic -fdata-sections -ffunction-sections -std=c++0x
  -lgsoap++ -lsoci_core -lsoci_sqlite3 -lmicrohttpd -lfetcp -lfeisc -lFedmIscCore
  -lboost_system -lboost_thread -lboost_program_options -lboost_date_time
  -lboost_unit_test_framework  CMakeFiles/bar.dir/main.cpp.o
  CMakeFiles/bar.dir/mainapp.cpp.o  -o bar -rdynamic ../../libs/c++/libLIB_JSONXX.a
  ../../libs/c++/libLIB_CONFIG.a ../../libs/c++/libLIB_DB.a ../../libs/c++/libLIB_OBID.a
  ../../libs/c++/libLIB_HELPER.a ../../generated/c++/libGEN_WS.a
  ../../generated/c++/libGEN_DB.a ../../generated/c++/libGEN_CONFIG.a
  libMAIN_CONTROLLERS.a libMAIN_HARDWARE.a libMAIN_HELPER.a libMAIN_MODEL.a
  libMAIN_NETWORK.a libMAIN_SYSTEM.a ../../generated/c++/libGEN_DB.a
  ../../libs/c++/libLIB_DB.a ../../generated/c++/libGEN_CONFIG.a
  ../../libs/c++/libLIB_JSONXX.a ../../libs/c++/libLIB_CONFIG.a
  ../../libs/c++/libLIB_HELPER.a ../../libs/c++/libLIB_OBID.a
  ../../generated/c++/libGEN_WS.a
  </code></pre>