Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ranlib/ar in Mac OS gives me "has no symbols" warning

Tags:

c

unix

macos

linker

I use a particular libary that has a few ways of compiling it (platform- and target-specific code) and, as a result, sometimes has entirely empty .c files in the archive; the code was simply #ifdef'd away. This is absolutely understood and not a bug at all: I want it this way. And on Linux, this is indeed not a problem at all. If it were a problem, the linker would catch it.

Yet ranlib/ar on Mac OS cannot be convinced to suppress the "has no symbols" warnings for these files.

Now, I'm an engineer and I want to run my compilation process absolutely warning-less. This is critical code that is going to be evaluated; if I have warnings, people will look at me funny. Is there perhaps something I've overlooked? Some command-line option?

Thanks,

KJ

like image 326
KJH Avatar asked May 12 '14 07:05

KJH


2 Answers

Finally, newer versions of ranlib offer an option -no_warning_for_no_symbols, which is described in the man page as

Don't warn about file that have no symbols.

(as included in Xcode 10.1). Unfortunately, ar hasn't got this option yet. But as the man page states

running ranlib is completely equivalent to executing ‘ar -s’

therefore you probably can replace many (if not all) calls of ar by ranlib.

like image 68
jvb Avatar answered Nov 16 '22 10:11

jvb


Two possibilities that come to mind are (1) always put some symbol in the library, even if it is a zero-length object. (2) provide wrappers in the Makefile environment to ranlib/ar that filter the warnings out. The other user/automated build don't need to explicitly use grep -v, it can be in a command you provide and substitute, eg:

AR = $(PROJECT_HOME)/bin/project-ar
RANLIB = $(PROJECT_HOME)/bin/project-ranlib
like image 2
dbrower Avatar answered Nov 16 '22 10:11

dbrower