0

I would like to know how to link a pgc++ compiled code (blabla.a) with a main code compiled with c++ or g++ GNU compiler. For the moment linking with default gnu c++ linker gives errors like: undefined reference to `__pgio_initu'

2 Answers 2

3

As the previous person already pointed out, PGI supports G++ name mangling when using the pgc++ command. Judging from this output, I'm guessing that you're linking with g++ rather than pgc++. I've had the most success when using pgc++ as the linker so that it finds the PGI libraries. If that's not an option, you can link an executable with pgc++ -dryrun to get the full link line and past the -L and -l options from there to get the same libraries.

1
  • @MedAissa Can you please mark this answer as the solution for anyone who happens to search for this same problem in the future? Thanks.
    – jefflarkin
    Dec 10, 2015 at 15:12
0

Different C++ compilers use different name-mangling conventions to generate the names that they expose to the linker, so the member function name int A::foo(int) will be emitted to to the linker by compiler A as one string of goobledegook, and by compiler B as quite a different string of goobledegook, and the linker has no way of knowing they refer to the same function. Hence you can't link object files produced by different C++ compilers unless they employ the same name-mangling convention (and quite possibly not even then: name-mangling is just one aspect of ABI compatibility.)

That being said, according to this document, PGC++ supported name-mangling compatibility with g++ 3-and-half years ago, provided that PGI C++ compiler was invoked with precisely the command pgc++ or pgcpp --gnu. It may be that the library you are dealing with was not built in that specific way, or perhaps was built with an older PGI C++ compiler.

Anyhow, if g++ compiles the headers of your blabla.a and emits different symbols from the ones in blabla.a, you can't link g++ code with blabla.a. You'd need to rebuild blabla.a with g++, which perhaps is not an option.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.