當我嘗試在Linux中構建項目時,得到了Error: undefined symbol clock_gettime
。所以我發現我需要將-lrt
添加到構建命令(gcc)中。但是,現在它不能在OS X中編譯:ld: library not found for -lrt
。我不知道這個函數究竟在哪裏被調用,因爲它是靜態鏈接的代碼,但它似乎在沒有librt的OS X中工作得很好。鏈接的代碼可能使用#if __APPLE__
之類的替代方法。如何構建需要clock_gettime函數的Linux/OSX makefile
有沒有什麼辦法可以讓我指導gcc
只聯繫librt
如果需要的話,還是存在?如果不是,我該如何創建一個具有特定操作系統命令的Makefile?我沒有使用autoconf或類似的東西。
的Makefile文件是相當複雜的,但這裏的執行部分:
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
你可以張貼makefile文件,如果是很簡單? – pedr0
看到這個:http://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x – pedr0
如果有人試圖告訴我有關'clock_gettime'的替代方法,我會扼殺某人。我非常痛苦地說我不能控制使用這個函數,而這純粹是一個編譯問題,而不是代碼問題。 (憤怒來自我的初步谷歌搜索的結果完全回答「替代這個功能」問題) – meustrus