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

Linking ifort and icpc object files on Mac OS X

wclodius
Beginner
670 Views

I am trying to compare the outputs of a C++ procedure with the output of a Fortran translation of that procedure. The comparisons are being performed on a MacBook Pro with a 2.3 GHz Quad-Core Intel Core i5, running macOS Big Sur, version 11.6. The main system libraries are at Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/, and the main system header  files are at /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include and  /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/tidy. I am running on the Terminal command line with a manual Makefile. I am using the OneAPI compiler set 2021.2.0 20210228.

I have the equivalent following files to compile and link:

1. The original C++ source file, ./cpp_source.cpp.

2. The header file to that source file, ./cpp_source.h.

3. A C++ source file, ./cpp_extern.cpp, which provides extern C wrappers to the original source file and includes the above header file.

4. A "Fortran 90" file, ./fortran_wrapper.f90, which defines a module, fortran_wrapper, that provides C interoperability wrappers to the extern C wrappers.

5. A bunch of Fortran source code two directory levels down. These are precompiled into a library, ../../libfortran_code.a with module files in  the directory ../../mod_files.

6. A fortran main program file, ./fortran_main.f90, that calls a function, cpp_fun, defined in fortran_wrapper, and two function, fortran_fun and fun_input, defined in module, fun_module  accessed in libfortran_code.

Compilation of the files has no obvious problems. The cpp files ./cpp_source.cpp and ./cpp_extern.cpp, are compiled and stored in a library, ./libcpp_fun.a. The file ./fortran_wrapper.f90 is compiled to the object file, ./fortran_wrapper.o, with the mod file, ./mod_files/fortran_wrapper.mod. The main program file, ./fortran_main.f90, is compiled to the object file, ./main_program.o.

Linking the object files and libraries, however, returns the equivalent errors:

... % make -f Makefile.validation

ifort -O3 -I../../mod_files -module ./mod_files -L../../ -L./ -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/ fortran_main.o fortran_wrapper.o -lfortran_code -lcpp_fun -o fortran_main

Undefined symbols for architecture x86_64:

  "___gxx_personality_v0", referenced from:

      Dwarf Exception Unwind Info (__eh_frame) in libcpp_fun.a(cpp_extern.o)

      Dwarf Exception Unwind Info (__eh_frame) in libcpp_fun.a(cpp_source.o)

  "_fun_module_mp_fortran_fun_", referenced from:

      _MAIN__ in fortran_main.o

  "_fun_module_mp_fun_input_", referenced from:

      _MAIN__ in fortran_main.o

ld: symbol(s) not found for architecture x86_64

make: *** [test_64_bit_hash_validation] Error 1

 

The symbol "___gxx_personality_v0" appears to be related to C++ exception handling. Does that require linking with icpc, or does it require linking in an additional library? If it requires linking with icpc does that require a C++ main, and converting fortran_main to a C interoperability subroutine?

The problems with "_fun_module_mp_fortran_fun_" and "_fun_module_mp_fun_input_" appears to indicate problems with finding the appropriate symbols in the library ../../libfortran_code, or its associated module files in ../../mod_files. Is it obvious whether it is the library or the mod files that is the problem? If so how can  I change the link command to fix the problem?

 

Labels (1)
0 Kudos
3 Replies
Barbara_P_Intel
Moderator
646 Views

Check this out in the Fortran Developer Guide.  If your analysis is correct about exception handling, there are some additional libraries to link in.

wclodius
Beginner
598 Views

The libraries mentioned in the Fortran Developer Guide helped with the Dwarf exception. Do you know if the other messages indicate a failure to find the library or a failure to find the module (.mod/.smod) files? The command line options are rather diverse. Do you  know the best commands for specifying library and module file locations?

Barbara_P_Intel
Moderator
569 Views

For the path to libraries, use -L, e.g.  -L/tmp.

For the path to module files, use -module, e.g. -module /tmp. Note the space.

Reply