Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › g++ compile and linking help
New Posts  All Forums:Forum Nav:

g++ compile and linking help

post #1 of 8
Thread Starter 
I'm using GCC to compile and link a few files. Some of the files require GL/glut.h.
I have freeglut installed and a test program that I used and it works for it. It has a Makefile though so that was easy. Anyone able to help me make a Makefile for my other program. I'm not sure how to make one and could not find any good tutorials online.

Makefile for test program:
Code:
SAMPLE = ogl_glut_sample

CC ?= gcc
COPTS ?= -g

LIBS = -L/usr/X11R6/lib -lGL -lGLU -lglut -lXi -lXmu -lXext -lX11 -lm

all : $(SAMPLE)

clean : 
    rm -f $(SAMPLE)

run : $(SAMPLE)
    ./$(SAMPLE)

$(SAMPLE) : $(SAMPLE).cpp
    $(CC) -o $@ $(COPTS) $< $(LIBS)
Thanks.
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
post #2 of 8
Hobo, asking for help? Dude, if you can't do it, it can't be done!
post #3 of 8
Quote:
Originally Posted by The Hundred Gunner View Post
Hobo, asking for help? Dude, if you can't do it, it can't be done!
That was really good for moral....
Lee XT
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD FX-6300 Asus M5A97 SAPPHIRE Radeon HD 7850 AMD 4GB DDR3 1333MHZ 
RAMRAMRAMHard Drive
AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ OCZ Vertex 4 256GB 
CoolingOSMonitorKeyboard
Corsair H80 Windows 8.1 Pro MCE Dell P2414H WHXV7  Microsoft Generic 
PowerCaseMouseMouse Pad
Ultra 600W Limited Edition NZXT Black Steel Razer Deathadder Razer Goliath 
Audio
Realtek HD Audio 
  hide details  
Reply
Lee XT
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD FX-6300 Asus M5A97 SAPPHIRE Radeon HD 7850 AMD 4GB DDR3 1333MHZ 
RAMRAMRAMHard Drive
AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ OCZ Vertex 4 256GB 
CoolingOSMonitorKeyboard
Corsair H80 Windows 8.1 Pro MCE Dell P2414H WHXV7  Microsoft Generic 
PowerCaseMouseMouse Pad
Ultra 600W Limited Edition NZXT Black Steel Razer Deathadder Razer Goliath 
Audio
Realtek HD Audio 
  hide details  
Reply
post #4 of 8
Quote:
Originally Posted by Licht View Post
That was really good for moral....
morale*

Couldn't help it. I'm a speling be.
post #5 of 8
Quote:
Originally Posted by The Hundred Gunner View Post
morale*

Couldn't help it. I'm a speling be.
Be, lol. Classic.
Lee XT
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD FX-6300 Asus M5A97 SAPPHIRE Radeon HD 7850 AMD 4GB DDR3 1333MHZ 
RAMRAMRAMHard Drive
AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ OCZ Vertex 4 256GB 
CoolingOSMonitorKeyboard
Corsair H80 Windows 8.1 Pro MCE Dell P2414H WHXV7  Microsoft Generic 
PowerCaseMouseMouse Pad
Ultra 600W Limited Edition NZXT Black Steel Razer Deathadder Razer Goliath 
Audio
Realtek HD Audio 
  hide details  
Reply
Lee XT
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD FX-6300 Asus M5A97 SAPPHIRE Radeon HD 7850 AMD 4GB DDR3 1333MHZ 
RAMRAMRAMHard Drive
AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ OCZ Vertex 4 256GB 
CoolingOSMonitorKeyboard
Corsair H80 Windows 8.1 Pro MCE Dell P2414H WHXV7  Microsoft Generic 
PowerCaseMouseMouse Pad
Ultra 600W Limited Edition NZXT Black Steel Razer Deathadder Razer Goliath 
Audio
Realtek HD Audio 
  hide details  
Reply
post #6 of 8
Quote:
Originally Posted by dangerousHobo View Post
I'm using GCC to compile and link a few files. Some of the files require GL/glut.h.
I have freeglut installed and a test program that I used and it works for it. It has a Makefile though so that was easy. Anyone able to help me make a Makefile for my other program. I'm not sure how to make one and could not find any good tutorials online.

Makefile for test program:
Code:
SAMPLE = ogl_glut_sample

CC ?= gcc
COPTS ?= -g

LIBS = -L/usr/X11R6/lib -lGL -lGLU -lglut -lXi -lXmu -lXext -lX11 -lm

all : $(SAMPLE)

clean : 
    rm -f $(SAMPLE)

run : $(SAMPLE)
    ./$(SAMPLE)

$(SAMPLE) : $(SAMPLE).cpp
    $(CC) -o $@ $(COPTS) $< $(LIBS)
Thanks.
What files do you need to compile and what do they depend on?
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #7 of 8
Thread Starter 
Camera.cpp
Camera.h
ColorCube.cpp
ColorCube.h
Figure.cpp
Figure.h
Floor.cpp
Floor.h
Pyramid.cpp
Pyramid.h
Scene.cpp
Scene.h
VisualObject.cpp
VisualObject.h
glutBase.cpp
glutBase.h


Its an openGL program that uses glut

so needs: glut.h and GL.h
think the link for them in gcc is: -lGL -lGLU -lglut
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
post #8 of 8
-lglut implies -lGL and -lGLU, so you only need -lglut.

if you have the headers in somewhere like /usr/include/GL/glut.h then you shouldn't have any problems with them.

If you are not familiar with makefiles, they are fairly simple:
Code:
target : dependencies
<tab>actions
When you run "make" without any target, it will make the first target in the Makefile by default.

So, if you can compile with
Code:
g++ -Wall -lglut -o main foo.cpp main.cpp
then you should be able to just use
Code:
main : main.cpp foo.cpp
g++ -Wall -lglut -o main foo.cpp main.cpp
Putting it in the variables you have at the top just makes it easier to change the links, compiler or whatever for all of the targets rather than having to do them individually. Start simple and then add in these variables where required.

Your headers should not appear in the makefile at all. They should all be "#include"d from the c/cpp files.
Serene Power
(13 items)
 
  
CPUMotherboardGraphicsRAM
Dual Xeon E5620 Supermicro X8DAL-i EVGA 570HD SC 8GiB Corsair DDR3 1333 ECC-R 
Hard DriveOptical DriveOSMonitor
OCZ Agility 3 120GB SSD (+16TB NAS) LG 10x Blu-Ray Windows 7 x64 / Debian x64 Dell 2408WFP, P2411H 
PowerCase
850W CoolerMaster SilentPro M CoolerMaster Cosmos Pure 
  hide details  
Reply
Serene Power
(13 items)
 
  
CPUMotherboardGraphicsRAM
Dual Xeon E5620 Supermicro X8DAL-i EVGA 570HD SC 8GiB Corsair DDR3 1333 ECC-R 
Hard DriveOptical DriveOSMonitor
OCZ Agility 3 120GB SSD (+16TB NAS) LG 10x Blu-Ray Windows 7 x64 / Debian x64 Dell 2408WFP, P2411H 
PowerCase
850W CoolerMaster SilentPro M CoolerMaster Cosmos Pure 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › g++ compile and linking help