2013-10-29 17 views
0

好的,所以我編寫了一個簡單的記錄器,我寫入了一個庫,所以我可以將其包含在其他項目中。但是,當我試圖包含該記錄器的頭文件時,編譯失敗。如何從自編庫中包含頭文件?

這裏是我的Makefile鏈接庫:

CC= clang++ 
PROG= ./bin/tetris 
OBJS= ./src/main.o ./src/Tetris.o ./src/states/BaseState.o ./src/states/MenuState.o \ 
    ./src/states/GameState.o 
LIBS= allegro-5.0 allegro_dialog-5.0 allegro_font-5.0 allegro_ttf-5.0 allegro_color-5.0 
CXXFLAGS= -g -Wall -std=c++11 
LDFLAGS= $(shell pkg-config --static --libs ${LIBS}) -I./src/util -L./src/util/ -lsimplog 

all: $(PROG) 

$(PROG): $(OBJS) 
    mkdir -p ./bin/ 
    $(CC) -o $(PROG) $(CXXFLAGS) $(OBJS) $(LDFLAGS) 
    rm -f $(OBJS) 

clean: 
    rm -f $(PROG) $(TEST_PROG) $(OBJS) 

圖書館是libsimplog.a和位於src目錄這個項目的。我正在編譯它在一個單獨的項目文件夾,然後在這裏複製。 simplog.h/simplog.c只存在於最初編譯這個庫的項目文件夾中。據我所知,我編譯標誌中的-L ./src/ -lsimplog應該鏈接這個庫。然而,我的#include "simplog.h"仍然失敗在編譯:

fatal error: simplog.h: No such file or directory 

我編譯在自己的項目文件夾中的庫,從這個項目是分開的。 simplog.h/simplog.c存在於該項目中,而不是此項目。 對於編譯這個庫中的其他項目生成文件如下:

CC = clang 
CFLAGS = -Wall -c 
LIB = libsimplog.a 
SOURCE = simplog.c 
OBJ = simplog.o 

all: 
    $(CC) $(CFLAGS) $(SOURCE) 
    ar -cvq $(LIB) $(OBJ) 

clean: 
    rm -f $(LIB) 

回答

2

「-L」規定了連接路徑。

您需要告訴預處理器有另一個包含-I./src/的目錄。

CXXFLAGS= -g -Wall -std=c++11 -I./src/ -L./src/ -lsimplog $(shell pkg-config --cflags ${LIBS}) 
+0

嘗試這樣做,但它仍然失敗,出現同樣的錯誤編譯。 – PseudoPsyche

+0

好吧,相對於俄羅斯方塊Makefile,simplog.h是在「./src」中? – kfsone

+0

Infact,你的問題聽起來像有兩個Makefiles。 – kfsone

0

您是否嘗試過使用I Flags來包含頭文件? 如:

-I/usr/include/ 

從G的手冊頁++

-I dir   Add the directory dir to the list of directories to 
be searched for header files. Directories named by -I are searched 
before the standard system include directories. 
If the directory dir is a standard system include directory, 
the option is ignored to ensure that the default search order for 
system directories and the special treatment of system headers are no 
defeated .If dir begins with "=", then the "=" will be replaced by the 
sysroot prefix; see --sysroot and -isysroot.