Compilation séparée : erreurs lors de l'édition des liens
Bonjour je viens demander de l'aide car je n'y arrive pas.
J'essaie de compiler un programme CUDA C ecrit sur plusieurs fichier different.
Voici la structure de mon code (ce n'est pas mon vrai code mais un autre plus court ayant le meme type de strucure):
-----main.c-----
Code:
1 2 3 4 5 6 7 8 9
| #include <stdio.h>
#include <stdlib.h>
#include "initialisation.h"
int main() {
int *res = initialisation();
free(res);
return 0;
} |
----initialisation.h----
Code:
int* initialisation();
----inititialisation.cu---
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| #include <cuda_runtime.h>
#include <stdio.h>
__global__ void init(int* c_tab) {
int idx = threadIdx.x;
c_tab[idx] = 0;
}
int* initialisation() {
int nBytes = sizeof(int) * 100;
int* tab = (int*)malloc(nBytes);
int* c_tab;
cudaMalloc(&c_tab, nBytes);
init <<< 1,100 >>> (c_tab);
cudaMemcpy(tab, c_tab, nBytes, cudaMemcpyDeviceToHost);
cudaFree(c_tab);
return tab;
} |
-------------
Et voici mon makefile :
----makefile----
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| ARCH=--gpu-architecture=sm_60
EXTENSION_OBJET=obj #pour pouvoir switch entre mon ordi windows et linux
all: test
test: main.$(EXTENSION_OBJET) initialisation.$(EXTENSION_OBJET)
nvcc $(ARCH) -rdc=true --output-file test main.$(EXTENSION_OBJET) initialisation.$(EXTENSION_OBJET)
main.$(EXTENSION_OBJET): main.c initialisation.h
g++ -o main.$(EXTENSION_OBJET) -c main.c
initialisation.$(EXTENSION_OBJET): initialisation.cu
nvcc $(ARCH) -rdc=true --output-file initialisation.$(EXTENSION_OBJET) -c initialisation.cu |
Et voici l'erreur que j'obtiens :
Citation:
main.obj : error LNK2019: unresolved external symbol __main referenced in function main
main.obj : error LNK2019: unresolved external symbol _Z14initialisationv referenced in function main
Merci pour votre aide :)