Skip to content

Cannot compile/run on macOS #3

@quinntpratt

Description

@quinntpratt

Hello, I've been following along in your book "Modern Fortran" to learn the basics of the language.
I made it all the way to chapter 11 (great book by the way!) and now I've encountered an issue with the c-binding business...

I was able to install/compile libdill with no errors following the commands given in section 11.1.2.
However, the initial versions of the files: mod_dill.f90, and server.f90 given in listings 11.2 and 11.3 in the textbook don't work for me.
I also tried jumping to the end of the chapter, cloning this repo, and following the instructions in the readme file that didn't work either (with a similar error).

I am able to compile both module/program with no issue,
>> gfortran -c mod_dill.f90 server.f90
which produces the binary files... but when it comes to linking them with,
>> gfortran mod_dill.o server.o -o server
I'm hit with:

Undefined symbols for architecture x86_64:
  "_dill_ipaddr_local", referenced from:
      _MAIN__ in server.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

which suggests a leading underscore is being added to the libdill function dill_ipaddr_local at compile time? (I don't know C really at all), and thus bind(c,name="dill_ipaddr_local") can't find its binding?

In an effort to track this down further I wrote a simple hello_world.c program with a function to print "Hello world" and that encountered the same issue with the underscores unless I compile and link the c program with gfortran as well (instead of gcc)... but I'm not sure how I can apply this information to the compilation/binding of libdill.

Any help with this would be amazing - and I'm sure others working on macOS would benefit too.
Thank you.

Other info:
>> gfortran --version gives,

GNU Fortran (GCC) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

My machine is a Macbook Pro (with intel CPU) running macOS 11.7.2 (big sur)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions