jeudi 20 juillet 2017

Segmentation fault from boost (system_complete) function inside my project(a library) but not on the same function in a more simple file

I recently upgradeted my boost library to 1.63 version. But the function system_complete now doesn't work inside my project. The code in my project now goes in segmentation fault. But when I compiled the broken code in a simple program of test:

#include <boost/filesystem.hpp>

namespace fs=boost::filesystem;

    int main()
{
    fs::path selfpath=fs::system_complete("Testa:
}

and it compiles and works with:

g++ -std=c++11 Testa5.cpp -lboost_filesystem -lboost_system

but on the same computer but inside my library goes in segmentation fault on the instruction system_complete.

How is it possible? How can I fix it?

(I'm on Ubuntu) (I installated boost from here: http://ift.tt/2gOdhh1)

This is the piece of code that cause problem:

#define BASE_PATH_EXE   0                                   // the working dir is where the executable is
#include <boost/filesystem.hpp>

namespace fs=boost::filesystem;
int main(int argc, char* argv[]){


    clock_t tStart;

    //file
    bool exec_lstar, exec_obp , exec_approx_obp;
    string obp_dfa_file="";
    string random_dfa_file;

    // working dir
    string base_path;
    string res_path;

    //parse input arguments

    array<bool,3>  whatexec= parse_input_args(argc, argv, &obp_dfa_file); //se passo oltre al nome dell'eseguibile il nome di un file eseguo sia lstar e che obp su questo dfa. Se come secondo argomento passo nothing significa che sono interessato a eseguire solo obp
    exec_lstar =      whatexec[0];
    exec_obp   =      whatexec[1];
    exec_approx_obp = whatexec[2];

    // Setting the locale, in order to choose the correct language
    //string curr_os_locale = setlocale(LC_CTYPE, "");
    //cout<<"Current locale: "<<curr_os_locale<<endl;

    // Choose your base path: current dir or path of executable?
    if(BASE_PATH_EXE){
        // complete path of the executable,that is in the cartel bin (of release or debug)
        cout<<"I'm here"<<endl;
        fs::path selfpath=fs::system_complete(argv[0]);
cout<<"I'm here"<<endl;
        // path of the folder where the executable is: it is assumed as the working directory
        base_path = selfpath.parent_path().c_str();
    }else{
        // the working dir is the current dir
        base_path = fs::current_path().parent_path ().c_str();
    }

}

Aucun commentaire:

Enregistrer un commentaire