How do I link with GLU? - opengl

I've just discovered FLTK and I made a makefile for my test. Here is my makefile:
################ template makefile ##############
# We don't know what compiler to use to build fltk on this machine - but fltk-config does...
CC  = $(shell fltk-config --cc)
CXX = $(shell fltk-config --cxx)
# Set the flags for compiler: fltk-config knows the basic settings, then we can add our own...
CFLAGS   = $(shell fltk-config --cflags)
CXXFLAGS = $(shell fltk-config --cxxflags) -I/System/Library/Frameworks/OpenGL.framework/Versions/A/
# We don't know what libraries to link with: fltk-config does...
LINKFLTK = $(shell fltk-config --ldstaticflags)
LINKFLTK_GL = $(shell fltk-config --use-gl --ldstaticflags) -lGLU
LINKFLTK_IMG = $(shell fltk-config --use-images --ldstaticflags)
# Possible steps to run after linking...
STRIP      = strip
POSTBUILD  = fltk-config --post # Required on OSX, does nothing on other platforms, so safe to call
TARGET = CompletedFile
# Define what your target application is called
all: $(TARGET)
# Define how to build the various object files... -snip-
# Now define how to link the final app - let's assume it needs image and OpenGL support
$(TARGET): MyWindow.o main.o
$(CXX) -o $# MyWindow.o main.o $(LINKFLTK_IMG) $(LINKFLTK_GL)
$(STRIP) $#
$(POSTBUILD) $#  # only required on OSX, but call it anyway for portability
############### end #################
(Heres the object file code:)main.o: main.cpp MyWindow.h main.h
$(CXX) -c $< \
$(CXXFLAGS)
MyWindow.o: MyWindow.cpp MyWindow.h
$(CXX) -c $< \
$(CXXFLAGS)
Here is the error it gives me:
In file included from MyWindow.cpp:10:
MyWindow.h:14:20: error: GL/glu.h: No such file or directory
MyWindow.cpp: In member function ‘virtual void MyWindow::draw()’:
MyWindow.cpp:49: error: ‘gluPerspective’ was not declared in this scope
make: * [MyWindow.o] Error 1
(The code is irrelevant)

Depending on the fltk version you are using it has some of it's own openGL headers. I add the following lines to my include libraries:
-lfltk -lfltk_gl -lGL -lGLU
Overkill but it gets the job done.

The compiler can't find your GLU.h header. Adjust your #include or -I switch to point to the right location.

Related

Makefile unable to link libraries during runtime

