I'm using Linux OS and Eclipse. For some reason eclipse does not recognise some of the GLFW commands despite the fact that glfw3.h is included properly. I'm unable to use GLFWwindow, glfwCreateWindow and glfwDestoyWindow. Anyone know why?
Edit
Just to be specific my IDE is underlining these methods as if they are not defined.
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
using namespace std;
int main() {
if (!glfwInit()){
return 0;
}
GLFWwindow* window = glfwCreateWindow(680, 480, "test", NULL, NULL);
cin.get();
if (window){
glfwDestroyWindow(window);
}
glfwTerminate();
return 0;
}
If I remember correctly, the Eclipse editor in C/C++ mode uses the compiler to generate its symbol database, so unless you build the editor will not recognize new symbols.
So the solution is to actually build your project, even if the editor tells you there are errors.
Related
I have reinstalled windows for other reasons, and after setting up MinGWx64 (my portable compiler of choice), I had it working back again, EXCEPT for a little problem; I tried to compile an old project with OpenGL (using GLFW), and it did it with no exceptions nor errors; but then I tried to run the code, and I just couldn't. No errors, no waiting, nothing, just stopped instantly. So I made some tests, and long story short, it was GLEW. Basically, if you invoke any function from GLEW, the program just won't run, no matter the line from where it is called, but will previously compile without any issues (that have to be with the library I mean).
This is a short example of what that looks like:
#include <iostream>
#include <GL/gl.h>
int main() {
std::cout << "works\n";
glfwInit();
return 0;
};
This works, but now when I add a glew function (those some-variables would be values):
#include <iostream>
#include <GL/glew.h> //Included before (correctly)
#include <GL/gl.h>
int main() {
std::cout << "works\n";
glfwInit();
GLFWwindow* window = glfwCreateWindow((someresulution),(someresolution),(sometitle),NULL,NULL);
glfwMakeContextCurrent(window);
if (glewInit()!=GLEW_OK) std::cout << "glew not ok\n"; //HERE
return 0;
};
Again, it compiles just fine, but the program won't do anything (even tho the function call is below the "works" log, but neither it or "glew not ok" will be logged), just exit instantly.
This leads me to think it is something to be with the linking, maybe it not finding glew32.lib, but I have checked all files were in the right dirs like 4 times. The path's ok, vscode settings are ok (if that helps anyway), and I just can't figure it out, as it is the first time something like this happens to me. If there's anyone that knows about a solution or something about it, I would be pleased to have some help, any suggestions will be appreciated. Thanks.
Did you define GLEW_STATIC for static version or GLEW_BUILD for dll version in your program ?? I guess without defining those will create compilation errors in glew
I wanted to use the code blocks to draw circles. I downloaded BGI and put the files of the BGI in the correct places in the code blocks folder (and also changed the complier settings from codeblocks). However, when calling the initwindow from the main in the codeblocks, nothing happend (there isn't any window);
#include <iostream>
#include <graphics.h>
int main()
{
initwindow(900,900);
circle(90,90,90);
return 0;
}
Thanks in advance.
Recently I've been working on a project that uses SDL2 on Code::Blocks 10.03 on Debian. I need to load some PNG images and a font to write some things to screen. However, when I try to load the files, both IMG_load and TTF_OpenFont create a segmentation fault.
I am 100% sure the files are on the current path, as using incorrect filenames such as buckt.png instead of bucket.png result in both SDL_GetError and IMG_GetError returning "Couldn't open buckt.png", the same with TTF files; whereas if I use the correct filename, it causes the segfault. Interestingly enough, if I compile the project from the command line, using g++ main.cpp -std=c++11 -lSDL2 -lSDL2_image -lSDL2_ttf it compiles and runs perfectly, but since I'm forced to use Code::Blocks, the terminal is not an option
For showcase, this snippet is located on the topmost part of the main function. As you may have guessed, on Code::Blocks, it won't work.
#include <iostream>
#include <limits>
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
using namespace std;
int main( int argc, char* args[] ) {
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
TTF_Init();
// The segfault is caused here, using Code::Blocks
TTF_Font *gFont = TTF_OpenFont("LiberationMono-Bold.ttf",20);
if (gFont == NULL) {
// This is never reached
cout << "gFont is empty!" << endl;
}
TTF_Quit();
SDL_Quit();
}
And the execution working directory is set to ., which is the main folder for the Code::Blocks project, and also where the fonts and images are located.
If anyone has found a workaround to this situation, please let me know.
I'm relatively new to c++, so bear with a little.
I have a class with the constructor:
Window(int width, int height, const std::string& title);
As defined in the header file.
I then have the code:
#include "window.h"
int main(int argc, char** argv) {
new Window(800, 600, "Elysian Engine");
}
in Main.
When building, I am getting the error "undefined reference to 'Window(int, int, std::string const&)'" Which I do not understand, as I thought I am correctly importing it and everything. I understand this to be a linking error, but I'm not sure why.
Thanks!
--- EDIT ---
The code for window.cpp:
#include "window.h"
#include <SDL2/SDL.h>
#include <SDL/SDL.h>
#include <GL/glew.h>
Window::Window(int width, int height, const std::string& title) :
width(width),
height(height),
title(title),
isCloseRequested(false) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);
context = SDL_GL_CreateContext(window);
SDL_GL_SetSwapInterval(1);
GLenum res = glewInit();
if (res != GLEW_OK) {
fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
}
}
Window::~Window() {
SDL_GL_DeleteContext(context);
SDL_DestroyWindow(window);
SDL_Quit();
}
Because your code does not appear to be causing the issue, I will address the IDE.
When I first started using Code::Blocks, I ran into the "undefined reference" problem quite a bit. There are multiple ways that I solved this.
Exit Code::Blocks and re-open it. This solved my issues more times than I would care to count. It's similar to finally realizing that an executable is acting strangely because you needed to run make clean before compiling; sometimes, you are compiling an old version of code without realizing it.
Delete window.h and window.cpp from the project and re-add them. This is similar to the solution above. Although this has worked for me before, I couldn't figure out exactly why it worked.
Include the full path of window.h. Instead of #include "window.h", try #include "/path/goes/here/window.h". It is possible that your current location (as specified in your #include statement) is incorrect.
Check the compiler that is selected for the project. When I used Code::Blocks, I typically used gcc. However, there was a case where I was receiving all sorts of errors (upon attempting compilation) that I either did not understand or could not resolve, only to learn that I had accidentally selected some gcc variant from the compiler selection list that I did not even have installed.
Create a new project. Move your source files out of the project folder that is created by Code::Blocks, and then remove that project folder. Launch Code::Blocks, create a new project, and add your source files to the new project.
When all else fails and you absolutely must use Code::Blocks, reinstall the full package. I had to do this my first time using Code::Blocks (which was also my first time using an IDE). I realized that I had a bare-bones installation of the IDE, which was limiting what I could do (including compiling). Naturally, I cannot access the Code::Blocks website right now, otherwise I would offer a link here as well. In this case, I think it is safe to say that the full-featured stable version will be the largest (in MB) you can find on Code::Blocks' Downloads page. After you have reinstalled, create a new project and add your files back to it.
I eventually moved to using writing code in an IDE (for the linting!), and taking care of a makefile on my own. It has been awhile since I've used Code::Blocks, but each of the above bullets represents solutions/work-arounds that have helped me for your specific problem (or, in general) while I was using Code::Blocks.
Why BlockInput isn't working
#include <iostream>
#include <windows.h>
#include <winable.h>
int main() {
BlockInput(true);
Sleep(10000);
return 0;
}
and it simply doesn't block anything!
I can still do everything like I haven't even done that.what I also find weird is that MSDN sais that it should be declared in winuser.h and it is in Winable.h + I thought that winable.h is in windows.h but It's not, I had to include it seperatly >_>
If it helps my IDE is:
Code::Blocks 10.05 MinGW
EDIT: Actually I did the GetLastError() and it prints error 5 ERROR_ACCESS_DENIED
How may I get the access?
Run your code as an administrator. Right-click on the executable and click 'run as Administrator'.