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

dynamic_cast is turned into whatever_cast by -lxca when linking C++ and FORTRAN.

pir
Beginner
650 Views
Hi!



I'm making a program in c++ that include som fortran modules. When I link the total program I need to use a library called -lcxa. If I don't use it I get a lot of linking error messages.

like:

undefined reference to 'for_read_seq_xmit'.



BUT if I use it, then dynamic_cast does't work. When I use dynamic_cast it casts to wathever.



Like this:



class Base;



class SubclassA: public Base;



class SubclassB : public Base;



Base *base = new SubclassA ( );



SubclassB *b= dynamic_cast ( base );



Normally b should be NULL, but it isn't.





How can I solve this? Is there some other library that I can use instead of xca? I use gcc 4.02 when compiling the c++ code and linking the c++ and FORTRAN together.



The FORTRAN code is compiled with Intel9.0





Hope someone know how to solve this

pir
0 Kudos
2 Replies
TimP
Honored Contributor III
650 Views
You leave us guessing here. So, I'm guessing you are using g++-4.02 as the main program, and you are doing I/O from both C++ and Fortran. You must take care not to touch the same data streams with both C++ and Fortran (including stdout and stderr).
I would have thought you would require more than libcxa to satisfy run-time library requirement of the ifort compiled code. For example, if you are using a version of ifort which has a libifcore library, you might try that first.
If you could make a sample Fortran only application which uses your subroutines, and set the additional option -# while linking, you could see which ifort libraries are expected. There should be both static and dynamic linked versions of each library, and you might try both. Setting -i-static in your Fortran sample should choose only static libraries for Fortran run-time.
As the g++-4 compatibility of Intel 9.0 compilers is not good, ifort 9.1 might do better.
0 Kudos
pir
Beginner
650 Views
Hi!

Sorry for the missing information. I'm not so used to FORTRAN.

This is the libraries that I use when I compile (except c++ libs):
-L/opt/intel/fc/9.0/lib -lcxa -lifcoremt -lifcore -limf -lsvml -lunwind

The thing is that I've tried to compile without one of those libs one at a time.
There seems like all of them are needed to link the program successfuly.
But I noticed that if I compile only c++ code with all of the FORTRAN libraries included ( and of course c++ libraries ) the dynamic_cast worked if I removed the -lxca. So if I could replace this one with something, it maybe could work.

The problem is that I'm have these object files written in FORTRAN and compiled with ifort 9.0 which need to be inserted in my c++ project.
I'm not so sure I'm skilled enough to make these test compilations.
Is this my only option?

One thing that makes me confused is that I've read a similar thread about ifort7.0 which ended with that it was said that the problem was solved. So the problem is not solved for all c++ compilers I guess...
This problem can't be that uncommon, I suppose there are some FORTRAN code which is reused by inserting it in c++ and I suppose gcc is quite common amoing c++ programmers.


thanks
pir
0 Kudos
Reply