So I am using nvidia's deepstream sdk and trying to modify the makefile of one of the sample examples given as I wish to link and add my own libraries. This is the makefile being employed where I am setting the path of the CUSTOM_LIB to point to the location of my library. The issue is the project gets compiled successfully but during run time, its unable to find the custom library. I performed ldd on the executable generated and there also it was showing the library as 'not found'. I think it's something to do with rpath but I am not sure about that.
APP:= sample
TARGET_DEVICE = $(shell gcc -dumpmachine | cut -f1 -d -)
NVDS_VERSION:=4.0
LIB_INSTALL_DIR?=/opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/lib/
ifeq ($(TARGET_DEVICE),aarch64)
CFLAGS:= -DPLATFORM_TEGRA
endif
CUDA_VER:=10.0
CC:=g++
SRCS:= $(wildcard ../src/*.c)
#SRCS+= $(wildcard ../../apps-common/src/*.c)
#SRCS+=
INCS:= $(wildcard ../include/*.h)
PKGS:= gstreamer-1.0 gstreamer-video-1.0 x11 opencv
OBJS:= $(SRCS:.c=.o)
CFLAGS+= -I../include -I/usr/include -I$(CUSTOM_LIB)/include -I/usr/local/cuda-10.0/targets/aarch64-linux/include/ -I/usr/include/jsoncpp -DDS_VERSION_MINOR=0 -DDS_VERSION_MAJOR=4 -fpermissive -Wnarrowing
LIBS+= -L$(LIB_INSTALL_DIR) -L/usr/lib/aarch64-linux-gnu -L$(CUSTOM_LIB)/lib -L/usr/lib/aarch64-linux-gnu/ -lcurl -letlic -letolm -lssl -lcrypto -llogger -lpthread -lsqlite3 -ljsoncpp -lnvdsgst_meta -lnvbufsurface -lnvbufsurftransform -lnvds_meta -lnvdsgst_helper -lnvds_utils -lm -L/usr/local/cuda-$(CUDA_VER)/lib64/ -lcudart \
-lgstrtspserver-1.0 -Wl,-rpath,$(LIB_INSTALL_DIR)
CFLAGS+= `pkg-config --cflags $(PKGS)`
LIBS+= `pkg-config --libs $(PKGS)`
all: $(APP)
debug: CXXFLAGS += -DDEBUG -g
debug: CFLAGS += -DDEBUG -g
debug: $(APP)
%.o: %.c $(INCS) Makefile
$(CC) -c -o $# $(CFLAGS) $<
$(APP): $(OBJS) Makefile
$(CC) -o $(APP) $(OBJS) $(LIBS)
clean:
rm -rf $(OBJS) $(APP)
You need to set rpath to a colon-separated list of directories where your libraries are found. You only add LIB_INSTALL_DIR but not CUSTOM_LIB_DIR. Generally everything you pass to -L you need to pass to -rpath too, unless there is a specific reason not to. For example, if you are building a package that has more than a single library and you are going to install in a standard place like /usr/lib, you don't have to add the directory where libraries temporarily live to -rpath. If you are going to install to a non-standard directory, add that directory.

How to modify library in makefile

I have a makefile that I need to modify to include the path to libraries.I am trying to run program given to me by someone else. I'm really confused on how the makefile works and don't understand what the previous lines are.
These are the directions given to me to modify the makefile:
Change the lines:
INCS = -I"../../LIB/libpca/include"
LIBS = -L"../../LIB/libpca/build" -lpca -larmadillo
in the Makefile to represent the folder where you installed the libpca and armadillo libraries.
Now I now what my new paths are:
Desktop/PCA-CD/Libraries
but I don't understand what is is that I really need to change.
Here is what the makefile looks like:
PROG = CD
UNAME := $(shell uname)
ifeq ($(UNAME), Darwin)
CXX = clang++ -stdlib=libc++
else
CXX = g++
endif
FLAGS = -O0 -g3 -Wall -std=c++0x -pthread
INCS = -I"../../LIB/libpca/include"
LIBS = -L"../../LIB/libpca/build" -lpca -larmadillo
SRCS = CD.cpp
RM = rm -f
all :
$(CXX) $(FLAGS) $(INCS) $(SRCS) $(LIBS) -o $(PROG)
# $(CXX) $(FLAGS) $(SRCS) -o $(PROG)
clean :
$(RM) $(PROG)
Thanks for any help provided.
I think they're suggesting to change the line:
INCS = -I"../../LIB/libpca/include"
LIBS = -L"../../LIB/libpca/build" -lpca -larmadillo
to
INCS = -I"Desktop/PCA-CD/Libraries/include"
LIBS = -L"Desktop/PCA-CD/Libraries/build" -lpca -larmadillo
Notice that Desktop/PCA-CD/Libraries is a relative path, and assumes that the library is stored in the subdirectory of the build directory. From your build directory, try running ls Desktop/PCA-CD/Libraries/build, to confirm it is right path. If it's not, replace it with the absolute path of the directory where you installed the library.

Getting Eclipse to read includes from makefile

I have a makefile which compiles my code just fine when running make.
If a create a makefile project in eclipse and import my already existing makefile it is possible to build the project.
But Eclipse does not resolve names, as it cannot find my include files. Is there a way where Eclipse automatically can read include paths from the makefile?
My makefile looks like this
# Put your stlink folder here so make burn will work.
STLINK=~/Programs/stlink
# Put your source files here (or *.c, etc)
SRCS=main.c system_stm32f4xx.c ../src/*.c
# Binaries will be generated with this name (.elf, .bin, .hex, etc)
PROJ_NAME=blinky
# Put your STM32F4 library code directory here
STM_COMMON=../STM32F4-Discovery_FW_V1.1.0
# Normally you shouldn't need to change anything below this line!
#######################################################################################
CC=arm-none-eabi-gcc
OBJCOPY=arm-none-eabi-objcopy
CFLAGS = -g -O2 -Wall -Tstm32_flash.ld
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
CFLAGS += -I.
# Include files from STM libraries
CFLAGS += -I$(STM_COMMON)/Utilities/STM32F4-Discovery
CFLAGS += -I$(STM_COMMON)/Libraries/CMSIS/Include -I$(STM_COMMON)/Libraries/CMSIS/ST/STM32F4xx/Include
CFLAGS += -I$(STM_COMMON)/Libraries/STM32F4xx_StdPeriph_Driver/inc
CFLAGS += -I ../include/
# add startup file to build
SRCS += $(STM_COMMON)/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/TrueSTUDIO/startup_stm32f4xx.s
OBJS = $(SRCS:.c=.o)
.PHONY: proj
all: proj
proj: $(PROJ_NAME).elf
$(PROJ_NAME).elf: $(SRCS)
$(CC) $(CFLAGS) $^ -o $#
$(OBJCOPY) -O ihex $(PROJ_NAME).elf $(PROJ_NAME).hex
$(OBJCOPY) -O binary $(PROJ_NAME).elf $(PROJ_NAME).bin
clean:
rm -f *.o $(PROJ_NAME).elf $(PROJ_NAME).hex $(PROJ_NAME).bin
# Flash the STM32F4
burn: proj
$(STLINK)/st-flash write $(PROJ_NAME).bin 0x8000000

makefile not finding header file from -I include path

I have the makefile given below. When I do make I get the following error
cc -c -o timing.o timing.c
test_c.c:5:17: fatal error: test.h: No such file or directory
#include "test.h"
I have manually verfied that test.h is present in ../include path. I am not sure why this is not finding the header file.It would be great if someone could help.Also I would expect g++ instead of cc
# Makefile template for shared library
CXX = g++ # C++ compiler
CXXFLAGS = -fPIC -Wall -Wextra -O2 -g -I../include #CXX flags
LDFLAGS = -lboost_system -shared # linking flags
RM = rm -f # rm command
TARGET_LIB = libtest.a # target lib
C_SRCS := test_a.c test_b.c
CPP_SRCS := test_c.cpp test_d.cpp
OBJS := $(C_SRCS:.c=.o) $(CPP_SRCS:.cpp=.o)
.PHONY: all
all: ${TARGET_LIB}
$(TARGET_LIB): $(OBJS)
$(CXX) $(CXXFLAGS) ${LDFLAGS} -o $# $^
.PHONY: clean
clean:
-${RM} ${TARGET_LIB} ${OBJS}
~
You have not written a rule for building timing.o from timing.c, so Make uses the default rule it has for that.
But that rule uses CFLAGS, not CXXFLAGS. The CXXFLAGS variable appears in the rule for building object files from C++ sources.
So modify CFLAGS instead of CXXFLAGS, and it should work.

make not searching in include path

I'm working through an OpenGL tutorial (OpenGL SuperBible 5) and I'm trying to get the supplied Makefile to work for my own program. I'm trying to get make to access a header file GLTools.h in my /home/ben/lib/GLTools/include/ directory and I'm including it in my Makefile with -I/home/ben/lib/GLTools/include/ (actually I'm using -I$(SHAREDINCPATH)) but make complains that there is no such file. Here is my Makefile (I've explicitly mentioned where I have edited the original Makefile):
MAIN = Triangle
SRCPATH = ./ # Edited: src is in CWD
SHAREDPATH = /home/ben/lib/GLTools/src/ # Edited to copied GLTools/src dir
SHAREDINCPATH = /home/ben/lib/GLTools/include/ # Edited to copied dir
LIBDIRS = -L/usr/X11R6/lib -L/usr/X11R6/lib64 -L/usr/local/lib
INCDIRS = -I/usr/include -I/usr/local/include -I/usr/include/GL -I$(SHAREDINCPATH) -I$(SHAREDINCPATH)GL
CC = g++
CFLAGS = $(COMPILERFLAGS) -g $(INCDIRS)
LIBS = -lX11 -lglut -lGL -lGLU -lm
prog : $(MAIN)
$(MAIN).o : $(SRCPATH)$(MAIN).cpp
glew.o : $(SHAREDPATH)glew.c
GLTools.o : $(SHAREDPATH)GLTools.cpp
GLBatch.o : $(SHAREDPATH)GLBatch.cpp
GLTriangleBatch.o : $(SHAREDPATH)GLTriangleBatch.cpp
GLShaderManager.o : $(SHAREDPATH)GLShaderManager.cpp
math3d.o : $(SHAREDPATH)math3d.cpp
$(MAIN) : $(MAIN).o glew.o
$(CC) $(CFLAGS) -o $(MAIN) $(LIBDIRS) $(SRCPATH)$(MAIN).cpp $(SHAREDPATH)glew.c $(SHAREDPATH)GLTools.cpp $(SHAREDPATH)GLBatch.cpp $(SHAREDPATH)GLTriangleBatch.cpp $(SHAREDPATH)GLShaderManager.cpp $(SHAREDPATH)math3d.cpp $(LIBS)
clean:
rm -f *.o
...and here is the make complaint:
ben#crunchbang:~/Code/C++/OpenGL/SuperBible5/SB5/Listings$ make
g++ -c -o Triangle.o Triangle.cpp
Triangle.cpp:4:50: fatal error: GLTools.h: No such file or directory
compilation terminated.
make: *** [Triangle.o] Error 1
As a sanity check I'm printing out the location of GLTools.h:
ben#crunchbang:~/Code/C++/OpenGL/SuperBible5/SB5/Listings$ ls /home/ben/lib/GLTools/include/
GL GLFrame.h GLMatrixStack.h GLTriangleBatch.h
GLBatchBase.h GLFrustum.h GLShaderManager.h math3d.h
GLBatch.h GLGeometryTransform.h GLTools.h StopWatch.h
Any idea why I cannot compile? I am pointing right at the GLTools.h with INCDIRS, right?
Also, I cannot find a declaration of COMPILERFLAGS anywhere in the makefile -- is this system-defined?
for g++ you need to define in your makefile
CXXFLAGS = $(COMPILERFLAGS) -g $(INCDIRS)
And since you use both C files and C++ files then define both in your makefile:
CFLAGS = $(COMPILERFLAGS) -g $(INCDIRS)
CXXFLAGS = $(COMPILERFLAGS) -g $(INCDIRS)
CFLAGS is used by make when it compiles C files, CXXFLAGS is used when make compiles C++ files. See http://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
CFLAGS
Extra flags to give to the C compiler.
CXXFLAGS
Extra flags to give to the C++ compiler.