GCC compiler cannot compile Hello World program [closed] - c++

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.

Related

Undefined reference when using "Hello world" of Irrlicht library [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'm trying to compile the very first code given by Irrlicht library website.
As said in the title, I get an undefined reference. I'm using 8.2 netbeans IDE.
This is what I've done so far :
Installed Irrlicht library from the Linux repository (I'm using Ubuntu 18.04).
Using these command lines : sudo apt-get install libirrlicht1.8 libirrlicht1.8-dbg libirrlicht-dev libirrlicht-doc
In the "project properties", I've added the include directory, as well as the include headers (e.g all the files contained in /usr/include/irrlicht. Also, in the "Additional Options" (the linker part, I guess ?) , I've seen online that I should add -lIrrlicht command line, and it still got me the undefined reference.
I've tried also the following command line : -L /usr/include/irrlicht -lIrrlicht, still got me the undefined reference.
I know that the compiler finds the library, as it does not make a compilation error saying that it doesn't know "irrlicht.h", so the problem is coming from the linker. What command line does the linker expects ?
Note : I'm not able to make any update. Talking about irrlicht, it seems that I have 363 packages outdated. Could the problem be from there ?
Edit : Here is the minimum code, as requested. There is no point showing it, as the error comes from the linker command line :
#include <cstdlib>
#include <iostream>
#include <irrlicht.h>
using namespace std;
using namespace irr;
using namespace core;
int main(int argc, char** argv) {
IrrlichtDevice *device=createDevice(video::EDT_SOFTWARE,dimension2d<u32>(640,480),16,false,false,false,0);
return 0;
}
I had a similar problem with another library. I fixed it by changing the path in the linker?
according to https://de.wikibooks.org/wiki/Irrlicht_-_from_Noob_to_Pro:_C%2B%2B_f%C3%BCr_Irrlicht_einrichten
you have to link lIrrlicht like:
LIBS += -L/.../Irrlicht/irrlicht-1.7.1/lib/Linux
LIBS += -lIrrlicht
instead of -L /usr/include/irrlicht -lIrrlicht (for unix).
Did you try that?

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

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

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

Visual Studio 2013 Professional linker errors [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I really want to use Visual Studio Professional's debugger to take a look at a segmentation fault I encountered in my program. However, the IDE would not compile even a simple program such as this:
// test_aug.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Test" ;
return 0;
}
It keeps throwing the error "error LNK1104: cannot open file 'gdi32.lib'.
The thing is I don't want to fix this one linking error just to keep getting more for different libraries (I have also seen it for different libraries).
Can someone please tell me how to fix this error in general so I will not encounter it anymore, and can move on to ACTUALLY DEBUGGING.
If the linker cannot find that library check for its existence and/or set the path to find it into additional library directories.
The linking phase won't go on without solving that error first.
Other two thoughts:
gd123.lib sounds wrong, I believe you wanted to use gdi32.lib. Make sure the name is right
make sure that is included into the Windows SDK (express editions don't include it)

Linking g++ with opengl (glm, glew and freeglut) [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 4 years ago.
Improve this question
This is the c++ code I want to run on my computer: http://pastebin.com/66BEyTWK
On the university computer, this code displays a white square. But when I try to run it on my computer all I get is a blank screen.
I read on the opengl faq that the problem might be that I am linking with the wrong combination of opengl libraries.
The include part of the code suggests that I need to link glm, glew and freeglut.
#include <iostream>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <glm/glm.hpp>
I read that it is not necessary to link glm, because it is only a header file. So this is the compile statement I came up with:
g++ -o main white_square.cpp -lGL -lglut -lGLEW
At my university they have setup a custom makefile which I can't get much sense out of: http://pastebin.com/3DxST3Xs