Can't get openGL to link in ubuntu - c++

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.

Related

How can I fix my OpenGL build environment on OSX?

UPDATE
I've sorted this by explicitly adding the appropriate -I and -L options, but I'm curious as to why this is necessary now when it wasn't before? On the plus side those annoying library out-of-sync warnings are gone.
UPDATE ENDS
I've broken my OSX OpenGL build environment. I'm building from terminal (using make) with g++, for example:
g++ -o myprog main.o -lglfw -lglew -framework OpenGL
and getting errors:
ld: library not found for -lglfw clang: error: linker command failed with exit code 1 (use -v to see invocation)
These are in addition to compiler errors such as:
g++ -c main.cpp main.cpp:3:10: fatal error: 'GL/glew.h' file not found
So it seems the OpenGL libraries and includes have been lost. Everything was working fine until I executed the command:
export SDKROOT="$(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
Which I did to try and fix warning messages like:
ld: warning: text-based stub file /System/Library/Frameworks//OpenGL.framework/OpenGL.tbd and library file /System/Library/Frameworks//OpenGL.framework/OpenGL are out of sync. Falling back to library file for linking.
I got that 'fix' from here: macOS framework lib problem
I realise it was reckless running commands that I don't fully understand but nonetheless... now I can't compile/link any OpenGL code and after scouring the internet for help I've come up with nothing, so here I am.
I'm running OSX 10.13.6 on a 2013 MacBook Pro.
First post BTW so please forgive me if I've not provided enough detail.

how do I eliminate linker error mingw32/bin/ld.exe: cannot find -lSDL

I am trying to build SDL for use with Eclipse. I am trying to remove this linker error:
Beginning Compilation
21:15:53 **** Incremental Build of configuration Debug for project CMD ****
Info: Internal Builder is used for build
g++ "-IC:\\MinGW\\include\\SDL2" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\CMD.o" "..\\src\\CMD.cpp"
g++ -o CMD.exe "src\\CMD.o" -lmingw32 -lSDL -lSDL2main -lSDL2
ERROR(s):
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lSDL
collect2.exe: error: ld returned 1 exit status
21:15:54 Build Finished (took 1s.36ms)
The most pertinent SO archive source I researched didn't seem to have an actionable answer for my problem, though it had the exact same problem/error:
title --
producing the same error message:
c:/mingw/bin/../lib/gcc/mingw32/4.7.0/../../../../mingw32/bin/ld.exe: cannot find -lSDL.
If you click to the authors "solution" for the same error as mine its not clear to me how he solved it.
Any help?
Problem solved, SDL2 awesome. Ok:
c:/mingw/bin/../lib/gcc/mingw32/4.7.0/../../../../mingw32/bin/ld.exe: cannot find -lSDL.
Reinstallation of SDL2 avoiding binary conflict between SDL files and SDL2 files
as keltar mentioned resolved the immediate problem, and the problem built with no errors!Fixing what was in the braces unmasked new problem: crashing. I stripped the program to bare bones and concluded the crashing was outside of the code since it was occurring even without code.
To solve the new problem would need to go the SDL2 distribution file (the one copied to MinGW) and copy the SDL2.dll from it [DLL from distributable][1]--- by dragging the file over your debug and/or release folders where the .exe file lives.(.exe + dll -> right?) moving dll to exes. Build/Run the program
it should work!
You should see a Welcome message!
https://www.caveofprogramming.com/c-for-complete-beginners/setting-up-sdl-windows.html

Eclipse C++ on OSX Cant Build

I am new to coding and C++ and have just installed C++ and XCode on my computer. I have made Mac OSX GCC my preferred tool chain.
I can't seem to even get a simple Hello World program to run, I really need some help here, I've posted before and looked around but nothing seems to help me.
Code:
#include <iostream>
using namespace std;
int main() {
cout << "Hello world \n";
return 0;
}
Error after clicking on build all:
12:38:22 **** Incremental Build of configuration Debug for project Test1 ****
make all
Building file: ../test.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"test.d" -MT"test.o" -o "test.o" "../test.cpp"
Finished building: ../test.cpp
Building target: Test1
Invoking: MacOS X C++ Linker
g++ -o "Test1" ./test.o
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Test1] Error 1
12:38:37 Build Finished (took 15s.286ms)
You mentioned that you just installed XCode. If you are looking to get started with C++ programming, using XCode will make your experience more satisfying and learning curve faster than if you use Eclipse. XCode is a "native" IDE on Mac.
Having said this, I understand there may be reasons to use Eclipse, e.g. if you expect to start programming on non-Apple platforms in a very near future, or want to familiarize yourself with Eclipse as the IDE to do Android programming. However, if you are going to be on Mac for awhile and want to pick up C++ faster, I would strongly recommend sticking with XCode.
Now, the error you show could be because the file has not been saved, as suggested by one of the commenters. That's exactly the error you get if main() is missing.

How to solve a runtime symbol lookup error?

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

Clang/LLVM on Eclipse (Mac)

I am trying to run Eclipse with the Clang compiler without success. First I went here http://clang.llvm.org/get_started.html and followed the instructions 1 through 8 successfully. I also installed the llvm toolchain via Eclipse marketplace.
What do I do next to successfully compile with Clang? From the installation I have two folders, llvm and build, where do I put them? How do I connect this to Eclipse?
I also downloaded lld in case I needed it since the llvm-ld doesn't work anymore. Below is my error message. I'll be so grateful if someone can help me figure this out! I've wasted a lot of hours on this.
20:09:47 **** Incremental Build of configuration Debug for project recursion ****
Info: Internal Builder is used for build
clang -O0 -emit-llvm -g3 -Wall -c -fmessage-length=0 -o recursiveprint.bc ../recursiveprint.c
lld -v -native -o recursion recursiveprint.bc
Cannot run program "lld": Unknown reason
Error: Program "lld" not found in PATH
PATH=[/usr/bin:/bin:/usr/sbin:/sbin]
20:09:47 Build Finished (took 74ms)