title: How to flag variables to avoid linker optimization (C)
body: <p>I am building static libraries with CMake, but the final linking process happens in a custom make script. In one of the components that build a library, there is a table that's not used in the code, but contains version information and has to end up in the final executable.</p>
  <p>The compiler here is tasking, but its linker should behave similar to gcc.</p>
  <p>Currently there is a makefile that defines a linker option to achieve that:</p>
  <pre><code>LINK_OPT += --extern=MyTable myLibrary.a
  </code></pre>
  <p>which I am reasonably sure is the equivalent of gcc's <code>--undefined=MyTable myLibrary.a</code>.</p>
  <p>My goal is to get rid of those makefiles, so the component can be defined solely in CMake. The issue I have is that, due to how the build is set up with the linking not happening in the CMake context, simply attaching linker options to the static library targets in CMake won't help, as they aren't available when I actually link.</p>
  <p>I have tried using <code>__attribute__((used))</code> and <code>__attribute__((export))</code> in the source code, but they didn't help. I checked the compiler supports them, and suspect they would work if I simply linked object files instead of libraries(?)</p>
  <p>Is there any meta information I can attach to the library or the source code that tells the linker to please include MyTable in the executable, without me having to specify a linker option on the linker command line?</p>