C++ Link 失败 - ld:找不到 [makefile] [gcc/cygwin]
C++ Link Failure - ld: cannot find [makefile] [gcc/cygwin]
我正在尝试创建一个 makefile 系统来构建我的整个项目。我正在使用 cygwin 和 gcc 编译器。我 运行 在共享库上遇到一个我无法理解的 linking 错误。
我担心 ld: cannot find -lbase
和 ld: cannot find -lsimsimA429
。
这些文件显然是建立的。我什至做了一个目录列表作为构建命令的一部分,以表明它们存在。
-rwxr-xr-x+ 1 user group 116832 Mar 25 10:09 /cygdrive/d/myProj/lib/libbase.so
-rwxr-xr-x+ 1 user group 75972 Mar 25 10:09 /cygdrive/d/myProj/lib/libsimsima429.so
并且 link 命令还显示我包含了正确的 link 目录
g++ -shared -L/cygdrive/d/myProj/lib -lpthread -lrt -lbase -lsimsimA429 ...
我做错了什么导致这个错误?
此外,我对编写 makefile 比较陌生。如果您对我如何改进它们有任何意见,我将不胜感激。
下面列出了完整的 makefile 和输出...
/cygdrive/d/myProj/src/sfi/base/makefile
#------------------------------------------------------------------------------
#-- BASE
#------------------------------------------------------------------------------
#--
# Make does not offer a recursive wildcard function, so here's one:
rwildcard=$(wildcard ) $(foreach d,$(wildcard *),$(call rwildcard,$d/,))
MKDIR=mkdir
ROOTDIR=$(realpath ../../..)
PROJDIR=$(notdir $(CURDIR))
LIBDIR=$(ROOTDIR)/lib
OBJDIR=$(ROOTDIR)/obj/$(PROJDIR)
SRCDIR=$(ROOTDIR)/src
#OUTPUT FILE lib file or executable
TARGET=$(LIBDIR)/lib$(PROJDIR).so
INCLUDES=
#INCLUDES+=
LIBS=
#LIBS+=
LDFLAGS=
LDFLAGS+= -shared
LDFLAGS+= -L$(LIBDIR)
#LDFLAGS+= -Wl,-rpath
CCFLAGS=
#CCFLAGS+= -fPIC
#CCFLAGS+= -ansi
#CCFLAGS+= -pedantic
CCFLAGS+= -g
CCFLAGS+= -Wall
#CCFLAGS+= -std=c++11
CCC=g++
SRC= $(call rwildcard,./,*.cpp)
OBJECTS=$(patsubst %.cpp,$(OBJDIR)/%.o,$(SRC))
# Set our own Goal.
.DEFAULT_GOAL := all
.PHONY: all
all: $(TARGET)
$(OBJDIR)/%.o: %.cpp
@$(MKDIR) -p $(abspath $(dir $@))
$(CCC) -c $(CCFLAGS) $(INCLUDES) $< -o $@
$(TARGET): $(OBJECTS)
$(CCC) $(LDFLAGS) $(LIBS) -o $(TARGET) $(OBJECTS)
ls -l $(TARGET)
.PHONY: clean
clean:
rm -f $(OBJECTS) $(TARGET)
test:
@echo $(OBJECTS) | tr " " "\n"
/cygdrive/d/myProj/src/sfi/drivers/a429/simsimA429/makefile
#------------------------------------------------------------------------------
#-- SIMSIMA429
#------------------------------------------------------------------------------
#--
# Make does not offer a recursive wildcard function, so here's one:
rwildcard=$(wildcard ) $(foreach d,$(wildcard *),$(call rwildcard,$d/,))
MKDIR=mkdir
ROOTDIR=$(realpath ../../../../..)
PROJDIR=$(notdir $(CURDIR))
LIBDIR=$(ROOTDIR)/lib
OBJDIR=$(ROOTDIR)/obj/$(PROJDIR)
SRCDIR=$(ROOTDIR)/src
#OUTPUT FILE lib file or executable
TARGET=$(LIBDIR)/lib$(PROJDIR).so
INCLUDES=
INCLUDES+= -I$(SRCDIR)/face
INCLUDES+= -I$(SRCDIR)/sfi/base
INCLUDES+= -I$(SRCDIR)/sfi/drivers/a429/include
LIBS=
LIBS+= -L$(LIBDIR)
#LIBS+= -lbase
LDFLAGS=
LDFLAGS+= -shared
#LDFLAGS+= -Wl,-rpath
CCFLAGS=
#CCFLAGS+= -fPIC
#CCFLAGS+= -ansi
#CCFLAGS+= -pedantic
CCFLAGS+= -g
CCFLAGS+= -Wall
#CCFLAGS+= -std=c++11
CCC=g++
SRC= $(call rwildcard,./,*.cpp)
OBJECTS=$(patsubst %.cpp,$(OBJDIR)/%.o,$(SRC))
# Set our own Goal.
.DEFAULT_GOAL := all
.PHONY: all
all: $(TARGET)
$(OBJDIR)/%.o: %.cpp
@$(MKDIR) -p $(abspath $(dir $@))
$(CCC) -c $(CCFLAGS) $(INCLUDES) $< -o $@
$(TARGET): $(OBJECTS)
$(CCC) $(LDFLAGS) $(LIBS) -o $(TARGET) $(OBJECTS)
ls -l $(TARGET)
.PHONY: clean
clean:
rm -f $(OBJECTS) $(TARGET)
test:
@echo $(OBJECTS) | tr " " "\n"
/cygdrive/d/myProj/src/sfi/ioss/makefile
#------------------------------------------------------------------------------
#-- IOSS
#------------------------------------------------------------------------------
#--
# Make does not offer a recursive wildcard function, so here's one:
rwildcard=$(wildcard ) $(foreach d,$(wildcard *),$(call rwildcard,$d/,))
MKDIR=mkdir
ROOTDIR=$(realpath ../../..)
PROJDIR=$(notdir $(CURDIR))
LIBDIR=$(ROOTDIR)/lib
OBJDIR=$(ROOTDIR)/obj/$(PROJDIR)
SRCDIR=$(ROOTDIR)/src
#OUTPUT FILE lib file or executable
TARGET=$(LIBDIR)/lib$(PROJDIR).so
INCLUDES=
INCLUDES+= -I$(SRCDIR)/face
INCLUDES+= -I$(SRCDIR)/sfi
INCLUDES+= -I$(SRCDIR)/sfi/base
INCLUDES+= -I$(SRCDIR)/sfi/drivers/a429/include
INCLUDES+= -I$(SRCDIR)/sfi/ioss
LIBS=
LIBS+= -L$(LIBDIR)
LIBS+= -lpthread
LIBS+= -lrt
LIBS+= -lbase
LIBS+= -lsimsima429
LDFLAGS=
LDFLAGS+= -shared
#LDFLAGS+= -Wl,-rpath
CCFLAGS=
#CCFLAGS+= -fPIC
#CCFLAGS+= -ansi
#CCFLAGS+= -pedantic
CCFLAGS+= -g
CCFLAGS+= -Wall
#CCFLAGS+= -std=c++11
CCC=g++
SRC= $(call rwildcard,./,*.cpp)
OBJECTS=$(patsubst %.cpp,$(OBJDIR)/%.o,$(SRC))
# Set our own Goal.
.DEFAULT_GOAL := all
.PHONY: all
all: $(TARGET)
$(OBJDIR)/%.o: %.cpp
@$(MKDIR) -p $(abspath $(dir $@))
$(CCC) -c $(CCFLAGS) $(INCLUDES) $< -o $@
$(TARGET): $(OBJECTS)
$(CCC) $(LDFLAGS) $(LIBS) -o $(TARGET) $(OBJECTS)
ls -l $(TARGET)
.PHONY: clean
clean:
rm -f $(OBJECTS) $(TARGET)
test:
@echo $(OBJECTS) | tr " " "\n"
完整输出:
10:09:19 **** Build of configuration Default for project base ****
make -j all
g++ -c -g -Wall udpserver.cpp -o /cygdrive/d/myProj/obj/base/./udpserver.o
g++ -c -g -Wall udpclient.cpp -o /cygdrive/d/myProj/obj/base/./udpclient.o
g++ -c -g -Wall impl/clock.cpp -o /cygdrive/d/myProj/obj/base/./impl/clock.o
g++ -c -g -Wall impl/deque.cpp -o /cygdrive/d/myProj/obj/base/./impl/deque.o
g++ -c -g -Wall impl/thread.cpp -o /cygdrive/d/myProj/obj/base/./impl/thread.o
g++ -shared -L/cygdrive/d/myProj/lib -o /cygdrive/d/myProj/lib/libbase.so /cygdrive/d/myProj/obj/base/./udpserver.o /cygdrive/d/myProj/obj/base/./udpclient.o /cygdrive/d/myProj/obj/base/./impl/clock.o /cygdrive/d/myProj/obj/base/./impl/Stdafx.o /cygdrive/d/myProj/obj/base/./impl/deque.o /cygdrive/d/myProj/obj/base/./impl/thread.o
ls -l /cygdrive/d/myProj/lib/libbase.so
-rwxr-xr-x+ 1 user group 116832 Mar 25 10:09 /cygdrive/d/myProj/lib/libbase.so
10:09:25 Build Finished (took 5s.994ms)
10:09:25 **** Build of configuration Default for project simsimA429 ****
make all
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include A429HwCtrlTx.cpp -o /cygdrive/d/myProj/obj/simsima429/./A429HwCtrlTx.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include A429HwCtrlRx.cpp -o /cygdrive/d/myProj/obj/simsima429/./A429HwCtrlRx.o
g++ -shared -L/cygdrive/d/myProj/lib -o /cygdrive/d/myProj/lib/libsimsima429.so /cygdrive/d/myProj/obj/simsima429/./A429HwCtrlTx.o /cygdrive/d/myProj/obj/simsima429/./A429HwCtrlRx.o
ls -l /cygdrive/d/myProj/lib/libsimsima429.so
-rwxr-xr-x+ 1 user group 75972 Mar 25 10:09 /cygdrive/d/myProj/lib/libsimsima429.so
10:09:29 Build Finished (took 4s.339ms)
10:09:29 **** Build of configuration Default for project ioss ****
make -j all
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss IOS.cpp -o /cygdrive/d/myProj/obj/ioss/./IOS.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss message/IOSmsg.cpp -o /cygdrive/d/myProj/obj/ioss/./message/IOSmsg.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss message/MsgId.cpp -o /cygdrive/d/myProj/obj/ioss/./message/MsgId.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss message/IOSmsgA429.cpp -o /cygdrive/d/myProj/obj/ioss/./message/IOSmsgA429.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss interface/IOSInterfaceHandle.cpp -o /cygdrive/d/myProj/obj/ioss/./interface/IOSInterfaceHandle.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss interface/IOSInterface.cpp -o /cygdrive/d/myProj/obj/ioss/./interface/IOSInterface.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss interface/direct/IOSDirect_Interface.cpp -o /cygdrive/d/myProj/obj/ioss/./interface/direct/IOSDirect_Interface.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss bus/a429/A429MajorFrame.cpp -o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429MajorFrame.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss bus/a429/A429MsgRxControl.cpp -o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429MsgRxControl.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss bus/a429/A429BusTx.cpp -o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429BusTx.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss bus/a429/A429MsgRegistry.cpp -o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429MsgRegistry.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss bus/a429/A429BusRx.cpp -o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429BusRx.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss bus/a429/A429Message.cpp -o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429Message.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss bus/a429/A429MsgBuffer.cpp -o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429MsgBuffer.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss bus/m1553/M1553Connection.cpp -o /cygdrive/d/myProj/obj/ioss/./bus/m1553/M1553Connection.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss config/IOSConfig.cpp -o /cygdrive/d/myProj/obj/ioss/./config/IOSConfig.o
g++ -shared -L/cygdrive/d/myProj/lib -lpthread -lrt -lbase -lsimsima429 -o /cygdrive/d/myProj/lib/libioss.so /cygdrive/d/myProj/obj/ioss/./IOS.o /cygdrive/d/myProj/obj/ioss/./message/IOSmsg.o /cygdrive/d/myProj/obj/ioss/./message/MsgId.o /cygdrive/d/myProj/obj/ioss/./message/IOSmsgA429.o /cygdrive/d/myProj/obj/ioss/./interface/IOSInterfaceHandle.o /cygdrive/d/myProj/obj/ioss/./interface/IOSInterface.o /cygdrive/d/myProj/obj/ioss/./interface/direct/IOSDirect_Interface.o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429MajorFrame.o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429MsgRxControl.o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429BusTx.o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429MsgRegistry.o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429BusRx.o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429Message.o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429MsgBuffer.o /cygdrive/d/myProj/obj/ioss/./bus/m1553/M1553Connection.o /cygdrive/d/myProj/obj/ioss/./config/IOSConfig.o
/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lbase
/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lsimsima429
collect2: error: ld returned 1 exit status
makefile:61: recipe for target '/cygdrive/d/myProj/lib/libioss.so' failed
make: *** [/cygdrive/d/myProj/lib/libioss.so] Error 1
10:09:42 Build Finished (took 13s.205ms)
Cygwin 共享库是 *.dll
文件,而不是 lib*.so
文件。我想您的链接器正在努力寻找 base.dll
和 simsimA429.dll
.
我正在尝试创建一个 makefile 系统来构建我的整个项目。我正在使用 cygwin 和 gcc 编译器。我 运行 在共享库上遇到一个我无法理解的 linking 错误。
我担心 ld: cannot find -lbase
和 ld: cannot find -lsimsimA429
。
这些文件显然是建立的。我什至做了一个目录列表作为构建命令的一部分,以表明它们存在。
-rwxr-xr-x+ 1 user group 116832 Mar 25 10:09 /cygdrive/d/myProj/lib/libbase.so
-rwxr-xr-x+ 1 user group 75972 Mar 25 10:09 /cygdrive/d/myProj/lib/libsimsima429.so
并且 link 命令还显示我包含了正确的 link 目录
g++ -shared -L/cygdrive/d/myProj/lib -lpthread -lrt -lbase -lsimsimA429 ...
我做错了什么导致这个错误?
此外,我对编写 makefile 比较陌生。如果您对我如何改进它们有任何意见,我将不胜感激。
下面列出了完整的 makefile 和输出...
/cygdrive/d/myProj/src/sfi/base/makefile
#------------------------------------------------------------------------------
#-- BASE
#------------------------------------------------------------------------------
#--
# Make does not offer a recursive wildcard function, so here's one:
rwildcard=$(wildcard ) $(foreach d,$(wildcard *),$(call rwildcard,$d/,))
MKDIR=mkdir
ROOTDIR=$(realpath ../../..)
PROJDIR=$(notdir $(CURDIR))
LIBDIR=$(ROOTDIR)/lib
OBJDIR=$(ROOTDIR)/obj/$(PROJDIR)
SRCDIR=$(ROOTDIR)/src
#OUTPUT FILE lib file or executable
TARGET=$(LIBDIR)/lib$(PROJDIR).so
INCLUDES=
#INCLUDES+=
LIBS=
#LIBS+=
LDFLAGS=
LDFLAGS+= -shared
LDFLAGS+= -L$(LIBDIR)
#LDFLAGS+= -Wl,-rpath
CCFLAGS=
#CCFLAGS+= -fPIC
#CCFLAGS+= -ansi
#CCFLAGS+= -pedantic
CCFLAGS+= -g
CCFLAGS+= -Wall
#CCFLAGS+= -std=c++11
CCC=g++
SRC= $(call rwildcard,./,*.cpp)
OBJECTS=$(patsubst %.cpp,$(OBJDIR)/%.o,$(SRC))
# Set our own Goal.
.DEFAULT_GOAL := all
.PHONY: all
all: $(TARGET)
$(OBJDIR)/%.o: %.cpp
@$(MKDIR) -p $(abspath $(dir $@))
$(CCC) -c $(CCFLAGS) $(INCLUDES) $< -o $@
$(TARGET): $(OBJECTS)
$(CCC) $(LDFLAGS) $(LIBS) -o $(TARGET) $(OBJECTS)
ls -l $(TARGET)
.PHONY: clean
clean:
rm -f $(OBJECTS) $(TARGET)
test:
@echo $(OBJECTS) | tr " " "\n"
/cygdrive/d/myProj/src/sfi/drivers/a429/simsimA429/makefile
#------------------------------------------------------------------------------
#-- SIMSIMA429
#------------------------------------------------------------------------------
#--
# Make does not offer a recursive wildcard function, so here's one:
rwildcard=$(wildcard ) $(foreach d,$(wildcard *),$(call rwildcard,$d/,))
MKDIR=mkdir
ROOTDIR=$(realpath ../../../../..)
PROJDIR=$(notdir $(CURDIR))
LIBDIR=$(ROOTDIR)/lib
OBJDIR=$(ROOTDIR)/obj/$(PROJDIR)
SRCDIR=$(ROOTDIR)/src
#OUTPUT FILE lib file or executable
TARGET=$(LIBDIR)/lib$(PROJDIR).so
INCLUDES=
INCLUDES+= -I$(SRCDIR)/face
INCLUDES+= -I$(SRCDIR)/sfi/base
INCLUDES+= -I$(SRCDIR)/sfi/drivers/a429/include
LIBS=
LIBS+= -L$(LIBDIR)
#LIBS+= -lbase
LDFLAGS=
LDFLAGS+= -shared
#LDFLAGS+= -Wl,-rpath
CCFLAGS=
#CCFLAGS+= -fPIC
#CCFLAGS+= -ansi
#CCFLAGS+= -pedantic
CCFLAGS+= -g
CCFLAGS+= -Wall
#CCFLAGS+= -std=c++11
CCC=g++
SRC= $(call rwildcard,./,*.cpp)
OBJECTS=$(patsubst %.cpp,$(OBJDIR)/%.o,$(SRC))
# Set our own Goal.
.DEFAULT_GOAL := all
.PHONY: all
all: $(TARGET)
$(OBJDIR)/%.o: %.cpp
@$(MKDIR) -p $(abspath $(dir $@))
$(CCC) -c $(CCFLAGS) $(INCLUDES) $< -o $@
$(TARGET): $(OBJECTS)
$(CCC) $(LDFLAGS) $(LIBS) -o $(TARGET) $(OBJECTS)
ls -l $(TARGET)
.PHONY: clean
clean:
rm -f $(OBJECTS) $(TARGET)
test:
@echo $(OBJECTS) | tr " " "\n"
/cygdrive/d/myProj/src/sfi/ioss/makefile
#------------------------------------------------------------------------------
#-- IOSS
#------------------------------------------------------------------------------
#--
# Make does not offer a recursive wildcard function, so here's one:
rwildcard=$(wildcard ) $(foreach d,$(wildcard *),$(call rwildcard,$d/,))
MKDIR=mkdir
ROOTDIR=$(realpath ../../..)
PROJDIR=$(notdir $(CURDIR))
LIBDIR=$(ROOTDIR)/lib
OBJDIR=$(ROOTDIR)/obj/$(PROJDIR)
SRCDIR=$(ROOTDIR)/src
#OUTPUT FILE lib file or executable
TARGET=$(LIBDIR)/lib$(PROJDIR).so
INCLUDES=
INCLUDES+= -I$(SRCDIR)/face
INCLUDES+= -I$(SRCDIR)/sfi
INCLUDES+= -I$(SRCDIR)/sfi/base
INCLUDES+= -I$(SRCDIR)/sfi/drivers/a429/include
INCLUDES+= -I$(SRCDIR)/sfi/ioss
LIBS=
LIBS+= -L$(LIBDIR)
LIBS+= -lpthread
LIBS+= -lrt
LIBS+= -lbase
LIBS+= -lsimsima429
LDFLAGS=
LDFLAGS+= -shared
#LDFLAGS+= -Wl,-rpath
CCFLAGS=
#CCFLAGS+= -fPIC
#CCFLAGS+= -ansi
#CCFLAGS+= -pedantic
CCFLAGS+= -g
CCFLAGS+= -Wall
#CCFLAGS+= -std=c++11
CCC=g++
SRC= $(call rwildcard,./,*.cpp)
OBJECTS=$(patsubst %.cpp,$(OBJDIR)/%.o,$(SRC))
# Set our own Goal.
.DEFAULT_GOAL := all
.PHONY: all
all: $(TARGET)
$(OBJDIR)/%.o: %.cpp
@$(MKDIR) -p $(abspath $(dir $@))
$(CCC) -c $(CCFLAGS) $(INCLUDES) $< -o $@
$(TARGET): $(OBJECTS)
$(CCC) $(LDFLAGS) $(LIBS) -o $(TARGET) $(OBJECTS)
ls -l $(TARGET)
.PHONY: clean
clean:
rm -f $(OBJECTS) $(TARGET)
test:
@echo $(OBJECTS) | tr " " "\n"
完整输出:
10:09:19 **** Build of configuration Default for project base ****
make -j all
g++ -c -g -Wall udpserver.cpp -o /cygdrive/d/myProj/obj/base/./udpserver.o
g++ -c -g -Wall udpclient.cpp -o /cygdrive/d/myProj/obj/base/./udpclient.o
g++ -c -g -Wall impl/clock.cpp -o /cygdrive/d/myProj/obj/base/./impl/clock.o
g++ -c -g -Wall impl/deque.cpp -o /cygdrive/d/myProj/obj/base/./impl/deque.o
g++ -c -g -Wall impl/thread.cpp -o /cygdrive/d/myProj/obj/base/./impl/thread.o
g++ -shared -L/cygdrive/d/myProj/lib -o /cygdrive/d/myProj/lib/libbase.so /cygdrive/d/myProj/obj/base/./udpserver.o /cygdrive/d/myProj/obj/base/./udpclient.o /cygdrive/d/myProj/obj/base/./impl/clock.o /cygdrive/d/myProj/obj/base/./impl/Stdafx.o /cygdrive/d/myProj/obj/base/./impl/deque.o /cygdrive/d/myProj/obj/base/./impl/thread.o
ls -l /cygdrive/d/myProj/lib/libbase.so
-rwxr-xr-x+ 1 user group 116832 Mar 25 10:09 /cygdrive/d/myProj/lib/libbase.so
10:09:25 Build Finished (took 5s.994ms)
10:09:25 **** Build of configuration Default for project simsimA429 ****
make all
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include A429HwCtrlTx.cpp -o /cygdrive/d/myProj/obj/simsima429/./A429HwCtrlTx.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include A429HwCtrlRx.cpp -o /cygdrive/d/myProj/obj/simsima429/./A429HwCtrlRx.o
g++ -shared -L/cygdrive/d/myProj/lib -o /cygdrive/d/myProj/lib/libsimsima429.so /cygdrive/d/myProj/obj/simsima429/./A429HwCtrlTx.o /cygdrive/d/myProj/obj/simsima429/./A429HwCtrlRx.o
ls -l /cygdrive/d/myProj/lib/libsimsima429.so
-rwxr-xr-x+ 1 user group 75972 Mar 25 10:09 /cygdrive/d/myProj/lib/libsimsima429.so
10:09:29 Build Finished (took 4s.339ms)
10:09:29 **** Build of configuration Default for project ioss ****
make -j all
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss IOS.cpp -o /cygdrive/d/myProj/obj/ioss/./IOS.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss message/IOSmsg.cpp -o /cygdrive/d/myProj/obj/ioss/./message/IOSmsg.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss message/MsgId.cpp -o /cygdrive/d/myProj/obj/ioss/./message/MsgId.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss message/IOSmsgA429.cpp -o /cygdrive/d/myProj/obj/ioss/./message/IOSmsgA429.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss interface/IOSInterfaceHandle.cpp -o /cygdrive/d/myProj/obj/ioss/./interface/IOSInterfaceHandle.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss interface/IOSInterface.cpp -o /cygdrive/d/myProj/obj/ioss/./interface/IOSInterface.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss interface/direct/IOSDirect_Interface.cpp -o /cygdrive/d/myProj/obj/ioss/./interface/direct/IOSDirect_Interface.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss bus/a429/A429MajorFrame.cpp -o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429MajorFrame.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss bus/a429/A429MsgRxControl.cpp -o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429MsgRxControl.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss bus/a429/A429BusTx.cpp -o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429BusTx.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss bus/a429/A429MsgRegistry.cpp -o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429MsgRegistry.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss bus/a429/A429BusRx.cpp -o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429BusRx.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss bus/a429/A429Message.cpp -o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429Message.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss bus/a429/A429MsgBuffer.cpp -o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429MsgBuffer.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss bus/m1553/M1553Connection.cpp -o /cygdrive/d/myProj/obj/ioss/./bus/m1553/M1553Connection.o
g++ -c -g -Wall -I/cygdrive/d/myProj/src/face -I/cygdrive/d/myProj/src/sfi -I/cygdrive/d/myProj/src/sfi/base -I/cygdrive/d/myProj/src/sfi/drivers/a429/include -I/cygdrive/d/myProj/src/sfi/ioss config/IOSConfig.cpp -o /cygdrive/d/myProj/obj/ioss/./config/IOSConfig.o
g++ -shared -L/cygdrive/d/myProj/lib -lpthread -lrt -lbase -lsimsima429 -o /cygdrive/d/myProj/lib/libioss.so /cygdrive/d/myProj/obj/ioss/./IOS.o /cygdrive/d/myProj/obj/ioss/./message/IOSmsg.o /cygdrive/d/myProj/obj/ioss/./message/MsgId.o /cygdrive/d/myProj/obj/ioss/./message/IOSmsgA429.o /cygdrive/d/myProj/obj/ioss/./interface/IOSInterfaceHandle.o /cygdrive/d/myProj/obj/ioss/./interface/IOSInterface.o /cygdrive/d/myProj/obj/ioss/./interface/direct/IOSDirect_Interface.o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429MajorFrame.o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429MsgRxControl.o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429BusTx.o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429MsgRegistry.o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429BusRx.o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429Message.o /cygdrive/d/myProj/obj/ioss/./bus/a429/A429MsgBuffer.o /cygdrive/d/myProj/obj/ioss/./bus/m1553/M1553Connection.o /cygdrive/d/myProj/obj/ioss/./config/IOSConfig.o
/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lbase
/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lsimsima429
collect2: error: ld returned 1 exit status
makefile:61: recipe for target '/cygdrive/d/myProj/lib/libioss.so' failed
make: *** [/cygdrive/d/myProj/lib/libioss.so] Error 1
10:09:42 Build Finished (took 13s.205ms)
Cygwin 共享库是 *.dll
文件,而不是 lib*.so
文件。我想您的链接器正在努力寻找 base.dll
和 simsimA429.dll
.