使用静态库编译 C++ [英] Compile C++ with static lib

查看:61
本文介绍了使用静态库编译 C++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这对你们来说可能是一个愚蠢的问题,但我对 C++ 没有任何经验.我正在使用一个开源项目 osrm(这很棒).仍然要请求路由,您必须发出 http 请求.为了减少运行时间,我想围绕代码构建一个包装器并使用命令行调用它.所以我google了一下,发现osrm在编译项目时已经创建了一个静态lib(.a文件).我还发现了一个 一段代码,它为我指明了构建包装器的正确方向.因此,首先我构建了一个简单的 hello world 程序(见下文),其中包含来自该静态库的一些文件.为了编译,我遵循了 this 教程.我的目录结构如下所示:./helloWorld.cpp./libs/libOSRM.a

this will probably a dumb question for you guy's but I have no experience in C++ what so ever. I'm using an open source project 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 tutorial. My directory structure looks like 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;
}

我得到的确切错误:

致命错误:ServerPaths.h:没有这样的文件或目录#include "ServerPaths.h"

fatal error: ServerPaths.h: No such file or directory #include "ServerPaths.h"

推荐答案

-IPathToTheHeaderFiles 添加到编译器选项.所以它会找到要包含的文件.将 PathToTheHeaderFiles 替换为您的文件 ServPaths.h 所在的路径.

Add the -IPathToTheHeaderFiles to the compiler options. So it will find the files to be included. Replace PathToTheHeaderFiles with the path where your file ServPaths.h resides.

添加尽可能多的 -I 以用于进一步的头文件.

Add as many -I as you need for further header files.

此外,值得阅读一本关于 C++ 或/和 GCC 手册1

Additionally it would be worth to read a book about C++ or/and the GCC manual1

1 3.11 节会有所帮助.

1 Section 3.11 will help.

这篇关于使用静态库编译 C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