Unable to execute program using C++ IDE Codeblock GNU GCC compiler - c++

Good evening all and thank you for any help you can provide,
I have started off on my journey of trying to learn C++ and am struggling to execute any code that I have written. I have tried using both versions 13.12 and 16.01 of Codeblock and have also tried building multiple files. Same error message appears with all. Here is the sample code I first attempted with:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello\tI am your computer talking." << endl;
return 0;
}
Here is the error message that appears when I try to build:
File Line Message
===Build: Debug in SayHello (compiler: GNU GCC Compiler) ===
1d cannot find -1pthread
=== Build failed: 1 error(s), 0 warnings(s) (0 minute (s), 0 .. second(s)) ===
Could anyone advise on a resolution? I have read conflicting solutions, such as somewhere in my computer a file is missing (1pthread?). Again, really grateful for any advice and virtual cake will follow my saviour. Thank you!
Miles

Related

GCC compiler cannot compile Hello World program [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am trying to compile the default Hello World on Code Blocks with the GNU GCC compiler but am getting the result of
cannot find -lbgi
It would be really helpful because right now I can't do a single thing!
Earlier I tried to use graphics.h and downloaded libbgi.a and I thought that was the problem so I deleted it. However, the compiler still produced the same error for the Hello World program, as well as previous programs that I made with C. From these information I guess that the problem is in the compiler but I cannot figure out what is causing it.
//c++ hello world program
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
//c hello world program
#include <stdio.h>
#include <stdlib.h>
int main(){
printf("Hello world!\n");
return 0;
}
I expect Hello World to be the output.
however:
||=== Build: Debug in firstCppProject (compiler: GNU GCC Compiler) ===|
ld.exe||cannot find -lbgi|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
You need to create a Console application (steps).
Currently you seem to be using a project created using a template with settings for Borland-compatible graphics (using a port of the old Turbo C++ "graphics" libraries), but you have deleted the libraries required to make that work.
Alternatively, you could remove the dependency on BGI from your project's linker settings.

C++ Codeblocks + libcurl ends up with link errors

Hi I am a C++ beginner and I wanted to learn about http requests...
I picked cURL because I have experience using it before with php.
I downloaded this version from cURL website into C:\libs
Win64 x86_64 7zip 7.51.0 binary SSL SSH Viktor Szakáts 1.81 MB
This is what I've done so far on Codeblocks:
Under Global compiler settings/Search directories/Compiler, I added this path:
C:\libs\curl-7.51.0-win64-mingw\include\curl
Under Global compiler settings/Search directories/Linker, I added this path:
C:\libs\curl-7.51.0-win64-mingw\lib
Under Global compiler settings/Linker settings, I added this paths:
C:\libs\curl-7.51.0-win64-mingw\lib\libcurl.a
C:\libs\curl-7.51.0-win64-mingw\lib\libcurldll.a
-Under Global compiler settings/compiler settings, this box is checked from before:
Have g++ follow the C++11 standard... (no idea if this matters or not...)
Also, because I was desperate I copied the contents of C:\libs\curl-7.51.0-win64-mingw to C:\Program Files (x86)\CodeBlocks\MinGW, this step makes no sense to me, but I found it online so I tried...
Now I am running this code:
#include <cstring>
#include <string>
#include <iostream>
#include <stdio.h>
#include <curl.h>
#include <easy.h>
using namespace std;
int main(){
CURL* curl = curl_easy_init();
if(!curl){
cout << "error" << endl;
}else{
cout << "good job!" << endl;
curl_easy_cleanup(curl);
}
};
I am getting this errors:
undefined reference to `_imp__curl_easy_init'
undefined reference to `_imp__curl_easy_cleanup'
error: ld returned 1 exit status
Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s))
For some reason, including include curl/curl.h does not work, only way it works is including curl.h, same for easy.h
Any advice appreciated!
Thanks in advance!
You're linking with a static libcurl (on Windows) without having -DCURL_STATICLIB added to your CFLAGS when you build your application.
That is, you must define CURL_STATICLIB before the curl headers are included.
Described in the curl FAQ item Link errors when building libcurl on Windows

How to run c++ program in codeblocks?

i write a simple progrum in c++ and run using codeblocks(13:12). My code looks like -
#include <iostream>
using namespace std;
int main(){
cout << "hello" << end1;
return 0;
}
but it's don't build. it gives me an error message .
s Mine\c++ pro. . . 1 fetal error: No such file or directory
Why i am getting this issue ? Why the iostram file don't found . Whats the wrong with it and how to solve it ?
I am not sure about the error you wrote, but I think that your compiler might not be installed. I suggest you to unistall CodeBlocks and re-download the installer from http://www.codeblocks.org/downloads/26 that has the compiler already installed: codeblocks-16.01mingw-setup.exe from the link.
Good luck, pal!
EDIT 1: The script is fine, don't worry about it.
EDIT 2: Oops, I now see that you have a fault in your code. It's endl, not end1!

