Reputation: 792
UPDATE I switched to the meson build system. Everything is working fine now!
I am very new to using C++, OpenGl, and Gnome Builder. I have a very very basic foundation with C++ and I know how to link header files and libraries in CodeLite, however after messing around Gnome Builder I want to make the switch. I haven't found any beginner friendly tutorials on using Builder. I am just lost as to how I should link external libraries in Builder. Do I just manually edit the Makefile or is there a setting somewhere that will automate the makefile process with automake? Am I wrong in assuming that this is a makefile problem? Apologies if this is a very novice question.
I am using Ubuntu. I am getting the error "undefined reference to ..." for all the glfw and glew variables and headers. After installing libraries with apt, I have my libraries installed in usr/lib/x86-64-linux-gnu, headers in usr/include.
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
int main ()
{
glewExperimental = true;
if (!glfwInit() )
{
fprintf(stderr, "Failed to initialize GLFW \n");
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window;
window = glfwCreateWindow(1024, 768, "Tutorial 01", NULL, NULL);
if ( window == NULL )
{
fprintf(stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. \n");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = true;
if (glewInit() != GLEW_OK)
{
fprintf(stderr, "Failed to Initialize GLEW. \n");
return -1;
}
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
do {
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
while ( glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0);
return 0;
}
When trying to build I get this error output~
g++ -o practice -Wall -ggdb -fno-omit-frame-pointer -O2 practice.cpp /usr/bin/ld: /tmp/ccLx11Ky.o: in function
main': /home/joe/Projects/practice/practice.cpp:30: undefined reference to
glewExperimental' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:31: undefined reference toglfwInit' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:36: undefined reference to
glfwWindowHint' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:37: undefined reference toglfwWindowHint' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:38: undefined reference to
glfwWindowHint' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:39: undefined reference toglfwWindowHint' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:40: undefined reference to
glfwWindowHint' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:43: undefined reference toglfwCreateWindow' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:50: undefined reference to
glfwMakeContextCurrent' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:51: undefined reference toglewExperimental' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:52: undefined reference to
glewInit' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:58: undefined reference toglfwSetInputMode' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:65: undefined reference to
glfwWindowShouldClose' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:61: undefined reference toglClear' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:62: undefined reference to
glfwSwapBuffers' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:63: undefined reference toglfwPollEvents' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:65: undefined reference to
glfwGetKey' /usr/bin/ld: /home/joe/Projects/practice/practice.cpp:47: undefined reference to `glfwTerminate' collect2: error: ld returned 1 exit status make: *** [Makefile:8: practice] Error 1
My default Makefile looks as follows~
all: practice
WARNINGS = -Wall
DEBUG = -ggdb -fno-omit-frame-pointer
OPTIMIZE = -O2
practice: Makefile practice.cpp
$(CXX) -o $@ $(WARNINGS) $(DEBUG) $(OPTIMIZE) practice.cpp
clean:
rm -f practice
# Builder will call this to install the application before running.
install:
echo "Installing is not supported"
# Builder uses this target to run your application.
run:
./practice
Upvotes: 0
Views: 1122
Reputation: 14493
You need to customize the build command (practice) to include the required libraries. Conside using pkg-config --libs glew
(or pkg-config --libs -static glew
) to find which libraries are needed, and pkg-config --cflags
for command line flags, if any.
Most likely:
See glfw Errors with glfwWindowHint, and GLEW Linker Errors (undefined reference to `__glewBindVertexArray')
Upvotes: 0