我有文件夹ClientServer
。 在这个文件夹中我有两个其他文件夹,Database
和Server
。 在Server
文件夹我有类使用“database.h”和“newsgroup.h”。 这些文件位于Database
文件夹中。我用这个make文件创建了一个lib。我将libfile移至ClientServer
文件夹。然后我尝试在Server
文件夹中调用Make;我得到错误。C++中的静态库不工作
Makefile:47: ans.d: No such file or directory
Makefile:47: com.d: No such file or directory
Makefile:47: myserver.d: No such file or directory
In file included from myserver.cc:11:0:
ans.h:4:23: fatal error: newsGroup.h: No such file or directory
#include "newsGroup.h"
^
compilation terminated.
#
# Makefile to make the file libclientserver.a, containing
# connection.o and server.o
#
# Define the compiler. g++ can be
# changed to clang++.
CXX = g++
CC = g++
# Define preprocessor, compiler, and linker flags. Uncomment the # lines
# if you use clang++ and wish to use libc++ instead of libstdc++.
CXXFLAGS = -g -O2 -Wall -W -pedantic-errors
CXXFLAGS += -Wmissing-braces -Wparentheses -Wold-style-cast
CXXFLAGS += -std=c++11
#CPPFLAGS = -stdlib=libc++
#CXXFLAGS += -stdlib=libc++
#LDFLAGS += -stdlib=libc++
all: libdatabase.a
# Create the library; ranlib is for Darwin and maybe other systems.
# Doesn't seem to do any damage on other systems.
libdatabase.a: Database.o newsGroup.o
ar rv libdatabase.a Database.o newsGroup.o
ranlib libdatabase.a
# Phony targets
.PHONY: all clean
# Standard clean
clean:
rm -f *.o libclientserver.a
# Generate dependencies in *.d files
%.d: %.cc
@set -e; rm -f [email protected]; \
$(CPP) -MM $(CPPFLAGS) $< > [email protected]$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o [email protected] : ,g' < [email protected]$$$$ > [email protected]; \
rm -f [email protected]$$$$
# Include the *.d files
SRC = $(wildcard *.cc)
include $(SRC:.cc=.d)
您的依赖性处理过于复杂,并不完全正确。试试'-include $(SRC:.cc = .d)' – Beta
这意味着它找不到头文件,而不是lib。 – OMGtechy
为什么它需要头文件,那么一切都应该在lib中。 – user2975699