Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

simple C++ and FORTRAN code

msherl
Beginner
284 Views
Hi,

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:
[cpp]#include using namespace std; extern"C" { void fortfunc_(int *ii, float *ff); } int main() { int ii=5; float ff=5.5; fortfunc_(&ii, &ff); return 0; }[/cpp] and the fortran function is in fortran.f90:
[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:

/opt/intel/composer_xe_2011_sp1.8.273/compiler/lib/intel64/libifcore.so.5

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?

Cheers,

Mark
0 Kudos
2 Replies
TimP
Honored Contributor III
284 Views
If you have C++ in your build, you should use icpc rather than icc for the link step. It seems that you may have to append -lintlc following -lifcore. You could verify what is being done with library searches etc. by adding -# to your options.
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.
0 Kudos
JenniferJ
Moderator
284 Views

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-applications-in-version-9x-or-higher/

Jennifer

0 Kudos
Reply