Compilation from separate files!!

Hi guys!!

I have troubles compiling my code, i need some help and i hope you can help me.

I’m trying to compile the next files:

/home/madman/Desktop/Library/Fitness.cu
/home/madman/Desktop/Library/Fitness.h

/home/madman/Desktop/Library/Utils/Utils.cu
/home/madman/Desktop/Library/Utils/Utils.h

/home/madman/Desktop/Library/PSO/Lib_PSO.cu
/home/madman/Desktop/Library/PSO/Lib_PSO.h

/home/madman/Desktop/Library/PSO/Mono_PSO.cu
/home/madman/Desktop/Library/PSO/Mono_PSO.h

/home/madman/Desktop/Library/PSO/main.cu

and each files contains the next code:

/**Fitness.cu**/
#include "Fitness.h"
__device__ float getFitness( ... ){  ... }
__global__ void EvaluatePopulation( ... ){  ... }

/**Fitness.h**/
__device__ float getFitness( ... );
__global__ void EvaluatePopulation( ... );


/**Utils.cu**/
#include "Utils.h"
__device__ int RamdomNumber( ... ){ ... }
__global__ void initialize( ... ){ ... }

/**Utils.h**/
__device__ int RamdomNumber( ... );
__global__ void initialize( ... );


/**Lib_PSO.c**/
#include "Lib_PSO.h"
#include "Fitness.h"
#include "Utils.h"
void FitnessPopulation( ... ){
  ...
  initialize<<< n,m >>>( ... );//from Utils.h
  EvaluatePopulation<<< n,m >>>( ... );//from Fitness.h
  ...
}
void CalculateVelocity( ... ){ ... }

/**Lib_PSO.h**/
void FitnessPopulation( ... );
void CalculateVelocity( ... );


/**Mono_PSO.c**/
 void PSO_mono_Objetive( ... ){
    FitnessPopulation( ... );
    CalculateVelocity( ... );
 }

/**Mono_PSO.h**/
 void PSO_mono_Objetive( ... );


/**main.c**/
int main (int argc, char * argv[]){
   PSO_mono_Objetive( ... );
  return 0;
}

and i have tried to compile with:

nvcc -arch=sm_21 -dc ../Fitness.cu -lm
nvcc -arch=sm_21 -dc ../UtileriasMixtas/Utils.cu
nvcc -arch=sm_21 -dc Lib_PSO.cu
nvcc -arch=sm_21 -dc Mono_PSO.c
nvcc -arch=sm_21 -dc main.cu

and also i have tried:

nvcc -arch=sm_21 -dc main.cu Mono_PSO.c Lib_PSO.cu ../UtileriasMixtas/Utils.cu ../Fitness.cu -lm

and

nvcc -arch=sm_21 -dc ../Fitness.cu ../UtileriasMixtas/Utils.cu Lib_PSO.cu Mono_PSO.c main.cu -lm

Can someone help me with this, please?

I’m really confused n.n

You’re the best!!! thanks!!!

It is unclear what problem you are experiencing. What specifically doesn’t work, what errors are you seeing? For a worked example of separate compilation, take a look at this thread and in particular posts #9 and #10:

https://devtalk.nvidia.com/default/topic/526645/how-to-create-a-static-lib-for-device-functions-using-cuda-5-0-/

i forgoted show the problem, it’s with DEMono_CUDA.c:

madman@madman-G41M-Combo:~/Escritorio/Cuda/DE$ nvcc -arch=sm_21 -dc DEMono_CUDA.c
In file included from /usr/include/curand_kernel.h:67:0,
                 from DEMono_CUDA.h:14,
                 from DEMono_CUDA.c:2:
/usr/include/curand_philox4x32_x.h:109:84: error: expected ‘;’, ‘,’ or ‘)’ before ‘=’ token
 QUALIFIERS void Philox_State_Incr_carefully(curandStatePhilox4_32_10_t* s, uint64 n=1)
                                                                                    ^
/usr/include/curand_philox4x32_x.h:130:87: error: expected ‘;’, ‘,’ or ‘)’ before ‘=’ token
 QUALIFIERS void Philox_State_Incr_carefully_hi(curandStatePhilox4_32_10_t* s, uint64 n=1)
                                                                                       ^
/usr/include/curand_philox4x32_x.h: In function ‘Philox_State_Incr’:
/usr/include/curand_philox4x32_x.h:166:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
  for(int i=0; i<4; i++)
  ^
/usr/include/curand_philox4x32_x.h:166:2: note: use option -std=c99 or -std=gnu99 to compile your code
/usr/include/curand_philox4x32_x.h: In function ‘Philox_State_Incr_hi’:
/usr/include/curand_philox4x32_x.h:180:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
  for(int i=0; i<4; i++)
  ^
/usr/include/curand_philox4x32_x.h: At top level:
/usr/include/curand_philox4x32_x.h:186:17: error: conflicting types for ‘Philox_State_Incr’
 QUALIFIERS void Philox_State_Incr(curandStatePhilox4_32_10_t* s)
                 ^
/usr/include/curand_philox4x32_x.h:152:17: note: previous definition of ‘Philox_State_Incr’ was here
 QUALIFIERS void Philox_State_Incr(curandStatePhilox4_32_10_t* s, uint64 n)
                 ^
/usr/include/curand_philox4x32_x.h: In function ‘Philox_State_Incr’:
/usr/include/curand_philox4x32_x.h:196:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
  for(int i=0; i<4; i++)
...

thanks njuffa, i’m reading the thread, if i find the solution i’ll show it.

These compiler error messages would indicate ordinary syntax errors reported by the host compiler. That would appear to be gcc in this case. These have nothing to do with separate compilation. It would appear that you are compiling CUDA supplied header files with a C instead of a C++ compiler.

you’re right , you’re the best!!!

The problem was that my file had the name DEMono_CUDA.c
but it has to be DEMono_CUDA.cu

thanks a lot!!!