Note that there are some explanatory texts on larger screens.

plurals
  1. POStatic library with multiple .h and .cu files can't resolve functions
    primarykey
    data
    text
    <p>When compiling a static library with multiple.h and .cu files I get an unresolved extern function. Here is a short example that replicates the error.</p> <p>It appears that I can't get Nsight Eclipse Edition to compile extrafunctions.cu first. In my full project the file with extra functions <em>is</em> compiled first but it still throws the unable to resolve external function error.</p> <p>Here's the output for this sample:</p> <pre><code>**** Build of configuration Debug for project linkerror **** make all Building file: ../cudatest.cu Invoking: NVCC Compiler nvcc -I/usr/local/cuda/include -G -g -O0 -gencode arch=compute_30,code=sm_30 -odir "" -M -o "cudatest.d" "../cudatest.cu" nvcc --compile -G -I/usr/local/cuda/include -O0 -g -gencode arch=compute_30,code=compute_30 -gencode arch=compute_30,code=sm_30 -x cu -o "cudatest.o" "../cudatest.cu" ../cudatest.cu(19): warning: variable "devInts" is used before its value is set ../cudatest.cu(19): warning: variable "devInts" is used before its value is set ptxas fatal : Unresolved extern function '_Z9incrementi' make: *** [cudatest.o] Error 255 **** Build Finished **** </code></pre> <p>cudatest.h:</p> <pre><code>#ifndef CUDAPATH_H_ #define CUDAPATH_H_ #include &lt;cuda.h&gt; #include &lt;cuda_runtime.h&gt; #include "extrafunctions.h" void test(); #endif /* CUDAPATH_H_ */ </code></pre> <p>cudatest.cu:</p> <pre><code>#include &lt;cuda.h&gt; #include &lt;cuda_runtime.h&gt; #include "extrafunctions.h" __global__ void kernel(int* devInts){ int tid = threadIdx.x + (blockDim.x*blockIdx.x); if (tid == 0){ for(int i = 0; i &lt; NUMINTS; i++){ devInts[i] = increment(devInts[i]); } } } void test(){ int* myInts = (int*)malloc(NUMINTS * sizeof(int)); int* devInts; cudaMemcpy((void**)devInts, myInts, NUMINTS*sizeof(int), cudaMemcpyHostToDevice); kernel&lt;&lt;&lt;1,1&gt;&gt;&gt;(devInts); int* outInts = (int*)malloc(NUMINTS * sizeof(int)); cudaFree(devInts); free(myInts); free(outInts); } </code></pre> <p>extrafunctions.h:</p> <pre><code>#ifndef EXTRAFUNCTIONS_H_ #define EXTRAFUNCTIONS_H_ #include &lt;cuda.h&gt; #include &lt;cuda_runtime.h&gt; #define NUMINTS 4 int __device__ increment(int i); #endif /* EXTRAFUNCTIONS_H_ */ </code></pre> <p>extrafunctions.cu:</p> <pre><code>#include &lt;cuda.h&gt; #include &lt;cuda_runtime.h&gt; #include "extrafunctions.h" int __device__ increment(int i){ return i+1; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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