title: LDFLAGS in Qt pro file
body: <p>I have a Qt project that I'm compiling with GCC and MinGW for Ubuntu and Windows.</p>
  
  <blockquote>
    <p>I got a requirement to harden it by adding the following LDFLAGS:</p>
    
    <ul>
    <li>Stack execution protection: <code>LDFLAGS="-z noexecstack"</code></li>
    <li>Data relocation and protection (RELRO): <code>LDLFAGS="-z relro -z now"</code></li>
    </ul>
  </blockquote>
  
  <p>The question is can this be done with .pro file and how? I found it easy to add LFLAGS and CFLAGS in the project file but couldn't find anything for LDFLAGS. Even the output Makefiles don't seem to have any LDFLAGS defined.</p>
  
  <p>One way I found after long googling was to add <code>QMAKE_CFLAGS_RELEASE += "--noexecstack"</code> in the .pro file but I'm not convinced this is the right way.</p>
  
  <p>After the line above, the generated Makefile looks like this:</p>
  
  <pre><code>CC            = gcc
  CXX           = g++
  DEFINES       = -DUNICODE -DMY_LIBRARY -DQT_NO_DEBUG -DQT_NETWORK_LIB -DQT_CORE_LIB
  CFLAGS        = -pipe -fno-keep-inline-dllexport -O2 -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security --noexecstack -Wall -Wextra $(DEFINES)
  CXXFLAGS      = -pipe -fno-keep-inline-dllexport -O2 -frtti -Wall -Wextra -fexceptions -mthreads $(DEFINES)
  LINKER        = g++
  LFLAGS        = -Wl,-s -shared -Wl,-subsystem,windows -mthreads -Wl,--out-implib,C:\libmylib0.a
  </code></pre>
  
  <p>noexecstack appears in the <code>CLFAGS</code> list but not sure if that's alright. <code>CFLAGS</code> is not the same as <code>LDFLAGS</code>. It doesn't seems to validate the command either since <code>--thisdoesntexist</code> seemed to go through as well when I tried.</p>
  
  <p>Thank you in advance.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Based on Gwen's answer I tried adding <code>QMAKE_LFLAGS += "-z noexecstack -z relro -z now"</code> but this produced an error from ld.exe:
  <code>error: unrecognized option '-z'</code></p>
  
  <p><strong>EDIT2:</strong></p>
  
  <p>Tool versions:</p>
  
  <pre><code>C:\Qt\Qt5.5.0\Tools\mingw492_32\bin&gt;ld.exe -v
  GNU ld (GNU Binutils) 2.24
  
  C:\Qt\Qt5.5.0\Tools\mingw492_32\bin&gt;g++.exe --version
  g++.exe (i686-posix-dwarf-rev1, Built by MinGW-W64 project) 4.9.2
  </code></pre>