2017-01-31 69 views
-1

我試圖在Linux上使用GNU編譯器使用下面的Makefile錯誤:升壓/ regex.hpp:沒有這樣的文件或目錄

CXX=gcc #icpc 
RM=rm -f 
CPPFLAGS=-g -O3 -fopenmp 
CFLAGS= -Wall -c 
OPENMP = -fopenmp 
BIN = theVeecode_$(CXX) 

LIBS= -L /path-to-boost/boost_1_53_0/stage/lib/ -lboost_regex 

CPPSRCS=mathtools.cpp time_.cpp read_input.cpp vee_ao_calc.cpp vee_mo_calc.cpp write_int2e.cpp memory_check.cpp 
OBJS=$(subst .cpp,.o,$(CPPSRCS)) 
OBJS+=$(COBJS) 

all: $(BIN) 

$(BIN): $(OBJS) 
     $(CXX) main.cpp $(OPENMP) -o $(BIN) $(OBJS) $(LIBS) 

clean: 
     $(RM) $(OBJS) $(BIN) 

dist-clean: clean 
     $(RM) $(BIN) 

當我運行make命令來編譯我的C++代碼,我得到以下錯誤消息:

gcc -g -O3 -fopenmp -c -o read_input.o read_input.cpp 
read_input.cpp:9:27: error: boost/regex.hpp: No such file or directory 
read_input.cpp: In function 'void input::read_n_occ()': 
read_input.cpp:95: error: 'boost' has not been declared 
read_input.cpp:95: error: 'regex_search' was not declared in this scope 
make: *** [read_input.o] Error 1 

的read_input.cpp文件開頭

#... // other includes 
#include <boost/regex.hpp> 
using namespace std; 

namespace xxx 
{ 
//some code here 
} 

庫路徑「/ p ath-to-boost/boost_1_53_0/stage/lib /「包含文件 libboost_regex.a,libboost_regex.so和libboost_regex.so.1.53.0。

我不明白爲什麼編譯器沒有找到庫文件。有沒有人有任何想法,爲什麼它不工作,以及如何解決它?

在此先感謝。

+1

可能會錯過提升包括目錄? – P0W

+0

是的,你是對的。我很困惑,因爲我之前在另一臺機器上編譯了相同的Makefile代碼,所以我不清楚它爲什麼不起作用。無論如何,它現在工作。 – user3244013

回答

0

事實證明,問題出在Makefile中。更具體地說,在使用boost編譯.cpp文件的過程中,不包括boost庫的路徑。

%.o: %.cpp $(DEPS) 
     $(CXX) -c -o [email protected] $< $(CPPFLAGS) $(LIBS) 

最後,Makefile文件如下:在編譯步驟明確添加庫固定它

CXX=gcc #icpc 
RM=rm -f 
CPPFLAGS=-g -O3 -fopenmp 
OPENMP = -fopenmp 
BIN = theVeecode_$(CXX) 

LIBS= -I /path-to-boost/boost_1_53_0/ 
LIBS+= -L /path-to-boost/boost_1_53_0/stage/lib/ -lboost_regex 

CPPSRCS=mathtools.cpp time_.cpp read_input.cpp vee_ao_calc.cpp vee_mo_calc.cpp write_int2e.cpp memory_check.cpp 
OBJS=$(subst .cpp,.o,$(CPPSRCS)) 
DEPS=Vector3.h mathtools.h memory_check.h read_input.h time_.h vee_ao_calc.h vee_mo_calc.h write_int2e.h 

%.o: %.cpp $(DEPS) 
     $(CXX) -c -o [email protected] $< $(CPPFLAGS) $(LIBS) 

$(BIN): $(OBJS) 
     $(CXX) main.cpp $(OPENMP) -o $(BIN) $(OBJS) $(LIBS) 

clean: 
     $(RM) $(OBJS) $(BIN) 

dist-clean: clean 
     $(RM) $(BIN) 
相關問題