# Compiling Fortran CUBLAS example

**URL:** <https://forums.developer.nvidia.com/t/compiling-fortran-cublas-example/2454>\
**Category:** CUDA Programming and Performance\
**Created:** [January 28, 2008, 5:29pm UTC](https://forums.developer.nvidia.com/t/compiling-fortran-cublas-example/2454 "2008-01-28T17:29:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![NsK](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@NsK](https://forums.developer.nvidia.com/u/NsK)\
**Post date:** [January 28, 2008, 5:29pm UTC](https://forums.developer.nvidia.com/t/compiling-fortran-cublas-example/2454/1 "2008-01-28T17:29:34Z")

</div>

Hello,

First of all, I would like to highlight the fact that I am a total newby in the CUDA area…:)  
I am currently struggling a lot trying to compile the Fortran CUBLAS example (Fortran\_Cuda\_Blas.tgz) under Windows XP with Microsoft Visual Studio 2005 (using Intel Fortran Compiler).  
I have linked my code with the library “cublas.lib” but I still obtain this :

"  
1\>Compiling with Intel® Fortran Compiler 10.1.011 [IA-32]…  
1\>sgemm\_speed.f90  
1\>D:\Projects\CUDA\ICUBLAS\sgemm\_speed.f90(37) : Warning: Bad # preprocessor line  
1\>D:\Projects\CUDA\ICUBLAS\sgemm\_speed.f90(39) : Warning: Bad # preprocessor line  
1\>D:\Projects\CUDA\ICUBLAS\sgemm\_speed.f90(41) : Warning: Bad # preprocessor line  
1\>Linking…  
1\>sgemm\_speed.obj : error LNK2019: unresolved external symbol _CUBLAS\_SGEMM referenced in function MAIN_  
1\>sgemm\_speed.obj : error LNK2019: unresolved external symbol _SGEMM referenced in function MAIN_  
1\>Debug\icublas.exe : fatal error LNK1120: 2 unresolved externals  
"

I am quit sure it s because I don t manage to link with the fortran.o (\*) needed :rolleyes: …

I would be very grateful if someone could have the start of the beginning of a solution for me… thanks

(\*): this should be the object file result of the utility code “fortran.c” which takes care of the name mangling and decoration of different Fortran compilers.

---

<div class="post-metadata">

**Author:** ![LOlo](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@LOlo](https://forums.developer.nvidia.com/u/LOlo)\
**Post date:** [March 12, 2008, 7:27am UTC](https://forums.developer.nvidia.com/t/compiling-fortran-cublas-example/2454/2 "2008-03-12T07:27:13Z")

</div>

> [@](#):
>
> Hello,
> 
> First of all, I would like to highlight the fact that I am a total newby in the CUDA area…:)
> 
> I am currently struggling a lot trying to compile the Fortran CUBLAS example (Fortran\_Cuda\_Blas.tgz) under Windows XP with Microsoft Visual Studio 2005 (using Intel Fortran Compiler).
> 
> I have linked my code with the library “cublas.lib” but I still obtain this :
> 
> "
> 
> 1\>Compiling with IntelÂ® Fortran Compiler 10.1.011 [IA-32]…
> 
> 1\>sgemm\_speed.f90
> 
> 1\>D:\Projects\CUDA\ICUBLAS\sgemm\_speed.f90(37) : Warning: Bad # preprocessor line
> 
> 1\>D:\Projects\CUDA\ICUBLAS\sgemm\_speed.f90(39) : Warning: Bad # preprocessor line
> 
> 1\>D:\Projects\CUDA\ICUBLAS\sgemm\_speed.f90(41) : Warning: Bad # preprocessor line
> 
> 1\>Linking…
> 
> 1\>sgemm\_speed.obj : error LNK2019: unresolved external symbol _CUBLAS\_SGEMM referenced in function MAIN_
> 
> 1\>sgemm\_speed.obj : error LNK2019: unresolved external symbol _SGEMM referenced in function MAIN_
> 
> 1\>Debug\icublas.exe : fatal error LNK1120: 2 unresolved externals
> 
> "
> 
> I am quit sure it s because I don t manage to link with the fortran.o (\*) needed&nbsp; :rolleyes: …
> 
> I would be very grateful if someone could have the start of the beginning of a solution for me… thanks
> 
> (\*): this should be the object file result of the utility code “fortran.c” which takes care of the name mangling and decoration of different Fortran compilers.
> 
> [snapback]316236[/snapback]

Maybe you can try to change in your code CUBLAS\_SGEMM with cublasSgemm. The function defintions appears to be different than the fortran sample code.

---

<div class="post-metadata">

**Author:** ![sachin](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@sachin](https://forums.developer.nvidia.com/u/sachin)\
**Post date:** [February 3, 2009, 3:29am UTC](https://forums.developer.nvidia.com/t/compiling-fortran-cublas-example/2454/3 "2009-02-03T03:29:47Z")

</div>

> [@](#):
>
> Maybe you can try to change in your code CUBLAS\_SGEMM with cublasSgemm. The function defintions appears to be different than the fortran sample code.

I had a similar problem. i was trying to call a cublas function (say sgemm for now) from fortran.

[codebox]SUBROUTINE DGEMM ( TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB,

```
 $ BETA, C, LDC )

  external CUBLAS_DGEMM 

  CALL CUBLAS_DGEMM( TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB,

 $ BETA, C, LDC )

  END[/codebox]

```

because fortran is case INsensitive it automatically converts it to \_cublas\_dgemm before calling the fortran.c function. Note there is underscore BEFORE the function. this is something that fortran always does when calling functions.

Now if this doesnt fix the problem (which i dont think did for me). the dodgy way of fixing it is get rid of all the defenitions for the different compilers (comment them out) and add

#define CUBLAS\_FORTRAN\_COMPILER CUBLAS\_G77

at the end of the commented out block

let me know if this helps
