Using std::string causes Windows "Entry Point Not Found" [duplicate] - c++

This question already has answers here:
the procedure entry point __gxx_personality_v0 could not be located
(5 answers)
Closed 4 years ago.
When I compile this with G.C.C.:
#include <iostream>
#include <string>
int main()
{
std::cout << std::string("\r\n");
return 0;
}
By using the following batch:
g++ -Wall main.cc
And attempt executing the output (a.exe), then Windows crashes the initialization with this error:
If I avoid using std::string in the C++ code it executes normally, even including <string>. Any ideas?
Note, first time testing std::string.
I run Windows 8 / 64 bits. My compiler includes this file build-info.txt:
# **************************************************************************
version : MinGW-W64-builds-4.3.0
user : nixman
date : 03.30.2017- 1:01:08 PM
args : --mode=gcc-6.3.0 --buildroot=/c/mingw630 --jobs=2 --rev=2 --threads=win32 --exceptions=sjlj --arch=i686 --bin-compress
[much more here...]
# **************************************************************************
Also note that I'm used to disable and uninstall all possible anti-virus utilities (e.g., Windows Defender).

It was hard to find a solution (zZZzzZzZzZz), but finally, it's on this answer.
g++ -Wall -D_GLIBCXX_USE_CXX11_ABI=0 main.cc

Related

Mingw and c++ vectors [duplicate]

This question already has answers here:
the procedure entry point __gxx_personality_v0 could not be located
(5 answers)
Closed 4 years ago.
I am writing a simple small program in c++ to test vectors. The following code works well and output hello to the cmd.
The steps I follow are:
g++ filename.cpp to compile
.\a.exe to run
#include <iostream>
#include <vector>
using namespace std;
int main()
{
cout<<"hello";
return 0;
}
However, when I declare a vector, the hello does not show and the program seem to not working at all.
#include <iostream>
#include <vector>
using namespace std;
vector<int> a;
int main()
{
cout<<"hello";
return 0;
}
I do not get any error message while compiling. But I do get a certain message about no entry point when I run outside the cmd.
The procedure entry point _ZNKSt9baisc_ioslcSt11char_traitslcEEcvbEv
could not be located in the dynamic link library
I searched on google and stack overflow but could not find a solution to my problem.
For anyone who would read this later on, I had something called gtk installed and defined in the environment path variables and it seems like it was colliding with MinGW. Everything runs smooth by writing:
g++ ex1.cpp -static-libgcc -static -static-libstdc++
The problem is likely caused by the fact that the DLL containing the function the program is trying to access (_ZNKSt9baisc_ioslcSt11char_traitslcEEcvbEv here) is not found by Windows when it tries to execute your program.
There are a few solutions for this :
Static linking with the C++ library (--static-libstdc++) (this will directly link the C++ library into your executable (this may make your program bigger))
Putting the libstdc++ dll in your program folder (you should be able to find it somewhere in the compiler install folder)
Adding the path to the libstdc++ dll to the global PATH variable (If you want to know more about adding to the PATH, see here) so that the dll will be found for any executable running on your computer
Doing any of these should fix your problem.

iostream.h: no such file or directory [duplicate]

This question already has answers here:
fatal error: iostream.h no such file or directory [duplicate]
(3 answers)
Closed 6 years ago.
I am using Windows 8.1 and Dev C++ and I have the following code:
#include<iostream.h>
main()
{
cout<<"welcome to devc++";
system("pause");
}
The syntax is correct, but I get an error that says:
[Error] iostream.h: No such file or directory
I have tried to change to location of this .cpp folder, watched video tutorials, but I could not point out why I am getting this error and how to remove it.
You need to use #include<iostream> instead of #include<iostream.h>. The later one has been deprecated now; which is why you face the error. More details here.
Besides, main() being a function, should have a return type. So, you should write int main() and not just main().
Just do,
#include <iostream>
instead of
#include <iostream.h>
because, as C++ progressed from specific implementation to standard one,.h were deprecated from he library.
In addition to changing to
#include <iostream>
You can also add
using namespace std;
before main if you want to use cout without having to use std::cout.

