Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ - undefined reference to `__gxx_personality_seh0'

I am having an issue when trying to build my C++ application in Eclipse (neon.2). This application is simply supposed to create a file, print the numbers 15-210, save the file, then close. This is the error I am getting each time I try to build it:

17:59:42 **** Incremental Build of configuration Debug for project Project1 ****
Info: Internal Builder is used for build
g++ -o Project1.exe Q1.o Q2.o displayHeader.o 
Q2.o:Q2.cpp:(.data+0x0): undefined reference to `__gxx_personality_seh0'
Q2.o:Q2.cpp:(.xdata+0x10): undefined reference to `__gxx_personality_seh0'
collect2.exe: error: ld returned 1 exit status

17:59:44 Build Finished (took 1s.391ms)

This only happens when I attempt to use either ofstream or ifstream in my program. I have successfully built & ran other (very simple) C++ applications that don't use this in Eclipse, but when I do, I get this error.

Here is my code:

#include<iostream>
#include<iomanip>
#include<fstream>

using namespace std;

int main(){

    ofstream outfile;
    outfile.open("nums.txt");

    for (int i = 15; i < 211; i++) {
    outfile << i << " ";
    }

    outfile.close();

    return 0;

}

I created the project with MingW, and I have the /bin folder in my environment path variable, and under Project/Properties/C/C++ Build/Environment all of the variables are set. I've been searching through forums and tutorials like crazy to try and see if I missed something during installation of either Eclipse or MingW, but I don't see any issues.

I hope I provided adequate information but please let me know if anything else could help. I've been pulling my hair out over this for almost a week. And thank you so much for any help.

like image 793
crackedact0r Avatar asked Oct 22 '25 08:10

crackedact0r


1 Answers

You didn't do anything wrong or miss anything during installation!

I had this issue before , this occurs in MingW compiler and ofstream objects, you should change this command

x86_64-w64-mingw32-gcc [your code file]

with this :

x86_64-w64-mingw32-g++ [your code file]

In short , change gcc with c++ in Eclipse or command line.

My opinion, use MS Visual Studio for compiling C++ code in Windows, its compiler give you more features and flexibility and you could develop faster.

like image 169
malloc Avatar answered Oct 24 '25 20:10

malloc