Note that there are some explanatory texts on larger screens.

plurals
  1. POg++ linking undefined reference even though my shared object has those methods
    text
    copied!<p>Edit: Answer found. Ignore</p> <p>Sorry to ask this question even though it's been asked so many times but I've checked like 20+ similar questions and none of them have helped.</p> <p>I've created a shared object and am now using it in a program that links to that .so. The program is not able to link (ld error). </p> <p><strong>memfxns.h:</strong></p> <pre><code>#ifndef MEM_H #define MEM_H char* getBuf(); void releaseBuf(char*); #endif </code></pre> <p><strong>memfxns.cpp:</strong></p> <pre><code>#include "memfxns.h" char* getBuffer() { char* ret_val = new char[4]; //fill the buffer here return ret_val; } void releaseBuffer(char* buf) { delete buf; } </code></pre> <p>These guys are compiled like so to produce a shared object (note I've tried without the -soname because it appears to be repetitive, but did not succeed):</p> <pre><code>g++ -Wall -fPIC -c ./*.cpp g++ -shared -Wl,-soname,libmemfxns.so -o ./libmemfxns.so ./*.o </code></pre> <p>Now I want to get my program to link against the new .so:</p> <p><strong>prog.cpp:</strong></p> <pre><code>#include &lt;stdio.h&gt; #include "memfxns.h" int main() { char* buf = getBuf(); for(int i = 0; i &lt; 4; i++) printf("%d\n", buf[i]); releaseBuf(buf); return 0; } </code></pre> <p>Which I compile using the command:</p> <pre><code>g++ ./prog.cpp -o prog -I/home/jbu/Desktop/hadooprelated/testjna/so/include -L/home/jbu/Desktop/hadooprelated/testjna/so -lmemfxns /tmp/ccOR12i1.o: In function `main': prog.cpp:(.text+0x9): undefined reference to `getBuf()' prog.cpp:(.text+0x55): undefined reference to `releaseBuf(char*)' collect2: error: ld returned 1 exit status make: *** [all] Error 1 </code></pre> <p>I'm fairly sure that it's able to find libmemfxns.so because when I purposely call -lmemfxnsdoesntexist it complains that it cannot find the .so. I'm also sure my -L and -I directories are correct.</p> <p>I'm not sure if I need some kind of namespace/scoping in my header file but I have not seen examples need that...</p> <p>Any help would be greatly appreciated.</p> <p>Thanks, -Julian</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload