4

I am using Mac Os X 10.9.5 fully updated with XCode version 6.0.1. I have also installed the command line utilities that have to be installed after installing XCode. I am using GLFW and GLEW in my openGL libraries. GLEW was installed manually while GLFW was installed with Macports.

I want to do coding without XCode as I have been doing it on Windows (with MingW) and Linux. I have googled how to compile the program and also searched on stackoverflow.

So, currently my compile command looks like this (This is a C++ program)

g++ -framework Cocoa -framework OpenGL -framework CoreFoundation -framework CoreVideo -framework IOKit -L/usr/lib -L/usr/local/lib -I/usr/include/GLFW -I/usr/local/include/GL main.cpp -o main

I keep on getting the following error:

Undefined symbols for architecture x86_64:
"_glfwCreateWindow", referenced from:
  _main in main-ba7a57.o
"_glfwInit", referenced from:
  _main in main-ba7a57.o
"_glfwMakeContextCurrent", referenced from:
  _main in main-ba7a57.o
"_glfwTerminate", referenced from:
  _main in main-ba7a57.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The program is:

#define GLEW_STATIC
#include <glew.h>
#include <glfw3.h>
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {

GLFWwindow* window;
if(!glfwInit()) exit(EXIT_FAILURE);
window = glfwCreateWindow(1024, 768, "glfw", NULL, NULL);
if(!window) {
    glfwTerminate();
    exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);

const GLubyte* version = glGetString(GL_VERSION);
cout << "OpenGL version: " << version << endl;
glfwTerminate();
return 0;
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
rathorsunpreet
  • 101
  • 1
  • 5
  • 1
    you're not linking to glfw libs, there're just new linking directories, but no libs. – oblitum Oct 21 '14 at 02:08
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Reto Koradi Oct 21 '14 at 02:28
  • The GLFW libs are told by using -L/usr/local/lib. All libs are specified by the -L. – rathorsunpreet Oct 22 '14 at 15:58

2 Answers2

0

It's only a guess, but try adding `-lglfw' to the end of your command-line. This tells g++ to compile against libglfw.

Tom
  • 7,269
  • 1
  • 42
  • 69
0

The fact that the error says Undefined symbols for architecture x86_64 makes me think perhaps the versions of the libraries you installed were built to target 64 bit architectures. Remember when choosing libraries to install that you should be choosing 32 bit or 64 bit versions based on which architectures you intend to target, not which architecture your development machine uses.

See this other question for reference.

Community
  • 1
  • 1
Baher Ramzy
  • 171
  • 6
  • Okay, but, then g++ can be told to use certain architecture while compiling. How do you do that? If you say -arch i386 or -arch x86_64, I have used it and still got the same error. – rathorsunpreet Oct 22 '14 at 15:58
  • @rathorsunpreet I meant the issue could be with the libraries you installed, not your own code. Re-install the GLFW and GLEW libraries making sure that you install the 32 bit versions. – Baher Ramzy Oct 22 '14 at 16:07