Reputation: 7315
When I tried to build a project in Linux, I got Error: undefined symbol clock_gettime
. So I figured out that I needed to add -lrt
to the build command (gcc). However, now it won't compile in OS X: ld: library not found for -lrt
. I don't know exactly where this function is getting called as it's in statically linked code, but it seemed to be working just fine in OS X without librt. The linked code probably uses an alternative behind #if __APPLE__
or something.
Is there any way that I can instruct gcc
to only link librt
if it's needed, or if it exists? If not, how do I create a Makefile with OS-specific commands? I'm not using autoconf or anything like it.
The Makefile is rather complex, but here's the operative part:
CC := g++
# In this line, remove -lrt to compile on OS X
LFLAGS := -lpthread -lrt
CFLAGS := -c -Wall -Iboost_build -Ilibtorrent_build/include -Iinc
OBJDIR := obj
SRCDIR := src
SRC := $(wildcard $(SRCDIR)/*.cpp)
OBJS := $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRC))
# Note that libtorrent is built with a modified jamfile to place the
# libtorrent.a file in a consistent location; otherwise it ends up somewhere
# dependent on build environment.
all : $(OBJS) libtorrent_build boost_build
$(CC) -o exec $(LFLAGS) \
$(OBJS) \
libtorrent_build/bin/libtorrent.a \
boost_build/stage/lib/libboost_system.a
Upvotes: 5
Views: 4962
Reputation: 3011
If you google the problem you will find a good set of solutions, one is posted as a comment at the question, another is here:
gettimeofday()
could be a betteer solution, if you are compiling code not writed by you bear in mind that clock_gettime
function is NOT provided under OS X and you need to modify the code.
Hope that can help you, pedr0
Upvotes: -1
Reputation: 99144
You could try this:
LFLAGS := -lpthread
OS := $(shell uname -s)
ifeq ($(OS),Linux)
LFLAGS += -lrt
endif
Upvotes: 11