1

I'd like to build a Fortran program that will use a library with a specific interface, but I don't have the library currently installed on my system. I only need to compile the Fortran program, not run it. I assume that the system where my program is run will have the library installed in a standard location (i.e. /usr/lib).

Is this possible?

Specifically, I'd like to use the Conda-build system to compile a program that links to the MATLAB library (libmex). Since MATLAB is not installable with Conda or other package managers, I was hoping I could somehow build my program in such a way that it has the correct function call to libmex but requiring that users will have libmex installed in a place where my program can find it.

raf
  • 535
  • 4
  • 18
  • No, it won't work. – steve Mar 05 '21 at 17:51
  • 1
    If you know both the install path of the library and what symbols it exports, you can simply write a C file that defines all those functions with stub implementations, compile that into a library, and link against it. – Siguza Mar 05 '21 at 17:52
  • 2
    You may be able to _compile_ but you'll have a harder time _linking_. Even compiling may be impossible, such as if you need (Fortran) modules, etc., provided by the library implementation. Please give more details of your requirements. – francescalus Mar 05 '21 at 18:07
  • @francescalus yes the linking part is what I think I'm missing. I've added specific details to the question. – raf Mar 05 '21 at 19:31
  • 1
    Is it true that in C/C++, you can do this with a header file? Though that doesn't take care of the linking problem. My understanding of "dynamic linking" is that the program can search a list of locations at runtime for a required library. – raf Mar 05 '21 at 19:32
  • @raf It can, but you still have to persuade the linker to link the program for you and I do not think it is possible without actually having the library. – Vladimir F Героям слава Mar 05 '21 at 20:11
  • 2
    See https://stackoverflow.com/questions/45014588/is-it-possible-to-link-to-a-shared-library-without-access-to-the-library-itself See also the comment by Georg Schölly – Vladimir F Героям слава Mar 05 '21 at 20:12
  • Thanks @VladimirF. Sounds like its possible though painful and possibly error prone. – raf Mar 05 '21 at 21:28

0 Answers0