Setting up programming environment
Hi everyone!
Im making a simple game application using C++ and openGL for my uni. Im trying to get a proper working environment at home and problems come up as i do this. Some of them i have managed to sort out but others appear. Now I am at the stage where I have installed eclipse, a compiler and downloaded glew and glut libraries. I believe i have liked them to eclipse as well but not 100% sure. Well, I need someone whos relevant to guide me or tell me exactly what i need from scratch to start developing using OpenGL. "Hello World" compiles and runs so im on the right path. The other thing is that when i include glut and glew in my code, it used to underline them as it did not recognise them but now that's sorted as well. The underlining is gone (im guessing i did the linking right) but it won't compile because of this one error. 13:01:28 **** Incremental Build of configuration Debug for project second project **** make all Building target: second project Invoking: Cross G++ Linker g++ -o "second project" ./src/second\ project.o -l/usr/include/GL /bin/ld: cannot find -l/usr/include/GL collect2: error: ld returned 1 exit status make: *** [second project] Error 1 13:01:29 Build Finished (took 434ms) Please I need help with this as I can't start working on the project. If I made this post in the wrong forum, someone let me know asap! Cheers! |
Hi,
which distribution are you using? and how did you install your programming-environment? Markus |
Not sure how the compiler commandline was composed for your environment, but the part '-l/usr/include/GL' looks wrong. It should probably be in two different parts; maybe just one.
Code:
g++ -o "second project" ./src/second\ project.o -lGL -L/usr/include For the gory details on compiler options: Code:
man gcc |
I used terminal for everything. I installed eclipse, gcc and GL libraries (glew and glut).
I'm using fedora by the way. So if i get this right, I have to locate the libraries and move them to a different folder(?). $ locate libGL.so /usr/lib64/libGL.so /usr/lib64/libGL.so.1 /usr/lib64/libGL.so.1.2 I don't understand what I am to do with those. *I installed eclipse 2 times. The first time using add/remove software application but installed the java version by accident (or it must have been the only eclipse i was seeing on the screen). So I had to install the c++ version and so I did using terminal this time. I followed a simple guide on how to get it. Now i have 2 versions of eclipse, one (the first installation) that i can just run from the applications and the other (2nd installation c++) which is placed in /opt and doesnt come up in the applications screen. I can only run it from the folder. Don't know if any of this is relevant but I thought of mentioning just in case. |
No, you don't move them. You just use the appropriate compiler arguments to point to them. The '-l' (minus ell) argument tells the compiler/linker the name of a library to link. The '-L' argument tells the compiler/linker the name of a directory to add to its standard list of places to look for libraries.
BTW, when your compiler/Makefile says 'Cross G++ Linker', does that imply that you are building code for a non-native target architecture? Or does the word 'Cross' have some other meaning here? If you are doing cross development, that adds several levels of complexity. For cross development, you will need a full cross toolchain, as well as libraries for your target architecture. Usually, that means building those libraries, and installing them on the target host. If you are struggling with the basics like this, then you are really up against it, and have a lot of learning ahead. I would completely forget about using Eclipse in such an environment, as it will only add complexity that you don't need right now. --- rod. |
Could you explain to me in simple words why am i encountering these errors? Is it a matter of missplacing libs or linking failure?
Cheers |
I have already spelled it out as simply as I can make it. In order to link with a particular library, the linker needs to be told to do so. This is done with the '-l' linker option. In your case, the library is libGL, so your compiler option would be '-lGL'. In order for the linker to know where the specified library lives in your filesystem, it has to be told, unless it is in one of the compilers standard places to look for libraries. The way you tell the linker where to look for libraries is with the '-L' option, which takes as an argument, the name of a filesystem directory. In your case, the directory of interest seems to be /usr/lib64, so your commandline argument to the linker also needs '-L /usr/lib64'.
There is nothing I can do to break it down any further than this. If something about this doesn't make sense, please tell me what it is. --- rod. |
Hi again and thanks for replying. I understand what needs to be done but I don't know how to achieve this.
Ok so this is what i need to use gcc [-Idir...] [-Ldir...] right ? the dir for -L would be /usr/lib64. What about the -l ? Is it possible to give me a complete command line for it ? |
I cannot give you a complete compiler commandline with knowing all of the files you are trying to compile &/or create. Please read what I have written; I've already answered the question of compiler access to libraries:
Code:
-lGL -L /usr/lib64 |
Ok basicaly I was trying to link the libs into eclipse without using the terminal.
I am getting my head around the problem finally. There's only 1 source file that is to be compiled so far. This is what i got: Code:
$ gcc -lGL second.cpp -L /usr/lib64 |
As I said before, if you don't already know what you're doing, using Eclipse just adds weight. Start out from first priniciples where you will learn what all of the Eclipse settings and configuration questions actually mean.
For your present problem, it looks like you need to add another library. Perhaps 'libglut'? Add it to the same commandline as you did for libGL. If the library is in the same directory as libGL, then adding another '-L' option is not necessary. --- rod. |
Ok I get this...
Code:
# rpm -i freeglut-2.8.0-3.fc17.x86_64.rpm Code:
gcc -lGL second.cpp -L /usr/lib64 Any ideas ? The thing that confuses me the most is that while on eclipse, I went on project properties > C/C++ build > Settings and added /usr/include/GL (not /usr/lib64) to the libraries. After doing that, the underlining was gone (meaning it started to recognise the gl code). Anyway i will not bother with it for now, just pointing it out in case it helps to make sence. |
You installed a package that we assume has a library containing the undefined references. Now you have to link to the library. First, you have to find it, so you can tell the linker where it is, just like you did for the first (libGL) library. You also have to tell the linker to use it, just like you did for the first library. I will assume the library is called libglut.so I don't know where it got installed; you will have to figure that out and modify the following accordingly.
Code:
gcc second.cpp -L /usr/lib64 -L /wherever/libglut.so/is -lGL -lglut --- rod. |
Code:
su - |
I already have freeglut-devel to it's latest update.
Ok I think I am on the right path! This is what i get now: Code:
[kirba@kirba ~]$ locate libglut.so Is it OK to have my libs here /usr/lib64/ ? Also here is the code the code so far. Code:
#include <stdlib.h> |
All times are GMT -5. The time now is 08:46 PM. |