Martin Lauridsen
Martin Lauridsen

Reputation: 341

Boost program will not working on Linux

I have this program which uses Boost::Asio for sockets. I pretty much altered some code from the Boost examples. The program compiles and runs just like it should on Windows in VS. However, when I compile the program on Linux and run it, I get a Segmentation fault.

I posted the code here

The command I use to compile it is this:

c++ -I/appl/htopopt/Linux_x86_64/NTL-5.4.2/include 
-I/appl/htopopt/Linux_x86_64/boost_1_43_0/include 
mpqs.cpp mpqs_polynomial.cpp mpqs_host.cpp -o mpqs_host 
-L/appl/htopopt/Linux_x86_64/NTL-5.4.2/lib -lntl 
-L/appl/htopopt/Linux_x86_64/gmp-4.2.1/lib -lgmp -lm 
-L/appl/htopopt/Linux_x86_64/boost_1_43_0/lib -lboost_system 
-lboost_thread -static -lpthread

By commenting out code, I have found out that I get the Segmentation fault due to the following line:

boost::asio::io_service io_service;

Can anyone provide any assistance, as to what may be the problem (and the solution)?

Thanks!

Edit: I tried changing the program to a minimal example, using no other libraries or headers, just boost/asio.hpp:

#define DEBUG 0

#include <boost/asio.hpp>

int main(int argc, char* argv[]) {  
     boost::asio::io_service io_service;
     return 0;
}

I also removed other library inclusions and linking on compilation, however this minimal example still gives me a segmentation fault.

Upvotes: 2

Views: 749

Answers (1)

Rakis
Rakis

Reputation: 7874

From the GCC online documentation of the -static option:

On systems that support dynamic linking, this prevents linking with the shared libraries.

Boost can support static-only linkage but only if it was configured that way when the OS Package maintainer built it. Are you absolutely certain you should be using this flag? If not, try recompiling without the flag and see if that doesn't take care of the problem.

Upvotes: 4

Related Questions