I am trying to run a simple c++ code I wrote to practise calling a simple FORTRAN function.
The c++ code is in main.cpp:
[fortran] subroutine fortfunc(ii,ff) integer ii real*4 ff write(6,100) ii, ff 100 format('ii=',i2,' ff=',f6.3) return end[/fortran] Anyway, the problem is at the linking stage. I use icc to compile main.cpp -> main.o then ifort to compile fortran.f90 -> fortran.o
Then I attempt to link with icc like this:
icc -o prog main.o fortran.o -lifcore -limf
but I get the following linker problems:
ld: warning: libintlc.so.5, needed by /opt/intel/composer_xe_2011_sp1.8.273/compiler/lib/intel64/libifcore.so.5, not found (try using -rpath or -rpath-link)
ld: prog: hidden symbol `__intel_cpu_indicator_init' in /opt/intel/composer_xe_2011_sp1.8.273/compiler/lib/intel64/libirc.a(cpu_disp.o) is referenced by DSO
ld: final link failed: Nonrepresentable section on output
(1) The first warning is strange, as I have verified the library libintlc.so.5 is in the directory it mentions:
According to the man page the option -L allows you to specify a search directory for libraries - I tried the above directory and that didn't help.
(2) and (3) I don not understand what these errors mean, can someone lend a hand?
You could of course avoid the OS dependencies by USE iso_c_binding and the associated Fortran syntax.
If you have done as you show, it's a bit strange that you are getting a mixture of dynamic and static libraries in your link.
If you sourced the compilervars script which comes with the compiler to set your paths, the .so files should be taken care of in LD_LIBRARY_PATH for run-time access.
for mixed C/Fortran app, using "ifort" to link is easier.
Here is how I build it and it linked fine:
1. icpc -c t.cpp
2. ifort -c f.f90
3. ifort t.o f.o -nofor-main -lstdc++
Here is an article on building mixed C/Fortran program - http://software.intel.com/en-us/articles/intel-fortran-compiler-linking-mixed-fortran-cc-application...