Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8817417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:50:36+00:00 2026-06-14T04:50:36+00:00

I have wrote a cuda application which has a main.cpp that includes a Common.h

  • 0

I have wrote a cuda application which has a main.cpp that includes a Common.h file

#include "Common.h"
int main(int argc , char **argv)
{
   ...
   DeviceFunc(a_h , numvar , b_h); //Showing the data
   ....
}

Then, Common.h contains:

 #ifndef __Common_H
 #define __Common_H
 #endif
 void DeviceFunc(float * , int , float *);

Also, DeviceFunc.cu is in the same folder:

 #include<cuda.h>
 #include<stdio.h>
 #include "Common.h"
 __device__ __global__ void Kernel(float *, float * ,int );
 void DeviceFunc(float *temp_h , int numvar , float *temp1_h)
 {
    float *a_d , *b_d;
    //Memory allocation on the device
    cudaMalloc(&a_d,sizeof(float)*(numvar)*(numvar+1));
    cudaMalloc(&b_d,sizeof(float)*(numvar)*(numvar+1));

    //Copying data to device from host
    cudaMemcpy(a_d, temp_h, sizeof(float)*numvar*(numvar+1),cudaMemcpyHostToDevice);

    //Defining size of Thread Block
    dim3 dimBlock(numvar+1,numvar,1);
    dim3 dimGrid(1,1,1);

    //Kernel call
    Kernel<<<dimGrid , dimBlock>>>(a_d , b_d , numvar);

    //Coping data to host from device
    cudaMemcpy(temp1_h,b_d,sizeof(float)*numvar*(numvar+1),cudaMemcpyDeviceToHost);

    //Deallocating memory on the device
    cudaFree(a_d);
    cudaFree(b_d);
 }

 }

Now when I compile the code with nvcc -o main main.cpp, I get this error main.cpp:(.text+0x3a0): undefined reference to 'DeviceFunc(float*, int, float*)'

What is the problem

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:50:37+00:00Added an answer on June 14, 2026 at 4:50 am

    Undefined function reference occurs when the compiler finds the prototype of the function and don’t find the reference to the function during link. To avoid this linking error, you should 1) compile-link whole files at one command, or 2) separate the compile and link process. I recommend the latter as follows:

    nvcc -c main.cpp
    nvcc -c DeviceFunc.cu
    nvcc -c Kernel.cu
    nvcc main.o DeviceFunc.o Kernel.o -o main
    

    NOTICE that your shown codes miss the file containing the body Kernel function. I’ve supposed the body of Kernel function is included in Kernel.cu.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have wrote an application that syncs two folders together. The problem with the
I have a CUDA application that is data movement bound (i.e. large memcopies from
I have wrote a little function to dynamically include CSS file or JS file.
I just have a question about my cuda program that I wrote. It allows
We have some nightly build machines that have the cuda libraries installed, but which
I have wrote a script to detect when I reach the div element which
I have wrote a script that was run from a spreadsheet. I had One
I Have wrote a question which got a right answer here about emysql encoding.
I have wrote the code below which was taken from Java How to program
I have wrote below code. import java.io.*; class Test { public static void main(String

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.