Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot compile/run on macOS #3

Open
quinntpratt opened this issue Jan 16, 2023 · 4 comments
Open

Cannot compile/run on macOS #3

quinntpratt opened this issue Jan 16, 2023 · 4 comments

Comments

@quinntpratt
Copy link

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)

@milancurcic
Copy link
Member

Thanks @quinntpratt! I don't know why that is. I don't own a Mac and haven't used it before.

What I think this

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

suggests is that server.o tries to look for _dill_ipaddr_local but it's not found at link time. In other words, I think this name may be modified at the Fortran program side rather than the libdill side.

What does nm libdill.a | grep ipaddr_local output for you?

@quinntpratt
Copy link
Author

Hi @milancurcic,

nm libdill.a | grep ipaddr_local

results in,

                 U _dill_ipaddr_local
00000000000000b0 T _dill_ipaddr_local
0000000000000960 t _dill_ipaddr_local.cold.1
00000000000009a0 t _dill_ipaddr_local.cold.2
00000000000009e0 t _dill_ipaddr_local.cold.3
0000000000000a20 t _dill_ipaddr_local.cold.4
0000000000000a60 t _dill_ipaddr_local.cold.5

@milancurcic
Copy link
Member

OK, thanks. I don't think the underscore is our problem. I'll do some searching.

@jnorrid
Copy link
Contributor

jnorrid commented Feb 23, 2024

FYI: libdill now has a homebrew formula for macOS: https://formulae.brew.sh/formula/libdill

macOS users should not need to build it manually, but have the option to simply issue:

brew install libdill

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants