title: Cannot find symbol in linked library
body: <p>I'm trying to create go app, which uses some C++ code from sdk in shared library.<br />
  Added reference to target library with <code>#cgo LDFLAGS</code>:</p>
  <pre><code>#cgo LDFLAGS: -L/opt/cprocsp/lib/amd64 -lxades -v
  </code></pre>
  <p>and build go app with</p>
  <pre><code>go build -o main .
  </code></pre>
  <p>Compilation goes ok, but linking fails with error</p>
  <pre><code>/usr/bin/ld: $WORK/b001/_x003.o: undefined reference to symbol 'CryptReleaseContext'
  /usr/bin/ld: //opt/cprocsp/lib/amd64/libcapi10.so.4: error adding symbols: DSO missing from command line
  collect2: error: ld returned 1 exit status
  </code></pre>
  <p>Function CryptReleaseContext exists in <code>/opt/cprocsp/lib/amd64/libxades.so</code>.</p>
  <p>With <code>-v</code> option I noticed linker arguments order</p>
  <pre><code>/usr/lib/gcc/x86_64-linux-gnu/8/collect2 ... $WORK/b001/_cgo_main.o $WORK/b001/_x001.o $WORK/b001/_x002.o $WORK/b001/_x003.o -lxades -lstdc++ ...
  </code></pre>
  <p>With Google I found that arguments order may be important, but I can't find a way to control them and stucking with it. How can I build app?</p>
  <p>Example:<br />
  <strong><code>main.go</code></strong></p>
  <pre><code>package main
  
  import &quot;log&quot;
  
  func main() {
      data := &quot;&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;UTF-8\&quot;?&gt;&quot; +
          &quot;&lt;Envelope xmlns=\&quot;urn:envelope\&quot;&gt;&quot; +
          &quot;&lt;Data&gt;Hello, World!&lt;/Data&gt;&quot; +
          &quot;&lt;Node xml:id=\&quot;nodeID\&quot;&gt;Hello, Node!&lt;/Node&gt;&quot; +
          &quot;&lt;/Envelope&gt;&quot;
      signed := Sign(data)
      log.Print(signed)
  }
  </code></pre>
  <p><strong><code>signer.go</code></strong></p>
  <pre><code>package main
  
  /*
  #cgo LDFLAGS: -L/opt/cprocsp/lib/amd64 -lxades -v
  #include &lt;stdarg.h&gt;
  #include &lt;stdlib.h&gt;
  #include &quot;signer.h&quot;
  */
  import &quot;C&quot;
  import &quot;log&quot;
  import &quot;unsafe&quot;
  
  func Sign(data string) (result string) {
      log.Print(&quot;Signing message&quot;)
      c_data := C.CString(data)
      defer C.free(unsafe.Pointer(c_data))
      c_result := C.CString(result)
      defer C.free(unsafe.Pointer(c_result))
      C.sign(c_data, c_result)
      return C.GoString(c_result)
  }
  </code></pre>
  <p><strong><code>signer.h</code></strong></p>
  <pre><code>void sign(char* src, char *dst);
  </code></pre>
  <p><strong><code>signer.cpp</code></strong><br />
  SDK's example code, that uses functions from <code>/opt/cprocsp/lib/amd64/libxades.so</code></p>
  <pre><code>...
  
  extern &quot;C&quot; {
      void sign(char* src, char *dst){
          BYTE *pbToBeSigned = (BYTE *) src;
          DWORD cbToBeSigned = strlen(src);
          static XADES_SIGN_MESSAGE_PARA signParams = { sizeof(signParams) };
          initSignParams(&amp;signParams);
          PCRYPT_DATA_BLOB pSignedMessage = 0;
          // Создаем подписанное сообщение
          if (!XadesSign(&amp;signParams, NULL, FALSE, pbToBeSigned, cbToBeSigned, &amp;pSignedMessage)) {
              cout &lt;&lt; &quot;XadesSign() failed&quot; &lt;&lt; endl;
              return;
          }
  
          vector&lt;unsigned char&gt; message(pSignedMessage-&gt;cbData);
          copy(pSignedMessage-&gt;pbData, pSignedMessage-&gt;pbData + pSignedMessage-&gt;cbData, message.begin());
          char* result = reinterpret_cast&lt;char*&gt;(message.data());
          strcpy(dst, result);
      }
  }
  </code></pre>
  <p><strong>Update</strong></p>
  <pre><code>#cgo LDFLAGS: -L/opt/cprocsp/lib/amd64 -Wl,-rpath,/opt/cprocsp/lib/amd64 -lxades -v
  </code></pre>
  <p>didn't help</p>