G++ throws error when compiling C++ code including stoi [duplicate]

This question already has answers here:
Problems with std::stoi, not working on MinGW GCC 4.7.2
(2 answers)
Closed 7 years ago.
UPDATE:
Not only does this affect the MinGW version of G++, it also affects the Cygwin version. I can't use mingw-64 as its Windows port (win-builds) does not install G++ properly (doesn't install required .dlls) and when I install them myself G++ doesn't even run. This makes the problem even more serious.
END UPDATE
So I want to compile some C++ code with G++:
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
int maxInt = stoi(argv[1]);
srand(time(0));
cout << rand() % maxInt << endl;
}
When I compile it though, I get this error:
test.cpp: In function 'int main(int, char**)':
test.cpp:6:30: error: 'stoi' was not declared in this sopce
int maxInt = stoi(argv[1]);
^
I have tried compiling it with -std=c++11 and -std=c++0x, but it still gives this error. I am trying to compile it on a Windows 8.1 laptop with about 200 GB of free space. It has 4 GB of RAM, and has MinGW installed from SourceForge. I'm using GCC version 4.8.1, so if the version may be the case, please tell me where to get a higher version?
Since you are trying to parse a c-string, why not to use std::atoi? Remember to include cstdlib.

Netbeans C++ Application won't build [duplicate]

This question already has an answer here:
How to add a library include path for NetBeans and gcc on Windows?
(1 answer)
Closed 8 years ago.
I recently installed the MiniGW compiler so that I can start learning C++. But when I go to create a new project and have it include main, I get two error messages from the start(after the project has been created) Cannot Find Include File <cstdlib> and Unable to resolve identifier std and when I try and 'Clean and Build' the project, the clean is successful and the build is not. I have done a google search and ran across this post Netbeans 7.2 shows "Unable to resolve identifier" , although build is successful , but I'm not sure my problem is exactly the same since my project won't build (or maybe it is, I don't know), and I'm also not sure I understand the accepted answer. Can this be multiple problems or just one? I want to get this fixed so I can learn!
/*
* File: main.cpp
* Author: Zf
*
* Created on December 16, 2014, 1:50 PM
*/
#include <cstdlib>
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
return 0;
}
Edit: Lines 7 and 8 are where the error messages are.
Have you Tool Collection set properly ?
for example
<cstdlib> is found in C:\minGW\lib\gcc\mingw32\4.8.1\include\c++
Sounds like you need to tell the compiler where to find cstdlib. See this: How to add a library include path for NetBeans and gcc on Windows?
Cstdlib contains C functions, they are not wrapped in a namespace. Remove the using namespace std; line

How do I setup my g++ compiler for C++11? [duplicate]

This question already has answers here:
Closed 10 years ago.
I tried a basic program:
// ThreadExample.cpp
#include <string>
#include <iostream>
#include <thread>
using namespace std;
void task1(string msg)
{
cout << "task1 says: " << msg;
}
int main()
{
thread t1(task1, "Hello");
t1.join();
}
One I actually found on stackoverflow, but I tried compiling it using:
g++ -std=c++0x -pthread ThreadExample.cpp -o ThreadExample -lm
However, I keep getting an error that thread is undeclared. I have version 4.7.1 of the MinGW GNU for Windows. Is there something I can change so I can use C++11?
Noone has contributed an implementation of <thread>, <mutex> etc for Mingw yet, except when using Mingw with (optional) Pthreads support via a third-party pthreads implementation.
I started a thread at http://gcc.gnu.org/ml/libstdc++/2012-05/msg00020.html with some suggestions for implementing the missing features in terms of Windows native threads, but as I don't have a Windows machine and noone else has volunteered to do anything, nothing happened. I have almost zero interest in implementing it myself, because I never develop for Windows so it would be of no use to me whatsoever, and I would rather spend my limited free time implementing things I will actually use. If anyone wants to work on it I'd happily advise them and review their code and help shepherd it into GCC.