0

Is there a way to link PGI Compiler binaries to existing GNU binaries? When I try to link I get following error:

oacc.c.o:(.init+0x8): undefined reference to `__pgio_ini'
collect2: ld returned 1 exit status

Details:

I have compiled a few files with gcc and g++. The C main function is included in these files. Now I should add a OpenACC function to project which must be compiled by PGI C Compiler (pgcc). After compile, I get the above link error (the error is the same for both pgCC or g++ as linker).

Maybe I need to integrate the OpenACC function into a dummy library and include/link it to the project. But I have no idea how to do that.

Unfortunately, entire project cannot be compiled with PGI Compiler, since some functions depend on GNU Compiler.

Thanks in advance.

lashgar
  • 5,184
  • 3
  • 37
  • 45
  • "Unfortunately, entire project cannot be compiled with PGI Compiler, since some functions depend on GNU Compiler." <- very bad design. But nevertheless, try putting the `-lwhatever` flags to the end of the command line. –  Oct 21 '12 at 12:40
  • As @H2CO3 says, if you compile one file with a compiler, and another file with a different compiler, you should be able to link those two files fine. It's the same machine code on the same platform, after all. – Archimaredes Oct 21 '12 at 12:41
  • @H2CO3 Simple Yet Working! I added `/opt/pgi/linux86-64/12.9/lib/libpgc.a` to the list of binaries during link. Please post your comment as the answer. Thanks! – lashgar Oct 21 '12 at 12:49
  • @ahmad You're welcome - there's the answer. –  Oct 21 '12 at 12:53
  • Just for a future reference, the C++ mangling in gcc is different than the one in PGI (basically, for C++ objects/functions etc you end up with different symbol names, so you cannot link). You should be able to link fine if you use C-linkage. – ipapadop Feb 16 '13 at 00:21

1 Answers1

1

Newer versions of the GCC-based GNU toolchain require that the files to be linked (object files and static and dynamic libraries) be specified in the order in which symbols depend on one another. Consequentially, you have to put external libraries' linker flags as the last parameters:

gcc -o prog prog.o -lfoo

is correct, whereas

gcc -o prog -lfoo prog.o

will result in a linker error.