I am compiling my code using g++
g++ -g -O3 -fPIC -shared -lstdc++ -std=c++0x -I/home/nikesh.joshi/somepath/ main.cpp /home/nikesh.joshi/ml/somepath_apis/somepath/somefile.o
I have already included lib using ldconfig command. I need to use -fPIC because eventually this library will be linked with other static libraries to form a dynamic library. When I run this code using the following command
./a.out
It gives "Segment Fault".
code of main.cpp
#include<iostream>
using namespace std;
int main(){
cout<<"Hello";
}
If I compile this code using g++ main.cpp then code run successfully. I need to compile this code with all lib, so I can use functions of these libs.
I found same problem here : Why does including -fPIC to compile a static library cause a segmentation fault at run time?
But this does not resolve my problem.