在make期间链接所需的头文件

时间:2016-05-08 23:43:19

标签: makefile mapnik

我正在努力针对sample binary对我已经编译的a project进行制作。

编译失败,

$ make
c++   -D_THREAD_SAFE -I/usr/local/Cellar/protobuf/2.6.1/include   -L/usr/local/Cellar/protobuf/2.6.1/lib -lprotobuf-lite tileinfo.cpp ../../src/vector_tile.pb.cc -o tileinfo -lprotobuf-lite -lz
tileinfo.cpp:7:10: fatal error: 'vector_tile_compression.hpp' file not found
#include "vector_tile_compression.hpp"
         ^
1 error generated.
make: *** [tileinfo] Error 1

我可以在项目源中看到缺少的头文件。我想在编译时包含它,以便可以找到它。我假设只是复制所有来源是不正确的&我应该能够指向这个头文件。我尝试了-I标志,但无论我给它什么路径,它仍然无法找到这个头文件。

所以我塌陷并复制头文件......

$ cp ../../src/vector_tile_compression.hpp .
$ make
c++   -D_THREAD_SAFE -I/usr/local/Cellar/protobuf/2.6.1/include   -L/usr/local/Cellar/protobuf/2.6.1/lib -lprotobuf-lite tileinfo.cpp ../../src/vector_tile.pb.cc -o tileinfo -lprotobuf-lite -lz
In file included from tileinfo.cpp:7:
./vector_tile_compression.hpp:5:10: fatal error: 'vector_tile_config.hpp' file not found
#include "vector_tile_config.hpp"
         ^
1 error generated.
make: *** [tileinfo] Error 1

好的,它现在在一个新文件之后,它只是想要越来越多。让我们将整个项目源移动到示例中......

$ cp ../../src/* .
$ make
c++   -D_THREAD_SAFE -I/usr/local/Cellar/protobuf/2.6.1/include   -L/usr/local/Cellar/protobuf/2.6.1/lib -lprotobuf-lite tileinfo.cpp ../../src/vector_tile.pb.cc -o tileinfo -lprotobuf-lite -lz
In file included from tileinfo.cpp:7:
In file included from ./vector_tile_compression.hpp:5:
./vector_tile_config.hpp:10:10: fatal error: 'protozero/types.hpp' file not found
#include <protozero/types.hpp>
         ^
1 error generated.
make: *** [tileinfo] Error 1

那看起来有点像进步(虽然我担心我转了一圈)。它想要protozero。它包含在名为deps的项目的子文件夹中。好的,我试着把它包括在内。

$ make -I ../../deps/protozero/include/
c++   -D_THREAD_SAFE -I/usr/local/Cellar/protobuf/2.6.1/include   -L/usr/local/Cellar/protobuf/2.6.1/lib -lprotobuf-lite tileinfo.cpp ../../src/vector_tile.pb.cc -o tileinfo -lprotobuf-lite -lz
In file included from tileinfo.cpp:7:
In file included from ./vector_tile_compression.hpp:5:
./vector_tile_config.hpp:10:10: fatal error: 'protozero/types.hpp' file not found
#include <protozero/types.hpp>
         ^
1 error generated.
make: *** [tileinfo] Error 1

同样,我在路径上尝试了一些变体,但是这个-I标志,我认为它没有按我认为的那样做。

所以在绝望中我复制了依赖。

$ cp -r ../../deps/protozero/include/protozero .
$ make
c++   -D_THREAD_SAFE -I/usr/local/Cellar/protobuf/2.6.1/include   -L/usr/local/Cellar/protobuf/2.6.1/lib -lprotobuf-lite tileinfo.cpp ../../src/vector_tile.pb.cc -o tileinfo -lprotobuf-lite -lz
In file included from tileinfo.cpp:7:
In file included from ./vector_tile_compression.hpp:5:
./vector_tile_config.hpp:10:10: error: 'protozero/types.hpp' file not found with <angled> include; use "quotes" instead
#include <protozero/types.hpp>
         ^~~~~~~~~~~~~~~~~~~~~
         "protozero/types.hpp"

此消息告诉我,我不应该复制文件,而是链接到它们。显然,我走错了路。我应该做什么呢?

1 个答案:

答案 0 :(得分:1)

你快到了。我会以更干净的方式回顾这些步骤(即使你已经完成了一些工作)。

首先,您需要下载依赖项。 Looking at mapnik-vector-tile project Makefile我们有:

PROTOZERO_REVISION=v1.3.0 git clone https://github.com/mapbox/protozero.git ./deps/protozero && cd ./deps/protozero && git checkout $(PROTOZERO_REVISION)

从项目的根文件夹运行此命令后,您的deps文件夹中包含protozero

最后,您必须通过附加

告诉编译器这个新的包含路径
-I./deps/protozero/include

CXXFLAGS的{​​{1}}(假设您使用的文件结构类似于您提供的the one内的the binary link)。

相关问题