Hi, I have built a simple cuda project in visual studio that works perfectly fine when it is compiled alone.
However I want to use it in a cpp project, so I’ve referenced the project in my cpp one and added the include folder and the dependencies files.
I have also changed the cuda project configuration type as a static library.
Here is a typical header file of the cuda project
// whatever.h
#pragma once
#include <vector>
std::vector<double> doMath(const std::vector<double>& input);
and here a typical cu file of the cuda project
// whatever.cu
#include "whatever.h"
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
__global__ void kernel(double* input, double* output)
{
// ...
}
void doMath(const std::vector<double>& input)
{
double* dInput;
cudaMalloc(&dInput, input.size() * sizeof(double));
cudaMemcpy(dInput, input.begin(), input.size() * sizeof(double), cudaMemcpyHostToDevice);
double* dOutput;
cudaMalloc(&dOutput, input.size() * sizeof(double))
kernel<<<1,1>>>(dInput, dOutput);
std::vector<double> output(input.size());
cudaMemcpy(output.begin(), dOutput, input.size() * sizeof(double), cudaMemcpyDeviceToHost);
return output;
}
The main file of the cpp project looks like this
// main.cpp
#include <iostream>
#include <vector>
#include "whatever.h"
int main()
{
std::vector<double> input = {0,1,2,3,4,5,6};
std::vector<double> output = doMath(input);
for(double o: output) std::cout << o << ' ';
return 0;
}
Why do I get this error “error LNK2019: unresolved external symbol cudaMalloc” ?
Why isn’t it working, I haven’t use any cuda code in the header files.
How can I make this work ?