Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29274 Discussions

Multiple definition is allowed when linking library.

haifeng2009
Beginner
709 Views
Hello,

In my code development, I need to build some source code into a library AA and link this librarywith another code BB. Everything works all right. But I noticed that there were multiple definitions in AA and BB when I do the linking.

For example, I have a module file CC which is used in building AA library. Now when I link BB with library AA, I have the same module file CC in BB. IVF compiles and links AA and BB without any warning.

I am wondering whetherthisis normal. Which CC is used in AA and BB? In my case, the module file CC happened to be the same when building AA and BB. What about module file CChave different content (but with the same module name) in AA and BB? Which CC is used in AA and BB?

I hope I have made myself clear about my question.

Thanks,
Haifeng

0 Kudos
1 Reply
Steven_L_Intel1
Employee
709 Views

If module CC has the same symbols in both libraries, then whichever library is seen first will resolve references and the module from the other library will be unused. If the two instances of module CC have different symbols, and there are references to symbols such that both versions of CC are required to satisfy the references, then you'll get a linker error (unless the linker option /force:multiple is specified.)

The compiler can't check this, and having two modules of the same name in a Fortran program is not valid Fortran.
0 Kudos
Reply