Возможна ошибка сегментации, вызванная ошибкой переопределения (1 файл) - PullRequest
1 голос
/ 26 апреля 2019

первый пост, так что дайте мне немного расслабиться.

У меня были проблемы с запуском нейронной сети с использованием g++-8.2.0 -std=c++2a proj1.cpp a

При запуске с использованием Visual Studio, программа компилируется и работает без сбоев и выполняется в соответствии с желаемой логикой. При запуске с использованием g ++; однако в коде возникает следующая ошибка сегментации:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000409100 in std::string::_M_data() const ()
Missing separate debuginfos, use: debuginfo-install glibc-2.17-260.el7_6.4.x86_64
(gdb) where
#0  0x0000000000409100 in std::string::_M_data() const ()
#1  0x0000000000409170 in std::string::_M_rep() const ()
#2  0x0000000000406c4c in std::string::length() const ()
#3  0x0000000000404df6 in main ()

После получения этой ошибки я добавил несколько блоков try-catch и попытался перекомпилировать с флагом -g. При компиляции с -g программа не компилируется и возвращает несколько ошибок определения; однако, это единственный используемый файл, и все включения находятся в библиотеке std. Полная ошибка:

a:(.bss+0x1c0): multiple definition of `gMap'
/tmp/cc0u5Onx.o:(.bss+0x60): first defined here
a:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/lib/../lib64/crt1.o:(.rodata.cst4+0x0): first defined here
a: In function `main':
(.text+0x218c): multiple definition of `main'
/tmp/cc0u5Onx.o:/home/ugrads/d/dhlaurel/ms_windows/cpsc_redirected/cmpSci/csce420/proj/proj1.cpp:621: first defined here
a: In function `letterPicker(Network*)':
(.text+0xe01): multiple definition of `letterPicker(Network*)'
/tmp/cc0u5Onx.o:/home/ugrads/d/dhlaurel/ms_windows/cpsc_redirected/cmpSci/csce420/proj/proj1.cpp:345: first defined here
a: In function `data_start':
(.data+0x8): multiple definition of `__dso_handle'
/opt/gcc8.2.0/bin/../lib/gcc/x86_64-pc-linux-gnu/8.2.0/crtbegin.o:(.data+0x0): first defined here
a: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/lib/../lib64/crti.o:(.fini+0x0): first defined here
a: In function `T()':
(.text+0xe8): multiple definition of `T()'
/tmp/cc0u5Onx.o:/home/ugrads/d/dhlaurel/ms_windows/cpsc_redirected/cmpSci/csce420/proj/proj1.cpp:19: first defined here
a: In function `_start':
(.text+0x0): multiple definition of `_start'
/lib/../lib64/crt1.o:(.text+0x0): first defined here
a: In function `_init':
(.init+0x0): multiple definition of `_init'
/lib/../lib64/crti.o:(.init+0x0): first defined here
a: In function `gP(float)':
(.text+0x114d): multiple definition of `gP(float)'
/tmp/cc0u5Onx.o:/home/ugrads/d/dhlaurel/ms_windows/cpsc_redirected/cmpSci/csce420/proj/proj1.cpp:414: first defined here
a: In function `data_start':
(.data+0x0): multiple definition of `__data_start'
/lib/../lib64/crt1.o:(.data+0x0): first defined here
a: In function `valueOf(int)':
(.text+0xf6): multiple definition of `valueOf(int)'
/tmp/cc0u5Onx.o:/home/ugrads/d/dhlaurel/ms_windows/cpsc_redirected/cmpSci/csce420/proj/proj1.cpp:25: first defined here
a: In function `data_start':
(.data+0x18): multiple definition of `DEBUG'
/tmp/cc0u5Onx.o:/home/ugrads/d/dhlaurel/ms_windows/cpsc_redirected/cmpSci/csce420/proj/proj1.cpp:19: first defined here
a:(.bss+0x160): multiple definition of `solution'
/tmp/cc0u5Onx.o:/home/ugrads/d/dhlaurel/ms_windows/cpsc_redirected/cmpSci/csce420/proj/proj1.cpp:19: first defined here
a: In function `g(float)':
(.text+0xfb9): multiple definition of `g(float)'
/tmp/cc0u5Onx.o:/home/ugrads/d/dhlaurel/ms_windows/cpsc_redirected/cmpSci/csce420/proj/proj1.cpp:374: first defined here
/opt/gcc8.2.0/bin/../lib/gcc/x86_64-pc-linux-gnu/8.2.0/crtend.o:(.tm_clone_table+0x0): multiple definition of `__TMC_END__'
a:(.data+0x20): first defined here
/usr/bin/ld: error in a(.eh_frame); no .eh_frame_hdr table will be created.
collect2: error: ld returned 1 exit status

Я не уверен, где возникает рассматриваемая проблема, но после добавления некоторых блоков в мой основной файл он не смог даже добраться до строки 1, поэтому я решил включить мои #include, а также мой основной файл.

#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>
#include <random>
#include <fstream>
#include <numeric>


int main()
{
    int numLayers = 4;  //at least 2
    int hiddLayerSize = 16;
    int inputSize;
    int outputSize;
    std::cout << "ERROR BLOCK 1";
    std::vector<std::vector< std::string >  > letters;
    try{
        letters = bdfReader("ie9x14u.bdf");
    }catch (std::exception const &e){
        std::cout << "FILE READ ERROR\n";
        return -1;
    }

    std::vector<std::string> starLetters;
    std::cout << "ERROR BLOCK 2";

    std::vector<std::string> letterInput = sampleInp(letters);
    std::vector<std::string> letterOutput = std::vector<std::string>(26, "00000000000000000000000000");

    /* This was where I thought the problem might be occurring since it mentioned string errors, but after commenting it out, nothing happened

    for (int i = 0; i < 26; i++) {
        letterOutput[i][i] = '1';
    }
    */





    inputSize = letterInput[0].length();
    outputSize = letterOutput[0].length();



    Network* letterNet = new Network(majorityInput, majorityOutput, numLayers, hiddLayerSize, inputSize, outputSize);


    std::pair<std::vector<std::string>, std::vector<std::string> > majExamp = std::pair<std::vector<std::string>, std::vector<std::string> >(majorityInput, majorityOutput);

    std::pair<std::vector<std::string>, std::vector<std::string> > letterExamp = std::pair<std::vector<std::string>, std::vector<std::string> >(letterInput, letterOutput);

    letterNet = backPropLearn(letterExamp, letterNet);

    std::cout << weightsPrinter(letterNet);
    std::cout << std::to_string(networkAcc(letterExamp, letterNet)) + "* 100%\n";
    std::cout << "\n all done";


    return 0;

}

Любая помощь будет принята с благодарностью. Как упоминалось ранее, программа компилируется и выполняется безупречно в Visual Studio 2017.

...