BLAS Replacement causes failure of matrix multiplication in Linux but not in windows
<p>I have downloaded and installed package <a href="https://projects.coin-or.org/qpOASES" rel="nofollow">qpOASES</a>.</p>

<p>Considering the following code:</p>

<pre><code>#define ARMA_DONT_USE_CXX11 /* In Cygwin */
#include &lt;armadillo&gt;

int main()
{

    arma::mat A;
    A
        &lt;&lt;0.0119&lt;&lt;0&lt;&lt;arma::endr
        &lt;&lt;0.0237&lt;&lt;0.0119&lt;&lt;arma::endr
        &lt;&lt;0.0354&lt;&lt;0.0437&lt;&lt;arma::endr
        &lt;&lt;0.0469&lt;&lt;0.0354;

    arma::mat B;
    B
    &lt;&lt;1.0&lt;&lt;0&lt;&lt;0&lt;&lt;0&lt;&lt;arma::endr
    &lt;&lt;0&lt;&lt;1.0&lt;&lt;0&lt;&lt;0&lt;&lt;arma::endr
    &lt;&lt;0&lt;&lt;0&lt;&lt;1.0&lt;&lt;0&lt;&lt;arma::endr
    &lt;&lt;0&lt;&lt;0&lt;&lt;0&lt;&lt;1.0;

    std::cout&lt;&lt;"A^T*B:"&lt;&lt;std::endl&lt;&lt;A.t()*B&lt;&lt;std::endl;

    return 0;
}
</code></pre>

<p>When I multiply two matrices it runs ok in windows:</p>

<pre><code>g++ test.cpp -std=c++11 -o bin/example1 -I/cygdrive/d/tmp/qpoases/qpOASES/include -I'C:\cygwin\usr\local\include\' -I'C:\cygwin\usr\include' -Wall -Wconversion -O3 -lqpOASES -larmadillo -L'C:\cygwin\usr\local\lib\' /cygdrive/d/tmp/qpoases/qpOASES/src/BLASReplacement.o -L/cygdrive/d/tmp/qpoases/qpOASES/bin /cygdrive/d/tmp/qpoases/qpOASES/src/LAPACKReplacement.o -Wfatal-errors -Wconversion

./bin/example1
A^T*B:
   0.0119   0.0237   0.0354   0.0469
        0   0.0119   0.0437   0.0354
</code></pre>

<p>But it fails under Linux (Ubuntu):</p>

<pre><code>g++ test.cpp -std=c++11 -g -o bin/example1  -Wall -Wconversion -O3 -lqpOASES -larmadillo  -L'qpoases' qpOASES/LAPACKReplacement.o qpOASES/BLASReplacement.o -Wfatal-errors -Wconversion

./bin/example1
A^T*B:
Segmentation fault (core dumped)
</code></pre>

<p>I have realized that what causes error is the <code>BLASReplacement</code>. So removing <code>BLASReplacement</code> the program works fine:</p>

<pre><code>g++ test.cpp -std=c++11 -g -o bin/example1  -Wall -Wconversion -O3 -lqpOASES -larmadillo  -L'qpoases' qpOASES/LAPACKReplacement.o -Wfatal-errors -Wconversion

./bin/example1
A^T*B:
   0.0119   0.0237   0.0354   0.0469
        0   0.0119   0.0437   0.0354
</code></pre>

<p>Here is a quick access to <a href="https://github.com/asherikov/qpOASES/blob/master/src/BLASReplacement.cpp" rel="nofollow">BLASReplacement.cpp</a>.</p>

<p>It seems using <code>qpOASES</code> and <code>armadillo</code> together makes problem for me using Linux. What causes this problem and why this problem does not exist in my Windows?</p>

<hr>

<p><strong>UPDATE</strong></p>

<p>I used code-block as a debugger and found the last line causing error:</p>

<pre><code>typedef double T;
arma_fortran(arma_dgemm)(transA, transB, m, n, k, (const T*)alpha, (const T*)A, ldA, (const T*)B, ldB, (const T*)beta, (T*)C, ldC);
</code></pre>

<p>And the definition of this wrapper is in <code>def_blas.hpp</code></p>

<pre><code>extern "C"
  {
     ...
     void arma_fortran(arma_dgemm)(const char* transA, const char* transB, const blas_int* m, const blas_int* n, const blas_int* k, const double* alpha, const double* A, const blas_int* ldA, const double* B, const blas_int* ldB, const double* beta, double* C, const blas_int* ldC);
     ...
  }
</code></pre>

<p>A github fork to <code>Armadillo</code> library is <a href="https://github.com/RcppCore/RcppArmadillo/" rel="nofollow">here</a>.</p>

<p>It is in <code>blas_wrapper.hpp</code> inside <code>armadillo</code> seems <code>dgemm</code> of <code>armadillo</code> and <code>BLASReplacement.o</code> of <code>qpOASES</code> are clashing. What is the best way to get around it?</p>