0

已解决:我不完全确定为什么以及如何,但是当我从 -I~/dlib-18.18 更改为 -I../dlib-18.18 时,它就可以工作了。

我正在尝试编写一个使用 dlib 库编译程序的 makefile。我已经在根目录下载并安装了该库。

.cpp 文件的标头如下:

#include "dlib/optimization.h"
#include <iostream>

dlib 文件夹包含在 dlib-18.18 中, optimization.h 确实在 dlib 文件夹中。

下面是我的makefile(或其中的一部分)。我已将相关目录包含在 CFLAGS 中。但是,在编译过程中,g++ 说找不到 optimization.h (No such file or directory)

EXUCUTABLE = graph

CXX = g++
CXXFLAGS = -I. -I/usr/include/ -I~/dlib-18.18
FLAGS = -g -O -Wall -Wextra -Werror -Wfatal-errors -std=c++11 -pedantic

############### Rules ###############

all: ${EXUCUTABLE}

clean:
    rm -f ${EXUCUTABLE} *.o
## Compile step (.cpp files -> .o files)

%.o: %.cpp
    ${CXX} ${FLAGS} ${CXXFLAGS} -c $< 

graph: graph.o
    ${CXX} ${FLAGS} $^ -o $@

终端制造的输出

从终端访问时的 /dlib-18.18/dlib 文件夹

4

1 回答 1

0

You got your pattern wrong: %.o: %.c denotes that the rule is about compiling .c files (not .cpp files).

As a result, this rule doesn't apply and GNU Make falls back to its own set of default rules for compiling your C++ code.

Try this instead (assuming you're consistent with dlib, and you're using the .cpp extension for your C++ files):

CXX = g++
CXXFLAGS = -I. -I/usr/include/ -I~/dlib-18.18
FLAGS = -g -O -Wall -Wextra -Werror -Wfatal-errors -std=c++11 -pedantic

# To get *any* .o file, compile its .cpp file with the following rule.
%.o: %.cpp
    $(CXX) $(FLAGS) $(CXXFLAGS) -c $<

Now run make -B and watch the compiler output for -I~/dlib-18.18 options on the g++ command lines.

于 2016-04-17T23:32:56.450 回答