CMake外部静态库循环依赖

时间:2017-07-18 12:45:53

标签: makefile cmake circular-dependency

我正在将一个Makefile转换为GitHub项目中的CMakeLists.txt An implementation of Deformation Transfer algorithm in ANSI C

例如,在文件夹/corres_resolve中,其Makefile如下所示。

INCLUDE_PATH    := ./ ../external/include/ ../common/
SOURCE_PATH     := ./ ../common/
DEPENDENCY_PATH := dep
OBJECT_PATH     := obj

EXTERNAL_LIBS := $(wildcard ../external/lib/*.a)
LDLIBS := -lm -lpthread

CFLAGS += -O3

include ../makefile.mk

它的makefile.mk是

vpath %.h $(INCLUDE_PATH)
vpath %.c $(SOURCE_PATH)
vpath %.d $(DEPENDENCY_PATH)
 vpath %.o $(OBJECT_PATH)

## Default .o and .dep path and program name
OBJECT_PATH     ?= obj
DEPENDENCY_PATH ?= dep
PROGRAM_NAME    ?= run

# Source trunk
source-files    = $(wildcard  $(addsuffix /*.c, $(SOURCE_PATH)))
source-list     = $(notdir  $(source-files))

# Binary trunk
objname-list    = $(subst  .c,.o, $(source-list))
object-list     = $(addprefix  $(OBJECT_PATH)/, $(objname-list))

# Dependency trunk
depname-list    = $(subst  .c,.d, $(source-list))
dependency-list = $(addprefix  $(DEPENDENCY_PATH)/, $(depname-list))

# -I option to help the compiler finding the headers
CFLAGS += $(addprefix  -I, $(INCLUDE_PATH))

# Build external library cmdline parameter, those -Xlinker directives instructs
# The linker find the correct linking sequence regardless the order of items
# specified in EXTERNAL_LIBS.`enter code here`
LOADLIBES += \
-Xlinker --start-group \
    $(addprefix  -Xlinker , $(EXTERNAL_LIBS)) \
-Xlinker --end-group

# PROGRAM_NAME is provided in custom makefile
$(PROGRAM_NAME): $(object-list)
$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@
$(OBJECT_PATH)/%.o: %.c
@mkdir -p $(OBJECT_PATH)
$(COMPILE.c) $(OUTPUT_OPTION) $<
# Resolve [object,source] -- [header] dependency
-include $(dependency-list)
$(DEPENDENCY_PATH)/%.d: %.c
@mkdir -p $(DEPENDENCY_PATH)
@$(CC) -M $(CFLAGS) $< > $@.$$$$;           \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$

不幸的是,$(EXTERNAL_LIBS)有10个静态* .a文件,它们之间具有循环依赖关系。

如何在CMakeLists.txt中处理此问题?

1 个答案:

答案 0 :(得分:1)

它在makefile.mk文件中显示如何使用--start-group--end-group链接器选项来解决这个问题。

使用GCC,您可以-Wl使用--start-group-Wl--end-grouptarget_link_libraries()(仅限)public void get(){ try { clientSocket = new Socket(SERVERIP,SERVERPORT); handler.post(new Runnable() { @Override public void run() { mTextview.setText("Connected to server"); } }); handler.post(new Runnable() { @Override public void run() { try { DataInputStream dIn = new DataInputStream(clientSocket.getInputStream()); DataOutputStream dout = new DataOutputStream(clientSocket.getOutputStream()); dout.writeInt(-1001); while(true) { if(dIn.readInt()==(-1002)){ Log.d(":::::::Attempt for data", ":::::::::::::::::"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int length = 1; // read length of incoming message byte[] message = new byte[dIn.readInt()]; Log.d(":::Comming Size::",String.valueOf(message.length)); dIn.readFully(message); baos.write(message, 0, message.length); Log.d("Stuck", ":::::::::::::: 11111111 "+ String.valueOf(length)); byte[] buffer = baos.toByteArray(); Log.d("Stuck", ":::::::::::::: 22222222 "+ String.valueOf(length)); breceived = BitmapFactory.decodeByteArray(buffer, 0, buffer.length); Log.d("Stuck", ":::::::::::::: 33333333 "+ String.valueOf(length)); img.setImageBitmap(breceived); Log.d("Stuck", ":::::::::::::: 444444444 "+ String.valueOf(length)); // Execute the Runnable in 2 seconds //handler.postDelayed(t, 2000); dout.writeInt(-1001); }else{ Log.d(":::Else Data:::","!!!!!!!!!!!"); } if(!clientSocket.isConnected()){ break; } } clientSocket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 中有问题的库。