Linking problem with nvcc strange name of functions in .o

Hello,

I’m compiling a .cu to a .o with nvcc, I use the C functions defined into the .cu in fortran files.

And then I’ve got an undefined reference. ifort is expecting something like “my_c_function_”.

Looking in the .o with nm, I see that my function that I named “my_c_function_” in the .cu is renamed

_Z15my_c_function_PfPiiii

or

_Z22my_c_function_PiS_S_S_S_S_S_PfS0_S_S_S_S_S_S_S , etc.

or some other weird names.

Does anyone know the reason of this and have an idea about how I could solve this problem?

Thanks

Make sure the name of C functions are in small letters or same as fortran’s. C is case - sensitive, Fortran is not. SO make sure ‘cases’ of both the functions are same.

Another thing : are using underscore with C functions to make them callable from Fortran ? cause if you are then remove that underscore and add this to your Fortran compiling options ( in make file or wherever) " -assume nounderscore " and then you dont need underscores. (I Assume you are using ifort).

also you have to compile ifort like given in the nvidia Fortran example… linking -lcudart together along with the .o object file

Thanks for reply.

Yes, I use ifort, but wrapped into mvapich.

I put my C functions in small case and I used to add an underscore at the end of them to have a compatibility with ifort.

For the first idea I’m using some external libraries which are not compiled with the “-assume nounderscore” so I don’t think it will work fine. But I’ll test it anyway.

I’ll ask the second thing to my system admin, cause I don’t know what he did.

Those function names look like C++ mangled ones. You’ll probably want to wrap the declarations in the header file inside something like

[codebox]#ifdef __cplusplus

extern “C” {

#endif

void myFunc1( void );

int myFunc2( int );

#ifdef __cplusplus

}

#endif[/codebox]

Thanks YDD, you found it.
But what I still don’t understand is why when I compile with --host-compilation C, it doesn’t work.