Having trouble figuring out how to compile and link a simple boost program that just includes some boost libraries.
The code is as follows
#include <iostream>
#include <boost/array.hpp>
#include <boost/asio.hpp>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
Note to the moderators: there are a lot of posts on SO asking similar questions. However, I didn't find one that completely solved my issue (the key insight I was missing was that I needed to install boost-devel
). Thus, I created this Q&A.
Here are the steps necessary to compile your program
Install boost
and boost-devel
sudo yum install boost # installs the libraries for linking sudo yum install boost-devel # installs the header files for you to include for compilation
The command you're trying to get Eclipse to produce is the following:
g++ net-server.cpp -I /usr/include -L/usr/lib64/ -lboost_system
The -L/usr/lib64
is actually unnecessary, but I include it for the reader, since it allows the reader more easily understand the relationship between the -l
inclusion and the -L/usr/lib64
that's by default included in Oracle Linux (probably RHEL too).
The -I /usr/include
is also unnecessary, but it's included to make it clear to the reader where the boost/array.hpp
etc. files are coming from for the compilation phase.
To get Eclipse to produce that command
+
icon and add the boost_system
library.Heads up that I chose the "cross gcc compilation" option instead of the Linux cross-compile option. This is actually from within Nvidia's version of Eclipse (distributed with CUDA as "Eclipse Nsight"), so the instructions for the non-Nvidia version of Eclipse may vary a bit.
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.