13

I am trying to install a project which was developed on Ubuntu, but now I am trying to make it run on Max OSX - version: 10.10.5 (Yosemite).

My current ld version that comes by default with OSX:

ld -v
@(#)PROGRAM:ld  PROJECT:ld64-253.3
configured to support archs: i386 x86_64 x86_64h armv6 armv7 armv7s armv7m armv7k arm64 (tvOS)
LTO support using: LLVM version 3.7.0

Makefile contents:

PYLIB         = -I/usr/include/python2.7
CLIBS             =

CC            = gcc
CFLAGS        = $(PYLIB) $(CLIBS) -fPIC -O3 -std=c++11
LD            = g++
LDFLAGS       = -shared -L. -Wl,--no-as-needed $(CLIBS)



SWIG          = swig
SWIGFLAGS     = -c++ -python -extranative

MODULE        = iPlaneImporter
CMODULE       = $(MODULE).cpp
CMODULE_H     = $(MODULE).h
CMODULE_OBJ   = $(MODULE).o
INTERFACE     = $(MODULE).i

CWRAPPER      = $(MODULE)_wrap.cpp
CWRAPPER_OBJ  = $(MODULE)_wrap.o
PYMODULE      = $(MODULE).py
SOLIB         = _$(MODULE).so

SRCS          = $(CMODULE) $(CWRAPPER)
OBJS          = $(CMODULE_OBJ) $(CWRAPPER_OBJ)

all: $(SOLIB) $(PYMODULE)

.PHONY: clean
clean:
        rm -f $(CWRAPPER) $(PYMODULE) $(OBJS) $(SOLIB) *.pyc

$(CWRAPPER) $(PYMODULE): $(INTERFACE) $(CMODULE_H)
        $(SWIG) $(SWIGFLAGS) -o $(CWRAPPER) $(INTERFACE)

$(OBJS): $(SRCS)
        $(CC) -c $(SRCS) $(CFLAGS)

$(SOLIB): $(OBJS)
        $(LD) $(LDFLAGS) $(OBJS) -o $(SOLIB)

Error:

ld: unknown option: --no-as-needed
collect2: error: ld returned 1 exit status
make[1]: *** [_iPlaneImporter.so] Error 1

I believe the problem here is

LDFLAGS = -shared -L. -Wl,--no-as-needed $(CLIBS)

The OSX linker doesn't support this option and I checked the man page to see what possible replacements I could use instead of --no-as-needed, but couldn't find any.

Removing that option also doesn't help - throws other errors.

I tried installing the GNU Command line tools on OSX from an online resource here. But I believe the GNU linker is not included in that.

Additionally I have also installed gcc47, doesn't help either.

Can someone please suggest some workarounds to this option and confirm that the GNU linker cannot be installed on OSX?

Thanks!

Abhishek Balaji R
  • 665
  • 10
  • 25
  • 2
    Don't try using the unsupported option. Make sure you list your libraries after your object files. You might need to worry about (a) sequencing of library names and (b) not including libraries you don't need on the link line. – Jonathan Leffler Dec 16 '15 at 20:11
  • Removing the `-Wl,--no-as-needed` option is the correct solution. It is a no-op in this case (for GNU `ld`) because `--no-as-needed` is the default, and there is no preceding `--as-needed` option in the link command. If other errors occur when that option is removed then that's a separate matter, and without any information about those, there is no way for us to advise. – John Bollinger Mar 21 '23 at 13:39

0 Answers0