Trying to set up the GNU C++ COMPILER, but I get an error I don't understand when I try to compile hello.cpp

So I bought this book called C++ Programming In Easy Steps by Mike McGrath online.
In the instructions it specifies to create a source file written in C++, the infamous "helo world". So I created my cpp file through sublime text editor and moved it to a file called MyPrograms in my C directory.
The code is as follows:
#include <iostream>
using std::cout;
using std::endl;
int main()
{
cout << "hello world"<< endl ;
return 0 ;
}
I have also tried:
#include
using namespace std;
int main()
{
cout << "hello world"<< endl ;
return 0 ;
}
Ok so I saved this file as hello.cpp in C:\MyPrograms.
Then here is where the error occurs....
I open cmd.
I do "c++"
I receive the message "c++: no input files".Which is what I'm supposed to recieve according to the book.
I proceed to do "cd\myprograms" to enter into the MyPrograms directory.
Once in that directory I do "c++ hello.cpp". According to the book this is supposed to compile my source file and create an executable file next to it. Instead I get a long error message that end in collect 2: 1d returned 1 exit status.
When I visit MyPrograms no executable file has been made next to the original cpp file.
I have also tried to do "c++ hello.cpp -o hello.exe" but it gives me the error again. All of this is done on the command prompt.
Please help :(
It looks to me like MinGW isn't installed properly.
First, it looks like you are trying to use version 4.0.3 but it may be conflicting with a version 3.4.5 that you installed previously (one in c:\mingw and the other in e:\p\giaw\src\pkg).
The latest version of MinGW is 4.7.2.1 which you can install from here: http://www.mingw.org/wiki/InstallationHOWTOforMinGW
But it looks like you're just starting out and it may be better to work with something that's better optimized for Windows (unless you're trying to compile Free Software). You can get a copy of Visual Studio Express for free here:
http://www.visualstudio.com/downloads/download-visual-studio-vs#d-express-windows-desktop
There are older versions available as well if you scroll down (VSE 2010).

Xcode 3.2.1 and C++ string fails!

In Xcode 3.2.1 on Mac OS X Snow Leopard, I open a project under:
Command Line Tool of type C++ stdc++.
I have the following simple code:
#include <iostream>
#include <string>
using namespace std;
int main(){
string myvar;
cout << "Enter something: " << endl;
cin >> myvar;
cout << endl << myvar << endl;
return 0;
}
The program compiles fine, and prompts me to "Enter Something". When I type in something, and then press enter, I get the following error:
myproject(766) malloc: *** error for object 0x1000041c0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Program received signal: “SIGABRT”.
sharedlibrary apply-load-rules all
(gdb)
When compiling on an earlier version of Xcode (3.1.2) on a different computer (opened the project with the 'command line utility' option, which does not exist in 3.2.1), the code runs with NO PROBLEM.
Does anybody know what's going on?
Thanks,
Yuval
As far as I can tell, I'm not experiencing this issue in Release mode for x86_64. But I am seeing the issue in Debug x86_64. If I follow the directions given by Howard in this post, I'm able to get it running in debug mode:
Project -> Edit Active Target ...
Click Build tab
Search for "preprocessor"
Delete _GLIBCXX_DEBUG=1 _GLIBCXX_DEBUG_PEDANTIC=1
Build and run, you'll notice it works. Another interesting observation is that using __gnu_debug::string (from the <debug/string> header) alone does not trigger the error.
EDIT: from the horses mouth (known issues in XCode 3.2.1)
The default gcc 4.2 compiler is not compatible with the Standard C++ Library Debug Mode. C++ programs compiled with Xcode 3.2 may not work in the Debug configuration. To fix this, set the Compiler Version to 4.0, or edit the Debug configuration’s Preprocessor Macros and remove the entries:
_GLIBCXX_DEBUG=1 _GLIBCXX_DEBUG_PEDANTIC=1
You can do this for all projects by navigating to /Developer/Library/Xcode/Project Templates/Application/Command Line Tool/C++ Tool/C++Tool.xcodeproj/ and editing project.pbxproj and deleting the lines around line 138:
"_GLIBCXX_DEBUG=1",
"_GLIBCXX_DEBUG_PEDANTIC=1",
An easier way of accomplishing the same thing: paste these lines at the very beginning of your program (before any #include statements):
#define _GLIBCXX_FULLY_DYNAMIC_STRING 1
#undef _GLIBCXX_DEBUG
#undef _GLIBCXX_DEBUG_PEDANTIC
Obviously, this will only affect the current project.