openGL Porbleme mit Compiler
-
Hi !
Habe folgendes Anfängerprogramm geschrieben:
openGL.h#ifndef _OPENGL_H_ #define _OPENGL_H_ #include <stdlib.h> #include <GL/gl.h> #include <GL/glu.h> #include "SDL.h" using namespace std; class openGL { public: void quit(char* mesg); void initGL(); void resizeWindow( int width , int height ); void drawGLScene(); }; #endifopenGL.cpp
#include "openGl.h" #include <iostream> void openGL::quit(char* msg) { cout << msg; SDL_Quit(); exit( -1 ); } void openGL::initGL() { glShadeModel( GL_SMOOTH); glClearColor( 0.0f , 0.0f , 0.0f , 0.0f ); glClearDepth( 1.0f); glEnable( GL_DEPTH_TEST ); glDepthFunc( GL_LEQUAL); glHint( GL_PERSPECTIVE_CORRECTION_HINT , GL_NICEST ); } void openGL::resizeWindow( int width , int height ) { /* Height / width ration */ GLfloat ratio; /* Protect against a divide by zero */ if ( height == 0 ) height = 1; ratio = ( GLfloat )width / ( GLfloat )height; /* Setup our viewport. */ glViewport( 0, 0, ( GLint )width, ( GLint )height ); /* change to the projection matrix and set our viewing volume. */ glMatrixMode( GL_PROJECTION ); glLoadIdentity( ); /* Set our perspective */ gluPerspective( 45.0f, ratio, 0.1f, 100.0f ); /* Make sure we're chaning the model view and not the projection */ glMatrixMode( GL_MODELVIEW ); /* Reset The View */ glLoadIdentity( ); } void openGL::drawGLScene() { } int main( int argc , char** argv ) { }Beim Kompilieren erhalte ich folgende Fehlermeldung:
g++ -c -lGL -lGLU `sdl-config --cflags --libs` openGl.cpp -o openGL.o g++: -lGL: linker input file unused because linking not done g++: -lGLU: linker input file unused because linking not done g++: -rpath: linker input file unused because linking not done g++: /usr/lib: linker input file unused because linking not done g++: -lSDL: linker input file unused because linking not done g++: -lpthread: linker input file unused because linking not doneund schließlich:
g++ -lGL -lGLU `sdl-config --cflags --libs` openGl.cpp openGL.o -o openGL openGL.o(.text+0x0): In function `openGL::quit(char*)': : multiple definition of `openGL::quit(char*)' /tmp/ccxf37Se.o(.text+0x0): first defined here openGL.o(.text+0x28): In function `openGL::initGL()': : multiple definition of `openGL::initGL()' /tmp/ccxf37Se.o(.text+0x28): first defined here openGL.o(.text+0xac): In function `openGL::resizeWindow(int, int)': : multiple definition of `openGL::resizeWindow(int, int)' /tmp/ccxf37Se.o(.text+0xac): first defined here openGL.o(.text+0x13e): In function `openGL::drawGLScene()': : multiple definition of `openGL::drawGLScene()' /tmp/ccxf37Se.o(.text+0x13e): first defined here openGL.o(.text+0x144): In function `main': : multiple definition of `main' /tmp/ccxf37Se.o(.text+0x144): first defined here collect2: ld returned 1 exit statusLeider kann ich mit den Compilermeldungen nichts anfangen. Über einen Tip würde ich mich sehr freuen.
mfg
Tom
-
void quit(char* mesg); != void quit(char* msg);einfach die fehlermeldungen angucken - da kann man schon was rauslesen
-
#include "openGl.h"den namen der headerdatei solltest du ändern - auf einen win system könnte es damit probleme geben
-
tom07 schrieb:
Beim Kompilieren erhalte ich folgende Fehlermeldung:
g++ -c -lGL -lGLU `sdl-config --cflags --libs` openGl.cpp -o openGL.o g++: -lGL: linker input file unused because linking not done g++: -lGLU: linker input file unused because linking not done g++: -rpath: linker input file unused because linking not done g++: /usr/lib: linker input file unused because linking not done g++: -lSDL: linker input file unused because linking not done g++: -lpthread: linker input file unused because linking not donedie Meldungen kommen, weil du bereits beim kompilieren die Linkerflags angibst. Also --libs und -l...
und schließlich:[code]g++ -lGL -lGLU `sdl-config --cflags --libs` openGl.cpp openGL.o -o openGLhier kompilierst du die .cpp-Datei ein zweites mal und linkst die dann mit dem vorher erstellten object zusammen. Dadurch entstehen die Funktionen natürlich doppelt.
Vertexwahn schrieb:
void quit(char* mesg); != void quit(char* msg);nee, die beiden Prototypen sind absolut identisch.
-
DrGreenthumb schrieb:
nee, die beiden Prototypen sind absolut identisch.
ist das Standardkonform? darf ich einfach beliebige Bezeichner in Prototypen verwenden und dann später andere Bezeichner für die Parameter verwenden?
hat das irgendetwas mit function prototype scope und block scope zu tun?
-
Vertexwahn schrieb:
DrGreenthumb schrieb:
nee, die beiden Prototypen sind absolut identisch.
ist das Standardkonform? darf ich einfach beliebige Bezeichner in Prototypen verwenden und dann später andere Bezeichner für die Parameter verwenden?
ja, der eigentliche Prototyp ist nur void foo(char*); Das wäre auch eine gültige Deklaration.
-
MsVC 6.0 hat mich immer angemekert, wenn ich verschiedene namen für prototypen und definiton verwendet habe
-
Vertexwahn schrieb:
MsVC 6.0 hat mich immer angemekert, wenn ich verschiedene namen für prototypen und definiton verwendet habe
Jo. Ggf. nur als Warnung?!?
Naja, kann aber auch sein, daß _WENN_ Du einen Bezeichner angibst, diese auch identisch sein müssen.

-
zu den syntax schwierigkeiten habe ich ein neues thema aufgemacht - diese gehören ja nich hier her:
http://www.c-plusplus.net/forum/viewtopic-var-t-is-103336.html
-
Das heisst also , dass ich nicht linken muss. Zumindest funktioniert es jetzt.
tom
-
tom07 schrieb:
Das heisst also , dass ich nicht linken muss. Zumindest funktioniert es jetzt.
nee, das heißt, du guckst besser nochmal in die ersten Seiten deines C/C++ Buchs, wo beschrieben wird, wie man eigentlich kompiliert und linkt

-
DrGreenthumb schrieb:
tom07 schrieb:
Das heisst also , dass ich nicht linken muss. Zumindest funktioniert es jetzt.
nee, das heißt, du guckst besser nochmal in die ersten Seiten deines C/C++ Buchs, wo beschrieben wird, wie man eigentlich kompiliert und linkt

