C++ - undefined reference to `__gxx_personality_seh0' - c++

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.

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.

Related

G++ linker exiting with code 1 with an undefined reference to 'vkCreateInstance'

I've been having some trouble setting up a custom Vulkan build and development environment with G++ and VSCode. G++ doesn't seem to be linking to the proper library files, and is not recognizing only one of the Vulkan functions I've defined in main.cpp. That, or it's not properly finding the header files. I followed a video tutorial and did my own tweaking to make it work. (You can find it here https://www.youtube.com/watch?v=tRQ3zqCiKdQ). He creates a .bat file to run the compiler command and sets up some boilerplate tasks.json and launch.json files. The .bat file runs fine and makes it so that I don't have to type out file paths each time. Those work fine. And then I've copied his code as well just to get the build environment working, which I'm stuck on.
I'll admit, I'm not a wizard with command line compilers, but I just can't seem to find any information online that can help me. It's either outdated or the answer doesn't fix my issue. So I thought I'd try here. (first question btw).
I've got a basic, very recent and up-to-date Vulkan installation, a main.cpp file, a build.bat file, and g++ version 11.2.0 (according to MSys2, the latest version). I'm on Windows 64 bit running VSCode. I've included some in order, ending with a capture of my working directory. Afterwards, I'll list what I've tried.
Main.cpp
#include <iostream>
#include <vulkan/vulkan.h>
#include <vulkan/vulkan.hpp>
#include <vulkan/vulkan_core.h>
using namespace std;
int main(){
VkApplicationInfo appInfo = {};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "Pong";
appInfo.pEngineName = "PongEngine";
VkInstanceCreateInfo instanceInfo = {};
instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
instanceInfo.pApplicationInfo = &appInfo;
VkInstance instance;
VkResult result = vkCreateInstance(&instanceInfo, NULL, &instance);
if(result == VK_SUCCESS){
cout << "Successful!" << endl;
}
}
Build.bat
#echo off
SET include=-I ./src -I C:/VulkanSDK/1.2.198.1/Include/
SET links= -L /C:/VulkanSDK/1.2.198.1/Lib/vulkan-1.lib
#echo "Building main..."
g++ -Wall %include% %links% -o main src/main.cpp
Directory
Root
|-----src
|-main.cpp
|-build.bat
I have tried almost everything. This is always the output:
"Building main..."
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\brado\AppData\Local\Temp\ccj9NixH.o:main.cpp:(.text+0xabe): undefined reference to `vkCreateInstance'
collect2.exe: error: ld returned 1 exit status
The terminal process "E:\coding\vulkan\personal_vulkan_expirimenting\build.bat" terminated with exit code: 1.
Despite -L supposedly specifying directories to search in, anytime I don't include vulkan-1.lib on the -L tag, it breaks.
I've tried using -l to specify the specific library and that doesn't seem to work
I feel like I've tried every flag under the sun. Someone somewhere said it might have to do with -m64 flag but that wasn't it.
I've added in two seemingly redundant header files that I've manually searched for vkCreateInstance in and included them in the hopes that that would trigger it but in vain
I've edited the file paths every which way to see if the formatting was the issue
I have read and checked the g++ and Vulkan documentation to see if anything could help and I could find seemingly nothing that would have helped. Perhaps I'm looking in the wrong place. But I've been googling for hours.
Before this whole fiasco started, I was also trying to use GLFW and GLM as per the basic Vulkan tutorial that's provided, and that was also having linking problems, which to me, narrows it down to how I'm using the compiler.
What's so confusing is that the intellisense on VS Code recognizes the function, and the linker has no issue with the other functions. It may be a limitation in my understanding of compilers, or I've tunnel-visioned and am not seeing outside the problem, I don't know. I'll admit I'm not insanely familiar with g++, but as I tried to get more familiar with it over the course of this problem (that I've been on for the last couple hours) I couldn't find any documentation Let me know what other information I can provide, maybe there's something I'm leaving out. Thanks so much!

