dome some
dome some

Reputation: 479

boost python after compile and run gives me segfault

my sample code:

#include <iostream>
#include <boost/array.hpp>
#include <boost/python.hpp>
using namespace std;
int main(){
  boost::array<int, 4> arr = {{1,2,3,4}};
  cout << "hi" << arr[0];
  return 0;
}

compile using :

g++ a.cpp -o a -I /usr/include/python2.7/ -lboost_python -lboost_system -shared -fPIC

the run ./a and it gives me:

Segmentation fault (core dumped)

I think it is something related to boost python library, if I remove

#include <boost/python.hpp> 

and compile with

g++ a.cpp -o a

then ./a, everything works well. How do I solve it?

Upvotes: 2

Views: 589

Answers (2)

dome some
dome some

Reputation: 479

g++ a.cpp -o a -I /usr/include/python2.7/ -lboost_python -lpython2.7 -lboost_system -fPIC

I added -lpython2.7 and now its working

Upvotes: 0

sehe
sehe

Reputation: 393134

Drop the -shared flag on the executable:

http://coliru.stacked-crooked.com/a/5479166d518fb207

Upvotes: 1

Related Questions