简体   繁体   中英

Compile C++ with static lib

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

And the command to compile is this:

gcc –static helloworld.cpp –L ./libs –l libOSRM.a

The code it selve:

#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;
}

the exact error I got:

fatal error: ServerPaths.h: No such file or directory #include "ServerPaths.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.

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

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

1 Section 3.11 will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM