Author Topic: Some problem with resolving standard functions in static libs  (Read 3821 times)

Offline FCM

  • Multiple posting newcomer
  • *
  • Posts: 10
CB_10.05 + tdm_gcc_4.5.0  (WinXP, Win7)
There are two projects in one workspace:
1) console with cpp-file containing main function
2) static lib with f90-file containing fortran function

This works properly unless in fortran function some standard fortran functions ( MATMUL, WRITE ) are used. Building of fortran static lib is still ok, but building of the workspace results in errors like "undefined reference to _gfortran_matmul_r8_".
I suppose that all refs to standard fortran functions must be resolved within fortran project, isn't that so?

There is no such problem if both projects are fortran projects.
There is no such problem under Visual Studio with mixing Visual C++ console project and Visual Fortran static lib project.
???

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Some problem with resolving standard functions in static libs
« Reply #1 on: July 03, 2010, 02:14:17 pm »
Probably you need to explicitly link to the fortran's standard libraries in your console project,
because the c/c++ don't know anything about the fortran's libs.
Also keep in mind that static libs (.a files) are just an archive with object (.o) files.
There is no linking/dependency info in them.

Visual studio handles this automatically, because it adds libraries to the linker's options behind the scenes.
C::B doesn't do it at the moment.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline FCM

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Some problem with resolving standard functions in static libs
« Reply #2 on: July 09, 2010, 03:41:24 pm »
Thanks for response.
I tried to link manually some libs from mingw (containing word "fortran"), but (having no enough experience in GCC) without success. 

Offline FCM

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Some problem with resolving standard functions in static libs
« Reply #3 on: July 10, 2010, 02:46:31 pm »
I've successed after adding link to libgfortran.a in main CPP console project building options.
Previouly I tried adding this link to fortran (static lib) project building options.

But it looks amazing that this additional step is needed for MATMUL, WRITE (and perhaps some other)  gfortran procedures and statements, but is not nessesary for many other gfortran procedures and statements.