title: CMake / g++, library not being linked in OpenFOAM application
body: <p>I am trying to compile a custom OpenFOAM application. My build procedure is with CMake (though I'm not sure this has anything to do with my current problem).</p>
  
  <p>For those familiar with OpenFOAM, this is the pisoFoam application, and the problem library is the incompressibleLESModels.so library.</p>
  
  <p>The project builds without any problems.  And runs until it needs to make use of the IncompressibleLESModels library. At this point, the app claims not to know anything about that library and stops.</p>
  
  <p>I have included the incompressibleLESModels library in my TARGET_LINK_LIBRARIES within the CMake script (along with all the other necessary libraries).  </p>
  
  <p>OpenFOAM allows the user to link in libraries at run-time via an input file.  This method works fine (i.e., I can get the app to dynamically load in the incompressibleLESModels lib and run).  But I would rather not rely on this method.  And the standard OpenFOAM apps don't do this.</p>
  
  <p>When I run ldd on my executable, the incompressibleLESModels library is clearly not in the list of libraries.</p>
  
  <p>So it is as if the linker detects that the library is not needed during the link phase and chooses not to link it in.  From what I understand, this may be due to definitions passed to gcc, particularly add-needed, or as-needed and no-as-needed.</p>
  
  <p>I am adding the following definitions via the ADD_DEFINITIONS command in CMake:</p>
  
  <pre><code>-DWM_DP  -m64  -Dlinux64  -Wall -Wextra -Wno-unused-parameter -Wold-style-cast 
  -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -fPIC -Xlinker 
  --add-needed -Xlinker --no-as-needed
  </code></pre>
  
  <p>Any ideas are greatly appreciated.</p>
  
  <p>Kind regards, Madeleine</p>