Reputation: 3265
I'm reading the open-source code for RBENV, and I came across this line of code. When I generated the Makefile using the configure
script and ran make
, I saw the following:
$ make
gcc -fno-common -c -o realpath.o realpath.c
gcc -dynamiclib -dynamic -undefined dynamic_lookup -o ../libexec/rbenv-realpath.dylib realpath.o
I wanted to know what each of these commands is doing, so I started Googling each of the flags. I found many of them, but -undefined dynamic_lookup
initially stumped me. Eventually I found this Github issue, which contained the following sentence:
...the option -undefined dynamic_lookup must be passed to the linker to indicate that unresolved symbols will be resolved at runtime.
This makes sense to me, given what I know about the purpose of this particular Makefile (it allows RBENV to use a faster, more performant version of the realpath
program as a dynamic library).
However, I was unable to confirm this independently, since I don't see any official GCC docs which describe the -undefined
flag or the dynamic_lookup
option. I Googled gcc dynamic_lookup site:gnu.org
, but the only results which turned up were Bugzilla tickets, email threads about patches, etc. I also searched man gcc
and help gcc
in my terminal, but got No manual entry for gcc
as a response.
Questions:
-undefined dynamic_lookup
correct?-undefined dynamic_lookup
actually missing from the gcc docs?Upvotes: 3
Views: 2037
Reputation: 3265
Turns out I was getting the No manual entry for gcc
error because "gcc isn't installed anymore by Xcode, it really installs clang and calls it gcc". See this StackOverflow post and this answer for more info. Once I realized that, I Googled "man gcc" and found the docs from man7.org.
As user @n.m. mentions in the comment above, the -undefined
option (along with many others) is forwarded to the Darwin linker, therefore it is those docs that I should have been looking at. Once I found the Darwin linker docs, I found the info I was looking for:
undefined < treatment >
Specifies how undefined symbols are to be treated. Options are: error, warning, suppress, or dynamic_lookup. The default is error.
Upvotes: 1