重新定义错误可能导致分段错误问题(1个文件)

时间:2019-04-26 16:48:16

标签: c++ visual-studio segmentation-fault gdb g++

第一篇文章,所以给我一些时间。

我一直在使用神经网络运行神经网络时遇到问题 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行,因此我决定同时包含#includes和我的main文件。

#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中完美地编译和执行。

0 个答案:

没有答案