MinGW: Internal error when building a C++ program

I had been running C++ programs with G++17 quite comfortably, when one day for no apparent reason, this error shows up:
internal error in mingw32_gt_pch_use_address, at
config/i386/host-mingw32.c:190: MapViewOfFileEx: Attempt to access
invalid address.
Below is the complete error output:
[Finished in 4.5s with exit code 1]
[cmd: ['g++.exe', '-std=c++17', '-D DIV_DEBUG', 'D:\\Codes\\code.cpp', '-o', 'code.exe', '&&', 'code.exe<inputf.in>outputf.in']]
[dir: D:\Codes]
[path: C:\Python38\Scripts\;C:\Python38\;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\MinGW\bin;C:\ProgramData\pbox;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd;C:\Users\asus\AppData\Local\Microsoft\WindowsApps;C:\Users\asus\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;C:\tools;C:\Users\asus\AppData\Roaming\npm;C:\Users\asus\AppData\Local\atom\bin]
I've been searching for a solution for three days now and haven't found it yet. It looks like a bug in MinGW but I do not know how to fix this. My last option is to delete everything related to MinGW and reinstall it. Any better ideas are appreciated.
The code which I'm trying to compile.
#include <bits/stdc++.h>
int main() {
std::cout << "Hello, World!\n";
return 0;
}
It appears that removing the "bits/stdc++.h" header file removes this error. I would still like to know how I can fix this as I use this library on a daily basis for all my programs.
Edit: I tried building on Windows Powershell but the same error comes up.
PS D:\Codes> g++.exe -std=c++17 -D DIV_DEBUG code.cpp -o code.exe
internal error in mingw32_gt_pch_use_address, at config/i386/host-mingw32.c:190: MapViewOfFileEx: Attempt to access invalid address.
Update: Tried reinstalling MinGW. It didn't work.
Okay, so the issue went as miraculously as it had appeared. I precompiled the header files after reinstalling MinGW and for some reason, it fixed the issue. I'm not sure if this action triggered the fix.
If someone can throw some light on this strange behaviour, I would mark that answer as accepted.

Eclipse g++ not found in path: windows

