title: Building/Linking to TBB under MinGW
body: <p>I am building TBB under MinGW32 (on Windows 7 64 bit) and linking a simple program to it successfully. Unfortunately, my colleague is unable to do link successfully. We are both running the same version of Windows, the same version of MinGW (mingw-get-inst-20110802), and atttempting to compile the exact same code. Our PATH environment variable is exactly the same (.:/usr/local/bin:/mingw/bin:/bin). Yet, despite all things being equal (as far as I can tell), I can successfully build and run the program, my colleages attempts have failed at the link step. If I give him my tbb.dll, then he can successfully link his program. Thus, I am led to believe that there is something wrong about his build of tbb.dll. We have confirmed (using file) that we are producing 32-bit binaries for all object files and libraries</p>
  
  <pre><code>    $ file a.exe
      a.exe: PE32 executable for MS Windows (console) Intel 80386 32-bit
      $ file ./tbb/tbb30_20110704oss/lib/tbb.dll
      ./tbb/tbb30_20110704oss/lib/tbb.dll: PE32 executable for MS Windows (DLL) (console) Intel 80386 32-bit
  </code></pre>
  
  <p>The command line we are using to build TBB is:</p>
  
  <pre><code>    mingw32-make compiler=gcc arch=ia32 runtime=mingw tbb
  </code></pre>
  
  <p>The simple test program we are compiling is:</p>
  
  <pre><code>    #include &lt;tbb/task_scheduler_init.h&gt;
      using namespace tbb;
      int main() {
      task_scheduler_init init;
      return 0;
      }
  </code></pre>
  
  <p>The command line we are using to build the simple test program</p>
  
  <pre><code>    g++ test1.cpp -I ./tbb/tbb30_20110704oss/include -L ./tbb/tbb30_20110704oss/lib -ltbb
  </code></pre>
  
  <p>In my case, it builds and links flawlessly. In his case, he gets the error message:</p>
  
  <pre><code>    test1.o: In function `tbb::task_scheduler_init::task_scheduler_init(int, unsigned int)':
      test1.cpp:(.text._ZN3tbb19task_scheduler_initC1Eij[tbb::task_scheduler_init::task_scheduler_init(int, unsigned int)]+0x33): undefined reference to `tbb::task_scheduler_init::initialize(int, unsigned int)'
      test1.o: In function `tbb::task_scheduler_init::~task_scheduler_init()':
      test1.cpp:(.text._ZN3tbb19task_scheduler_initD1Ev[tbb::task_scheduler_init::~task_scheduler_init()]+0x16): undefined reference to `tbb::task_scheduler_init::terminate()'
  </code></pre>
  
  <p>The message seems to indicate that the linker is having a problem finding the symbols tbb::task_scheduler_init::initialize() and tbb_task_schedule_init::terminate(). However both of these symbols exist in tbb.dll (the nm output below is identical for both him and I):</p>
  
  <pre><code>    $ nm ../tbb/tbb30_20110704oss/lib/tbb.dll | grep task_scheduler_init
      676c9cb8 T __ZN3tbb19task_scheduler_init10initializeEi
      676c9c2c T __ZN3tbb19task_scheduler_init10initializeEij
      676c9b64 T __ZN3tbb19task_scheduler_init19default_num_threadsEv
      676c9afc T __ZN3tbb19task_scheduler_init9terminateEv
  </code></pre>
  
  <p>Can anyone offer any suggestion as to why I would be able to build and link this simple example, when my colleague cannot link, despite the fact that we are using the same exact tools, binaries, source code, operating system, etc??</p>