我有文件夾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