I am attempting to setup SDL2 for C++ with Eclipse on Windows 7.
In order to do so, I am following the tutorial in this link, which states that I must first install MinGW. So I follow the link provided in order to setup MinGW. I follow all the steps without issue. I then open Eclipse and attempt to build a simple hello world program:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
return 0;
}
To my surprise, this code doesn't build, with 6 errors.
I then proceed to simplify the program further:
int main()
{
return 0;
}
This also does not compile. There are two errors:
Program "g++" not found in PATH
Program "gcc" not found in PATH
Here is a screenshot.
However, my path does contain "C:\mingw\bin". I have also tried changing this to "C:\mingw". Looking inside "C:\mingw\bin", I find gcc and g++:
In addition, compiling a test program using the command line (g++ Test.cpp -o Test) works just fine, as does "g++ -v".
I have been searching the web for hours, and can't seem to find an answer as to why Eclipse can't seem to compile anything with MinGW. Questions I have looked at on SO (which haven't been able to fix my issue) include:
Eclipse mingw binary not found
Eclipse not finding c std libraries
g++ not found in path
Eclipse C++ : "Program g++ not found in PATH"
Program g++ not found in path
Program g++ not found in path C++ [duplicate]
Eclipse CDT (Juno) in Win7: Cannot find g++ in PATH, iostream unresolved and other fun stuff
Additional info:
Window > Preferences > C/C++ > Build > Settings > "CDT GCC Built-in Complier Settings MinGW [Shared]" : Toolchain MinGW GCC is not detected on this system.
I have also reinstalled Eclipse to no avail.
I realize that this may be a duplicate question of some that I have linked, but the information in previous questions have not been able to fix my problem, and I fear that adding a comment to an old question may not result in an answer.
Please request additional information as needed.
You need to set the environment for the c/c++ builder.
First you need to install the GNU tool-chain, you can choose either MinGW or Cygwin. You can see the steps here. I used MinGW.
Go to Window->Preferences->C/C++->Build->Environment and add a new variable, name it whatever you want for example a named it "MINGW", now paste the binaries directory of MinGW which is by default C:\MinGW\bin, you should have something like this:
Now when you create a new project you just have to select the MinGW tool-chain:
Hope that helps.
It appears as though I have fixed the problem for the moment.
In case others encounter the same issue:
Project > Properties > C/C++ Build > Settings > MinGW C++ Linker > Command changed from "g++" to "C:\mingw\bin\g++".

Commands 'cin' and 'cout' not working

I installed MinGW on Windows 8.1 to code in C++ and I am trying to run my codes using Sublime Text 3. So far I am successful, but I am not being able to use cin and cout. I know I can use scanf and printf, instead. But I might need to use cin and cout as well. When I am trying to build a C++ code containing cin or cout, it gives a compile time error. Let's see at a piece of code which generates such an error:
#include "iostream"
#include "cstdio"
using namespace std;
int main()
{
int n;
std::cin >> n;
std::cout << n;
}
The error coming up on my machine is: (Note:I have WinGHCi installed on my machine to use Haskell)
Info: resolving std::cin by linking to __imp___ZSt3cin (auto-import)
Info: resolving std::cout by linking to __imp___ZSt4cout (auto-importc:/program files (x86)/haskell platform/2013.2.0.0/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: warning: auto-importing has been activated without --enable-auto-import specified on the command line.
This should work unless it involves constant data structures referencing symbols from auto-imported DLLs.)
[Finished in 1.4s]
Please help me to find what is wrong. I deliberately don't want to use IDEs.
Note that a general suggestion is to use <iostream> instead of "iostream". In this regard, using <iostream> produces the following error on compiling the same code (with "iostream" and "cstdio" replaced by <iostream> & <cstdio>):
Info: resolving std::cin by linking to __imp___ZSt3cin (auto-import)
Info: resolving std::cout by linking to __imp___ZSt4cout (auto-importc:/program files (x86)/haskell platform/2013.2.0.0/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: warning: auto-importing has been activated without --enable-auto-import specified on the command line.
This should work unless it involves constant data structures referencing symbols from auto-imported DLLs.)
[Finished in 1.8s]
These type or errors is often throwned when you are using:
headers with version x
----------------------
lib with version y
So, check this.
update
If you're using compiler with version 4.6.3 but you're using header of 4.6 (for any reason), you got these kind errors.
Useful command:
which g++ #locate where is your compiler (generally /usr/bin/g++)
g++ --version #get compiler's version
find / -name iostream | grep c++ #find where're your includes

I am getting 5 errors in my "hello world" C++ program

My code is...
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!\n";
}
The errors i am getting are...
Description Resource Path Location Type
Symbol 'std' could not be resolved main.cpp /First/src line 3 Semantic Error
Program "g++" not found in PATH First [Discovery Options] page in project properties C/C++ Problem
Program "gcc" not found in PATH First [Discovery Options] page in project properties C/C++ Problem
Symbol 'cout' could not be resolved main.cpp /First/src line 8 Semantic Error
Program "make" not found in PATH First C/C++ Problem
Does anybody know whats wrong? This is my first time trying C++ and i am using eclipse-cpp-kepler-SR1-win32-x86_64
I can't comment yet but based on the error messages it seems that the compiler has not been setup properly or Eclipse cannot find it.
http://www.eclipse.org/forums/index.php/t/238347/
Make sure Eclipse can find your compiler.
You may have to setup some environment variables.
http://www.computerhope.com/issues/ch000549.htm
Also try following the instruction in the error message.
I hope that helps.
install g++ in your system and set env path!
In my case on osx, the errors on the basic hello world project were caused by something silly. everything was installed but i had no clue that the gcc expected me to read and agree to a License. go to terminal and type $ gcc. i was then prompted with the need to deal with the license agreement. once that was done, eclipse build the hello world project without problem. hope this helps others ...