I have cuda code which makes a call to a function present in a .c file whose header file I have included in my cuda code. So, in all I have a header file, a C file for that header file, and a CUDA code. When I am compiling my CUDA code using nvcc and specifying my cuda code name and c file name, then I am getting undefined reference to the functions I called in my CUDA code which are actually present in my C file. Please help me understand what am I doing wrong and how can I fix my mistake.
Ok I am pasting my code below... I did not post it initially because I thought its a linker error or something.
#include "dbConnection.h"
#include "error.h"
#include "libpq-fe.h"
#include <stdio.h>
#include <stdlib.h>
#include "appCompileSwitches.h"
int makeConnection(PGconn** conn,const char* connInfo);
void executeQuery(PGconn* conn,PGresult** res,char* statement,int* rows,int* columns);
/***************************************
* main(), enough said
****************************************/
int main(int argc, char **argv)
{
PGconn *conn = NULL;
PGresult *res= NULL;
float** result;
char* statement = "select visit_no,brand_name from visit_sample limit 3";
int rows=0,columns=0; // WILL BE USED TO CUDAMALLOC gpu memory
const char* connInfo = "dbname = moxy";
if(!makeConnection(&conn,connInfo))
{
printf("failed to connect to Database!\n");
return FAILURE;
}
}
The dbConnection.c file has :
#include <stdio.h>
#include <stdlib.h>
#include "libpq-fe.h"
#include <string.h>
#include "dbConnection.h"
#include "error.h"
#include "appCompileSwitches.h"
/****************************************************
* close database connection, given connecton info
****************************************************/
static void closeConnection(PGconn *conn)
{
/* close the connection to the database and cleanup */
PQfinish(conn);
}
/****************************************************
* connect to the database
* given the connInfo
****************************************************/
extern int makeConnection(PGconn** conn,const char* connInfo)
{
/* Make a connection to the database */
*conn = PQconnectdb(connInfo);
if (PQstatus(*conn) != CONNECTION_OK)
{
fprintf(stderr, "Connection to database failed: %s",PQerrorMessage(*conn));
PQfinish(*conn);
return FAILURE;
}
return SUCCESS;
}
So when I am doing:
nvcc DB.cu dbConnection.c -o DB
I am getting undefined reference to make connection. Also, I will be transferring the data I get from DB to GPGPU later and that is the whole point of this exercise so please do not say I have no CUDA calls here. This is a code still under development.