# compiling/linking gcc/nvcc objects with pgfortran

**URL:** <https://forums.developer.nvidia.com/t/compiling-linking-gcc-nvcc-objects-with-pgfortran/134384>\
**Category:** Legacy PGI Compilers (archived)\
**Created:** [February 13, 2015, 9:15am UTC](https://forums.developer.nvidia.com/t/compiling-linking-gcc-nvcc-objects-with-pgfortran/134384 "2015-02-13T09:15:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![galanti](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@galanti](https://forums.developer.nvidia.com/u/galanti)\
**Post date:** [February 13, 2015, 9:15am UTC](https://forums.developer.nvidia.com/t/compiling-linking-gcc-nvcc-objects-with-pgfortran/134384/1 "2015-02-13T09:15:56Z")

</div>

Dear All,  
I have the following problem:  
gfortran -c -fcray-pointer -O3 main.for  
nvcc -c cppcode.cu  
gfortran \*.o -lstdc++ -L/usr/local/cuda-6.5/lib64/ -lcudart

My question is how to do it with pgfortran.

Thanks,  
Barak

---

<div class="post-metadata">

**Author:** ![MatColgrove](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/matcolgrove/32/14047_2.png) [@MatColgrove](https://forums.developer.nvidia.com/u/MatColgrove)\
**Post date:** [February 13, 2015, 4:25pm UTC](https://forums.developer.nvidia.com/t/compiling-linking-gcc-nvcc-objects-with-pgfortran/134384/2 "2015-02-13T16:25:26Z")

</div>

Hi Barak,

It should be the same for pgfortran. Though you could use the -Mcuda flag to link instead of explicitly adding the CUDA libraries.

- Mat

---

<div class="post-metadata">

**Author:** ![galanti](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@galanti](https://forums.developer.nvidia.com/u/galanti)\
**Post date:** [February 13, 2015, 4:53pm UTC](https://forums.developer.nvidia.com/t/compiling-linking-gcc-nvcc-objects-with-pgfortran/134384/3 "2015-02-13T16:53:29Z")

</div>

Hi Mat,  
This is the gnu sequence:  
gfortran -c -fcray-pointer -O3 main.for  
nvcc -c cppcode.cu  
gfortran \*.o -lstdc++ -L/usr/local/cuda-6.5/lib64/ -lcudart

and what I do with pgfortran:  
pgfortran -c -Mcray=pointer -O3 main.for -Mfree  
nvcc -c cppcode.cu  
pgfortran -Mcuda -o …/load\_lib.exe ext\_lib.o -lstdc++  
and I get:  
/usr/bin/ld: ext\_lib.o: undefined reference to symbol ‘\_Unwind\_Resume@@GCC\_3.0’  
//lib/x86\_64-linux-gnu/libgcc\_s.so.1: error adding symbols: DSO missing from command line  
pgacclnk: child process exit status 1: /usr/bin/ld

Thanks,  
Barak

---

<div class="post-metadata">

**Author:** ![MatColgrove](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/matcolgrove/32/14047_2.png) [@MatColgrove](https://forums.developer.nvidia.com/u/MatColgrove)\
**Post date:** [February 13, 2015, 8:31pm UTC](https://forums.developer.nvidia.com/t/compiling-linking-gcc-nvcc-objects-with-pgfortran/134384/4 "2015-02-13T20:31:05Z")

</div>

Hi Barak,

I tried to recreate your issue here but my example just worked, so I’m not positive why you’re getting this.

One thought is that there’s a mismatch between the CUDA versions being used. Since it appears your nvcc is 6.5, try using “-Mcuda=cuda6.5”.

Another thing to try is add “-pgc++libs” to the link line. This will bring in the PGI C++ runtime libraries as well as some of the system C++ libraries.

- Mat

---

<div class="post-metadata">

**Author:** ![galanti](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@galanti](https://forums.developer.nvidia.com/u/galanti)\
**Post date:** [February 13, 2015, 10:12pm UTC](https://forums.developer.nvidia.com/t/compiling-linking-gcc-nvcc-objects-with-pgfortran/134384/5 "2015-02-13T22:12:31Z")

</div>

Hi Mat,  
Here is now a working combination:  
I added in the C++ code the two lines:  
#define TRUE 0xff  
#define FALSE 0

and the linking is:  
pgfortran cppcode.o main.o -pgc++libs -Mcuda=cuda6.0

Thanks a lot!  
Barak
