使用静态库编译 C++
Compile C++ with static lib
这对你们来说可能是个愚蠢的问题,但我从来没有任何 C++ 经验。我正在使用开源项目 osrm (which is awesome). Still to request a route, you have make an http request. To reduce the running time, I would like to build a wrapper around the code and call it using the command line. So I googled a bit and found that osrm already creates a static lib (.a file) when compiling the project. I also found a piece of code that points me in the right directions for building a wrapper. So to begin I build a simple hello world program (see below) that includes some files from that static lib. To compile I followed this 教程。 我的目录结构如下所示: ./helloWorld.cpp ./libs/libOSRM.a
编译命令是这样的:
gcc –static helloworld.cpp –L ./libs –l libOSRM.a
它自己的代码:
#include "Router.h"
#include "boost/filesystem/path.hpp"
#include "ServerPaths.h"
#include "ProgramOptions.h"
#include <InternalDataFacade.h>
#include <viaroute.hpp>
#include <iostream.h>
main()
{
cout << "Hello World!";
return 0;
}
我得到的确切错误:
fatal error: ServerPaths.h: No such file or directory #include "ServerPaths.h"
将-IPathToTheHeaderFiles
添加到编译器选项。所以它会找到要包含的文件。将 PathToTheHeaderFiles 替换为文件 ServPaths.h 所在的路径。
编辑:根据需要添加尽可能多的 -I
以获取更多头文件。
此外,值得阅读一本关于 C++ 的书 or/and GCC manual1
1 第 3.11 节会有所帮助。