I am trying to set up OpenGL on Eclipse C++. I have followed the steps described in the answer of [1], but, when I do that it appears the following:
Building target: opengltest
Invoking: MacOS X C++ Linker
g++ -L/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib -L/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries -framework GLUT -framework OpenGL -framework Cocoa -arch i686 -o "opengltest" ./main.o -lgl -lglu -lglut
ld: library not found for -lglut
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [opengltest] Error 1
I have also changed the include line to:
#include <GLUT/glut.h>
Why is this error appearing?
[1] OpenGL and GLUT in Eclipse on OS X
You followed a tutorial aimed at Linux/BSD developers. In MacOS X you neither use the X11 server not link directly to the OpenGL interface libraries. In MacOS you merely add the OpenGL framework (add -framework OpenGL to the compiler command options). I'm not an active Eclipse user, but I'm pretty sure, it recognized MacOS X frameworks and you can just add the OpenGL framework to it.
GLUT is not part of OpenGL it's an independent library, but it used to be part of the MacOS X OpenGL framework for some time. Recently it was moved into a separate framework.
To add further speed bumps, Apple decided, that they'd put the OpenGL header files not into the canonical place GL/…, but into OpenGL/… so that you'll have to litter your program source text with #ifdef preprocessor statements
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
Related
I am using Qt 5.6 with Qt Creator 4.3 on macOS Sierra 10.12.
I am building a Qt based application that uses OpenGL and OpenCL.
Software or system updates somewhere appear to have broken Qt Creators' ability to find the headers for OpenGL and OpenCL headers.
I have tried reinstalling Qt, Reinstalling Xcode and the Mac SDK and none of these options make it work.
The weird thing is my app compiles. QtCreator just cannot find the headers itself - this makes code navigation somewhat more complex.
So lets take OpenCL. I include it like this:
#ifdef __APPLE__
#include <OpenCL/cl.h>
#include <OpenCL/opencl.h>
#endif
My app.pro file for qmake has the following inside it:
macx:QMAKE_LFLAGS += -framework OpenCL
And with this it seems to compile. However the two OpenCL #include above in QtCreator are yellow underlined with a tooltip saying "OpenCL/cl.h: No such file or directory".
Now I can see that it compiles successfully as qmake is working out where the frameworks are and appending the paths successfully:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -std=gnu++11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.7 -Wall -W -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/Users/me/Projects/app -I. -I/Users/me/Qt5.6.2/5.6/clang_64/lib/QtWidgets.framework/Headers -I/Users/me/Qt5.6.2/5.6/clang_64/lib/QtGui.framework/Headers -I/Users/me/Qt5.6.2/5.6/clang_64/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I/Users/me/Qt5.6.2/5.6/clang_64/mkspecs/macx-clang -F/Users/me/Qt5.6.2/5.6/clang_64/lib -o main.o /Users/me/Projects/app/main.cpp
Now if I navigate to the following directory the headers are there and present:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenCL.framework/Versions/A
So I cannot see what is missing.
I have tried to "teach" Qt Creator about this framework directory with combinations of the following, but I havent found something that will work:
macx:QMAKE_LFLAGS += -framework OpenCL
macx:INCLUDEPATH += /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenCL.framework/Versions/A/Headers
macx:QMAKE_LFLAGS += -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
macx:LIBS += -framework OpenCL
I'm struggling to find information about how QtCreator find the system frameworks on a mac and how i get it to start finding them again. Any help would be massively appreciated.
For anybody that has the same problem the answer was actually rather simple in the end.
When you setup the kit in Qt creator (which tells it what compiler and debugger to use amongst other things) you need to be careful with the compiler used. I had two copies of clang on my machine, one was installed in /usr/bin (the system one) and the other was installed inside the XCode app bundle. My kit was using the Xcode installed one as thats where the libraries live. While this compiled just fine, Qt creator for some reason does not hook up the paths to libraries properly. Simply switching this over to using the one in /usr/bin solved it.
Note that i did not explicitly ask it to use the one in the Xcode app bundle, thats just the one that was automatically selected when the project was first opened in Qt creator. So you might have to adjust its default behaviour in order to fix things.
This is my first question on stackoverflow. I've seen a few posts related to openGL on Ubuntu, but none seem to relate to the problem I'm having.
For some reason whenever I try to build my project in eclipse-CDT I get the following console output:
**** Build of configuration Debug for project windows ****
make all
Building file: ../src/windows.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/windows.d" -MT"src/windows.d" -o "src/windows.o" "../src/windows.cpp"
Finished building: ../src/windows.cpp
Building target: windows
Invoking: GCC C++ Linker
g++ -o "windows" ./src/OGdisplay.o ./src/windows.o -lGLEW -lGL -lSDL2
/usr/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status
makefile:45: recipe for target 'windows' failed
make: *** [windows] Error 1
**** Build Finished ****
I've installed the mesa-common-Dev package and all the others I could find that have to do with opengl development, but it won't budge. I put: GLEW, GL, and SDL2 in libraries under the GCC C++ linker settings. It doesn't seem to have any issues finding SDL2 and GLEW, but for some reason just can't find GL.
I went to usr/include and can clearly see the GL folder with it's contents as well as SDL2(which it has no issues finding). I've tried the same thing in codeblocks with extremely simple code and get the same result saying it can't find GL.
I'm running Ubuntu 16.04LTS with an nvidia GeForce GTX 1060. I'm also using the NVIDIA Xserver driver version 367.44. Under the nvidia Xserver settings in the OpenGL information sections it says it has version: 4.5.0 NVIDIA 367.44 if that helps. If you need anymore information just let me know, I'm almost certain that it's something simple I'm not thinking of.
Here are my CDT linker settings if it'll let me post a pick:
linker settings screenshot
SOLUTION: I'm not sure it's much of a solution, but I reinstalled NVIDIA X server and it seems to be working fine now. Not sure what was orginally causing it though.
Recently I updated to XCode Version 8.0 (8A218a) on El Capitan (OS X 10.11 using Macports 2.3.4), and ever since, I have been getting the following link error when I try to compile my project inside Qt Creator.
/opt/local/bin/g++-mp-5 -headerpad_max_install_names -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.8 -Wl,-rpath,/Users/zero/builds/Qt5.7.0/5.7/clang_64/lib -o uniMR.app/Contents/MacOS/uniMR ALL_OBJECT_FILES_GO_HERE.o -F/Users/zero/builds/Qt5.7.0/5.7/clang_64/lib -L/opt/local/lib -L/usr/local/lib -funit-at-a-time -fopenmp -lmlpack -larmadillo -framework CoreFoundation -DNDEBUG -lpthread -lALL_ITK_LIBS_GO_HERE -framework QtOpenGL -framework QtWidgets -framework QtGui -framework QtCore -framework DiskArbitration -framework IOKit -framework QtXml -framework OpenGL -framework AGL
**ld: unexpected token: !tapi-tbd-v2 file '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd' for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [uniMR.app/Contents/MacOS/uniMR] Error 1**
I am compiling the main project with gcc 5.4 (not clang) inside QtCreator (Qt 5.7), and all my dependent libraries (ITK, BOOST, etc) are compiled using gcc 5.4 as well. I also recompiled all my dependent libraries after upgrading XCode, but that did not help either. I could find only one post that is related to the error I am seeing, but it doesnt seem useful:
https://trac.macports.org/ticket/51701
All was fine before I upgraded XCode. Now I am not sure how to fix the issue. I would appreciate any help on this. Thanks.
UPDATE:
This doesnt seem like a problem with any of the external libraries I am linking with. This is what I did. I created a new "QT widgets application" in QtCreator, and chose to compile with gcc5. I get the same error ld: unexpected token: !tapi-tbd-v2. If I switch to clang, then there is no error.
I had this "ld: unexpected token: !tapi-tbd-v2" error building an unrelated project and was able to solve it by editing the .tbd file for the framework that was giving the error.
For me that file was:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate.tbd
I simply removed the entire line "--- !tapi-tbd-v2" while building, and then put it back once finished.
had yesterday the same problem. I had XCode 7.3 and 8 on my system. Removing 7.3 and moving 8 into the apps location solved the problem.
I had the same problem. I used macport's GCC 6 as compiler and linker. It seems the GCC doesn't understand the new tbd format. In the MacOSX SDK path, there are now only these tbd text files which contain info about the real dylib libraries. So I just symlinked the real libraries to the SDK paths beside their tbd files. Then GCC can directly use the real libraries without parsing tbd files.
Here is a script for creating those symlinks:
https://gist.github.com/michalfapso/9abdbd5669bfdc4cd1a2179824d299e9
I had the same problem while compiling with opam.
The workaround was PATH=/usr/bin:$PATH, thus gcc will resolve to the default /usr/bin/gcc which is clang on macOS.
I can't seem to compile this program. I have other people in my class that are having no problem compiling this code. I'm using the same command to try to compile the program and installed the frameworks in the same directory as them. /Library/Frameworks. I also installed eclipse and followed the zamma.co.uk tutorial to setup sdl2 and that didn't work either. Here is the command i'm running when compiling
g++ -std=c++11 -o Gravity main.cpp Game.cpp Particle.cpp Point.cpp -I/Library/Frameworks/SDL2.framework/Headers -framework SDL2 -framework Cocoa
Note: I have tried both
#include <SDL.h>
and
#include <SDL2/SDL.h>
and neither work
The ld linker error you mention in your comments suggests you may need to pass the -F option or -L in case your features/library search path is not finding your SDL2 installation.
Your problem sounds similar to:
linker command failed, sdl
How do you include files in C++ from the /Library/Framework folder in MAC
I have been working on a pet project for a while, and I recently encountered a runtime symbol lookup error. As the error itself does not provide much information I have no idea how to solve it.
I am using Eclipse Mars.
I include the following headers:
#include <GL/glew.h> //glew-1.12.0
#include <GLFW/glfw3.h> //glfw-3.1.1
#include <iostream>
#include <fstream>
#include <algorithm>
#include <math.h>
My console output looks normal when I build the project.
12:05:00 **** Incremental Build of configuration Debug for project Game ****
make all
Building file: ../main.cpp
Invoking: Cross G++ Compiler
g++ -I/usr/include/libdrm -I/usr/local/include -O0 -g3 -Wall -c - fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp
Building target: Game
Invoking: Cross G++ Linker
g++ -L/usr/local/lib -o "Game" ./main.o -lGL -lGLEW -lGLU -lglfw3 -lX11 -lXcursor -lXi -lXinerama -lXrandr -lXxf86vm -lpthread
Finished building target: Game
12:05:01 Build Finished (took 567ms)
But when I try to run it I get the following error:
/home/lokko/git/buum/Game/Debug/Game: symbol lookup error:/home/lokko/git/buum/Game/Debug/Game: undefined symbol: __glewClipControl
I am a hobbyist programmer and everithing I know I have learned myself so it would be nice if the anwser was as clear as possible about what I need to do to get this to work. The specific function causing the problem is
glClipControl(GLenum origin,GLenum depth);
Edit:
I am running opengl 4.5 on Nvidia 840m and using proprietary Nvidia drivers. (349)
Solution:
So everything started to work after I the last Ubuntu update. Dont know what it was. The last update before that was less than 24 hours ago. I wouldnt consider this an actual solution and I will post when this issue returns.
The problem you're running into is, that OpenGL has to classes of symbols: OS ABI defined symbols, which are symbols and functionality which is asserted to be available for any OpenGL implementation running on the system (for Windows this is OpenGL-1.1, for Linux LSB4 OpenGL-1.2 and with the recently released LSB5 it's OpenGL-2.1).
Anything that's outside of those asserted to be available ABIs may be not available and must be first tested for presence, then loaded at runtime through the OpenGL extension mechanism. This covers core OpenGL versions higher than what's specified in the ABI, but also vendor specific extensions. In your case glClipControl is a function that got introduced with OpenGL-4.5 (which at the time of writing this is the highest OpenGL version around).
So for this function to be available you need a fairly recent GPU (well, everthing built by AMD and NVidia after 2012 should do the trick) and you need the latest drivers for that GPU.
That error is telling you, that the function you'd like to use is not supported by either your GPU or the OpenGL implementation you have.
Now in case of a run-of-the-mill Linux you're likely using the Mesa drivers (which go only up to OpenGL-3.x so far; OpenGL-4.x support will be there eventually) or a rather outdated vendor proprietary driver that's not OpenGL-4.5 capable.
Solution:
Check that your GPU is not made by Intel (there are only Mesa drivers for Intel GPUs)
Check that your GPU actually supports OpenGL-4.5
Download the latest proprietary drivers for that GPU and install those