linking pgi compiled library with gcc linker

ε祈祈猫儿з 提交于 2020-01-03 05:50:06

问题


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'


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/33656205/linking-pgi-compiled-library-with-gcc-linker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!