Simple Makefile problem - makefile

I'm trying to compile a project that uses 2 .cc files and a .h
I'm writing a Makefile but it's not compiling, I get an error:
make
g++ -I/usr/local/include/ -I/usr/local/include/libfreenect -I. -I/usr/include/GL -fPIC -g -Wall `pkg-config --cflags opencv` -L/usr/X11R6/lib -L/usr/lib -L/lib simple_gesture.cc -o simple_gesture `pkg-config --libs opencv` -L/usr/local/lib -lfreenect -lglui -lglut -lGLU -lGL
simple_gesture.cc: In function ‘void depth_cb(freenect_device*, void*, uint32_t)’:
simple_gesture.cc:315: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘clock_t’
simple_gesture.cc:315: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’
/tmp/cck2APvc.o: In function `depth_cb(_freenect_device*, void*, unsigned int)':
/home/dany/ToCompile/kinect-apps-playground-fingertip-detection/simple_gesture.cc:313: undefined reference to `FeatureExtractor::Process(unsigned char*, int const*, int)'
collect2: ld returned 1 exit status
make: *** [simple_gesture] Error 1
The Makefile is this:
all: simple_gesture
CFLAGS=-fPIC -g -Wall `pkg-config --cflags opencv`
LIBS = `pkg-config --libs opencv`
INCLUDE = -I/usr/local/include/ -I/usr/local/include/libfreenect -I. -I/usr/include/GL
FREE_LIBS = -L/usr/local/lib -lfreenect
GL_LIBS = -lglui -lglut -lGLU -lGL
GL_FLAGS = -L/usr/X11R6/lib -L/usr/lib -L/lib
feature_extractor: feature_extractor.h feature_extractor.cc
$(CXX) $(INCLUDE) $(CFLAGS) $(GL_FLAGS) $? -o $# $(LIBS) $(FREE_LIBS) $(GL_LIBS)
simple_gesture: simple_gesture.cc
$(CXX) $(INCLUDE) $(CFLAGS) $(GL_FLAGS) $? -o $# $(LIBS) $(FREE_LIBS) $(GL_LIBS)
%.o: %.c
$(CXX) -c $(CFLAGS) $< -o $#
clean:
rm -rf *.o feature_extractor simple_gesture
I think I'm not linking well the files..
Any idea?
[edit]
solved
it was enough:
simple_gesture: feature_extractor.h feature_extractor.cc simple_gesture.cc
$(CXX) $(INCLUDE) $(CFLAGS) $(GL_FLAGS) $? -o $# $(LIBS) $(FREE_LIBS) $(GL_LIBS)

Apparently your simple_gesture.cc depends on some function from FeatureExtractor class. So you should consider linking feature_extractor.o into your simple_gesture.

You need to make the binaries depend on the presence of the object files, not on the source files. You already have a rule for turning the source into an object.
all: simple_gesture
LIBS = `pkg-config --libs opencv`
INCLUDE = -I/usr/local/include/ -I/usr/local/include/libfreenect -I. -I/usr/include/GL
FREE_LIBS = -L/usr/local/lib -lfreenect
GL_LIBS = -lglui -lglut -lGLU -lGL
GL_FLAGS = -L/usr/X11R6/lib -L/usr/lib -L/lib
CFLAGS=-fPIC -g -Wall `pkg-config --cflags opencv` $(INCLUDE)
feature_extractor: feature_extractor.o
$(CXX) $(GL_FLAGS) -o $# $(LIBS) $(FREE_LIBS) $(GL_LIBS) $<
simple_gesture: simple_gesture.o feature_extractor.o
$(CXX) $(GL_FLAGS) -o $# $(LIBS) $(FREE_LIBS) $(GL_LIBS) $<
%.o: %.cc
$(CXX) -c $(CFLAGS) -o $# $<
clean:
rm -rf *.o feature_extractor simple_gesture

Related

Undefined references for libusb library

I am trying to use GoogleTest to test a simple function, but as I run make in my build folder, the compiler throws Undefined Reference error messages at me for libusb library. I need to add libusb library in GTEST_SRCS_ part of the makefile but I get same error. I am new to unit testing so, I do not know what should I do? How to build gtest with libusb library?
Makefile
GTEST_DIR= /home/sahin/googletest/googletest
LIBUSB_DIR= /usr/include/libusb-1.0
USER_DIR=.
LIBS += -L/usr/lib -lusb-1.0 -L/usr/lib/x86_64-linux-gnu/libusb-1.0.so -L./
CPPFLAGS += -I$(GTEST_DIR)/include -I$(LIBUSB_DIR)
CXXFLAGS += -g -Wall -Wextra -pthread
OBJECTS = main.o test.o
TESTS = test
GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
$(GTEST_DIR)/include/gtest/internal/*.h
LIBUSB_HEADERS = $(LIBUSB_DIR)/*.h
all : $(TESTS)
clean :
rm -f $(TESTS) gtest.a gtest_main.a *.o
GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
gtest-all.o : $(GTEST_SRCS_)
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
$(GTEST_DIR)/src/gtest-all.cc
gtest_main.o : $(GTEST_SRCS_)
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
$(GTEST_DIR)/src/gtest_main.cc
gtest.a : gtest-all.o
$(AR) $(ARFLAGS) $# $^
gtest_main.a : gtest-all.o gtest_main.o
$(AR) $(ARFLAGS) $# $^
test.o : $(USER_DIR)/test.cpp $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/test.cpp
test : test.o gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $#

makefile for two compilers

I would like to make a single makefile for two compilers. I like the example Intel has in its oneAPI, see below. Basically, under each target rule, it has explicit compilation rules. But my makefile is like:
# compile old fortran files
$(BLD)/%.o: $(SRC)/%.for
$(FC) -c $(FFLAGS) -o $# $<
# compile new fortran files
$(BLD)/%.o: $(SRC)/%.f90
$(FC) -c $(FFLAGS) -o $# $<
# link everything
$(target): $(objects)
$(FC) -o $# $(FFLAGS) -I $(BLD) $^ $(LDFLAGS)
I saw that one way would be to change the $(FC) variable plus the flags to appropriate values in a target. The advantage of the Intel that one can very specifically change the additional switches so if for gfortran i have the line $(FC) -o $# $(FFLAGS) -I $(BLD) $^ $(LDFLAGS) what if I need this to look like $(FC) -o $# $(FFLAGS) -J $(BLD) $^ $(LDFLAGS) for ifort etc. Is there a way to make a rule within another rule so something that would look like:
GFORT_EXE = $(target).gfort
IFORT_EXE = $(target).ifort
#
gfort: $(GFORT_EXE)
ifort: $(IFORT_EXE)
$(GFORT_EXE):
$(BLD)/%.o: $(SRC)/%.for
$(FC) -c $(FFLAGS) -o $# $<
# compile new fortran files
$(BLD)/%.o: $(SRC)/%.f90
$(FC) -c $(FFLAGS) -o $# $<
# link everything
$(FC) -o $# $(FFLAGS) -I $(BLD) $^ $(LDFLAGS)
Or what is the best way to approach it if i need the command line to look different in principal for each compiler?
The intel makefile:
# Copyright Intel Corporation 2014
#
# To compile with the GNU* C/C++ compiler, creating an execution file with the
# extension ".gcc" for binary instrumentation, issue:
#
# > make
#
# To compile with the Intel(R) C++ Compiler for Linux*, creating an execution
# file with the extension ".icc":
#
# Source <path_to_compiler_bin>/compilervars.sh or iccvars.csh;
#
# > make icc
#
# To compile with the Intel(R) C++ Compiler for Linux* with Intel(R) MKL library
# creating an executionfile with the extension ".mkl":
#
# Source <path_to_compiler_bin>/compilervars.sh or iccvars.csh;
#
# > make mkl
#
# To compile with the Intel(R) C++ Compiler for Linux to cross compile for the
# Intel(R) Xeon Phi(TM) coprocessor, creating an execution file with the
# extension ".mic":
#
# Source <path_to_compiler_bin>/compilervars.sh intel64
#
# > make mic
#
# To compile them all, use the source line from the Intel MIC architecture
# option above, then type:
#
# > make all
SHELL = /bin/sh
PARAMODEL = -DUSE_THR # Default parallelism using pthreads/Win threads
#PARAMODEL = -DUSE_OMP -fopenmp # Use OpenMP for multithreading
GCC = gcc
ICC = icc
CFLAGS = -g -O3 -fno-asm
OPTFLAGS = -xSSE3
# OPTFLAGS = -xHost -fno-alias
# add -DALIGNED to the multiply.c and matrix.c
LDFLAGS = -lpthread -lm
GCFLAGS = $(CFLAGS) $(PARAMODEL)
ICFLAGS = $(CFLAGS) $(PARAMODEL)-DICC -debug inline-debug-info #-vec-report3 -qopt-report -qopt-report-phase=vec
MKFLAGS = $(CFLAGS) -DUSE_MKL -DICC -mkl -debug inline-debug-info
GCC_EXE = matrix.gcc
ICC_EXE = matrix.icc
MKL_EXE = matrix.mkl
srcdir = ../src
gcc: $(GCC_EXE)
icc: $(ICC_EXE)
mkl: $(MKL_EXE)
all: $(GCC_EXE) $(ICC_EXE) $(MKL_EXE)
OBJS = util.o thrmodel.o multiply.o matrix.o
matrix.gcc: $(srcdir)/matrix.c $(srcdir)/multiply.c $(srcdir)/multiply.h $(srcdir)/util.c $(srcdir)/thrmodel.c
$(GCC) $(GCFLAGS) -c $(srcdir)/util.c -D_LINUX
$(GCC) $(GCFLAGS) -c $(srcdir)/thrmodel.c -D_LINUX
$(GCC) $(GCFLAGS) -c $(srcdir)/multiply.c -D_LINUX
$(GCC) $(GCFLAGS) -c $(srcdir)/matrix.c -D_LINUX
$(GCC) $(GCFLAGS) -g $(OBJS) -o ../matrix $(LDFLAGS)
matrix.icc: $(srcdir)/matrix.c $(srcdir)/multiply.c $(srcdir)/multiply.h $(srcdir)/util.c $(srcdir)/thrmodel.c
$(ICC) $(ICFLAGS) -c $(srcdir)/util.c -D_LINUX
$(ICC) $(ICFLAGS) -c $(srcdir)/thrmodel.c -D_LINUX
$(ICC) $(ICFLAGS) $(OPTFLAGS) -c $(srcdir)/multiply.c -D_LINUX
$(ICC) $(ICFLAGS) $(OPTFLAGS) -c $(srcdir)/matrix.c -D_LINUX
$(ICC) $(ICFLAGS) $(OBJS) -o ../matrix $(LDFLAGS)
matrix.mkl: $(srcdir)/matrix.c $(srcdir)/multiply.c $(srcdir)/multiply.h $(srcdir)/util.c $(srcdir)/thrmodel.c
$(ICC) $(MKFLAGS) -c $(srcdir)/util.c -D_LINUX
$(ICC) $(MKFLAGS) -c $(srcdir)/thrmodel.c -D_LINUX
$(ICC) $(MKFLAGS) $(OPTFLAGS) -c $(srcdir)/multiply.c -D_LINUX
$(ICC) $(MKFLAGS) $(OPTFLAGS) -c $(srcdir)/matrix.c -D_LINUX
$(ICC) $(MKFLAGS) $(OBJS) -o ../matrix $(LDFLAGS)
clean:
#rm -rf $(OBJS) $(GCC_EXE) $(ICC_EXE) $(MKL_EXE)
# * Other names and brands may be claimed as the property of others.
No, you can't redefine a rule within a rule (and quite frankly, you wouldn't want to, as there's tons of sharp sticks with this sort of approach, which you would be guaranteed to trip over). I would suggest for something like this you do two separate output directories, and have the rules based on the output directory, as so:
objects := ...
FC_gfort := ...
FC_ifort := ...
$(BLD)/gfort/%.o: $(SRC)/%.for
$(FC_gfort) -c $(FFLAGS) -o $# $<
$(BLD)/gfort/%.o: $(SRC)/%.f90
$(FC_gfort) -c $(FFLAGS) -o $# $<
$(BLD)/ifort/%.o: $(SRC)/%.for
$(FC_ifort) -c $(FFLAGS) -o $# $<
$(BLD)/ifort/%.o: $(SRC)/%.f90
$(FC_gfort) -c $(FFLAGS) -o $# $<
# link everything
$(target).gfort: $(BLD)/gfort/$(objects)
$(FC_gfort) -o $# $(FFLAGS) -J $(BLD)/gfort $^ $(LDFLAGS)
$(target).ifort: $(BLD)/ifort/$(objects)
$(FC_ifort) -o $# $(FFLAGS) -I $(BLD)/ifort $^ $(LDFLAGS)
Now, if you have lots of rules, and this gets to repetitive, you can use a define and eval, as so instead:
LINK_FLAG_gfort:=-J
LINK_FLAG_ifort:=-I
define RULES_template =
$$(BLD)/$(1)/%.o: $$(SRC)/%.for
$$(FC_$(1)) -c $$(FFLAGS) -o $$# $$<
$$(BLD)/$(1)/%.o: $$(SRC)/%.f90
$$(FC_$(1)) -c $$(FFLAGS) -o $$# $$<
$$(target).$(1): $$(BLD)/$(1)/$$(objects)
$$(FC_$(1)) -o $$# $$(FFLAGS) $$(LINK_FLAG_$(1)) $$(BLD)/$(1) $^ $$(LDFLAGS)
endef
$(eval $(call RULES_template,ifort))
$(eval $(call RULES_template,gfort))
Note the double $$'s in here (but not in front of $(1)...)
Also, I mentioned sharp sticks with your original idea, where you override the rule -- say you build ifort, and then did a subsequent build of gfort, with no clean in between. The .o files would not be rebuilt, as the timestamps would be newer than the sources', but the linker would run and use the obsolete artifacts.
Hope this helps

GNU make linker input file unused because linking not done

I have some troubles with my make file. All the output files are generated, but linking is not possible. Therefore, I don't get the output executable. Where is my mistake?
Here is my recipe for the output file:
gcc main.o memory.o startup_msp432p401r_gcc.o system_msp432p401r.o interrupts_msp432p401r_gcc.o -Wall -Werror -g -O0 -std=c99 -DHOST -MM -Wl,-Map=c1m2.map -T msp432p401r.lds -o c1m2.out
And here is the whole makefile:
ifeq ($(PLATFORM),HOST)
CC = gcc
else
CC = arm-none-eabi-gcc
endif
# Architectures Specific Flags
LINKER_FILE = msp432p401r.lds
CPU = cortex-m4
ARCH = mthumb
SPECS = nosys.specs
# Compiler Flags and Defines
LD = arm-none-eabi-ld
ifeq ($(PLATFORM),MSP432)
CFLAGS = -Wall -Werror -g -O0 -std=c99 -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16 --specs=nosys.specs
LDFLAGS = -T msp432p401r.lds
else
CFLAGS = -Wall -Werror -g -O0 -std=c99 -DHOST
LDFLAGS = -Wl,-Map=$(TARGET).map -T msp432p401r.lds
endif
TARGET = c1m2
CPPFLAGS = -MM
OBJS = $(SOURCES:.c=.o)
%.o: %.c
$(CC) $< $(CFLAGS) $(CPPFLAGS) -o $#
.PHONY: build
build: all
.PHONY: all
all: $(TARGET).out
$(TARGET).out: $(OBJS)
$(CC) $(OBJS) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $#
.PHONY: clean
clean:
rm -f $(OBJS) $(TARGET).out $(TARGET).map
Thank you very much!

Not able to include a library in makefile

I am kind of new in the use of make.
I have a library written in C which is in the folder folder1
Where these files are there is also a makefile which is the following:
PREFIX ?= /usr/local
CC = gcc
AR = ar
CFLAGS = -std=gnu99 -fPIC -Wall -Wno-unused-parameter -Wno-unused-function -I. -O4
APRILTAG_SRCS := $(shell ls *.c common/*.c)
APRILTAG_HEADERS := $(shell ls *.h common/*.h /usr/include/flycapture/*.h)
APRILTAG_OBJS := $(APRILTAG_SRCS:%.c=%.o)
TARGETS := libapriltag.a libapriltag.so
.PHONY: all
all: $(TARGETS)
#$(MAKE) -C example all
.PHONY: install
install: libapriltag.so
#chmod +x install.sh
#./install.sh $(PREFIX)/lib libapriltag.so
#./install.sh $(PREFIX)/include/apriltag $(APRILTAG_HEADERS)
#sed 's:^prefix=$$:prefix=$(PREFIX):' < apriltag.pc.in > apriltag.pc
#./install.sh $(PREFIX)/lib/pkgconfig apriltag.pc
#rm apriltag.pc
#ldconfig
libapriltag.a: $(APRILTAG_OBJS)
#echo " [$#]"
#$(AR) -cq $# $(APRILTAG_OBJS)
libapriltag.so: $(APRILTAG_OBJS)
#echo " [$#]"
#$(CC) -fPIC -shared -o $# $^
%.o: %.c
#echo " $#"
#$(CC) -o $# -c $< $(CFLAGS)
.PHONY: clean
clean:
#rm -rf *.o common/*.o $(TARGETS)
#$(MAKE) -C example clean
Then, in the folder example I have some example which I can just run by giving the following command in the terminal:
./opencv_demo
or
./apriltag_demo
In this folder example I have another makefile which is the following:
CC = gcc
CXX = g++
CPPFLAGS = -I..
CFLAGS = -std=gnu99 -Wall -Wno-unused-parameter -Wno-unused-function -O4
CXXFLAGS = -Wall -O4
LDFLAGS = -Lusr/include/flycapture -lpthread -lm
INC_DIR = /usr/include/flycapture
TARGETS := apriltag_demo opencv_demo
.PHONY: all
all: apriltag_demo opencv_demo
apriltag_demo: apriltag_demo.o ../libapriltag.a
#echo " [$#]"
#$(CC) -o $# $^ $(LDFLAGS)
opencv_demo: opencv_demo.o ../libapriltag.a /usr/include/flycapture/Error.h
#echo " [$#]"
#$(CXX) -o $# $^ $(LDFLAGS) `pkg-config --libs opencv`
%.o: %.c
#echo " $#"
#$(CC) -o $# -c $< $(CFLAGS) $(CPPFLAGS)
%.o: %.cc
#echo " $#"
#$(CXX) -o $# -c $< $(CXXFLAGS) $(CPPFLAGS)
.PHONY: clean
clean:
#rm -rf *.o $(TARGETS)
If I do make in the folder1 I get the following error:
opencv_demo.o: In function `main':
opencv_demo.cc:(.text.startup+0x24e): undefined reference to `FlyCapture2::Error::Error()'
opencv_demo.cc:(.text.startup+0x2a7): undefined reference to `FlyCapture2::Error::~Error()'
opencv_demo.cc:(.text.startup+0x11a0): undefined reference to `FlyCapture2::Error::~Error()'
collect2: error: ld returned 1 exit status
make[1]: *** [opencv_demo] Error 1
make[1]: Leaving directory `/home/fschiano/Repositories/apriltag2/example'
make: *** [all] Error 2
If I am not wrong this error tells me that I did not include a library.
In the file opencv_demo.cc I did:
#include "flycapture/FlyCapture2.h"
#include "flycapture/Error.h"
using namespace FlyCapture2;
Headers which are in /usr/include/flycapture a folder which contains all the headers needed for what I need in the file opencv_demo.cc.
I don't know why it is not working, someone is able to help me?
I think I should write in the makefile where to search for the libraries but I don't know how.
I tried to write the following things in the makefile separately but they are not working :
LDFLAGS = -Lusr/include/flycapture -lpthread -lm
INC_DIR = /usr/include/flycapture
DEPS = $(INC_DIR)/Error.h

Unable to change compiler in Crypto++ GNUmakefile

I'm trying to compile cryptopp with gcc49 on FreeBSD 10.x, however no matter how I instruct the Makefile to compile with g++49/gcc49, my attempts are ignored and it always compiles with c++.
I can't see at the moment where the compiler is defined in Makefile.
What I tried:
ifeq ($(CXX),gcc) # for some reason CXX is gcc on cygwin 1.1.4
CXX = g++49
endif
So I'd like the almighty of someone here to instruct it to compile with gcc49 (or g++49?) instead. Thanks!
Makefile:
CXXFLAGS = -DNDEBUG -g -O2
#CXXFLAGS = -g
# -fPIC is supported. Please report any breakage of -fPIC as a bug.
# CXXFLAGS += -fPIC
# the following options reduce code size, but breaks link or makes link very slow on some systems
# CXXFLAGS += -ffunction-sections -fdata-sections
# LDFLAGS += -Wl,--gc-sections
ARFLAGS = -cr # ar needs the dash on OpenBSD
RANLIB = ranlib
CP = cp
MKDIR = mkdir
EGREP = egrep
UNAME = $(shell uname)
ISX86 = $(shell uname -m | $(EGREP) -c "i.86|x86|i86|amd64")
# Default prefix for make install
ifeq ($(PREFIX),)
PREFIX = ..
endif
ifeq ($(CXX),gcc) # for some reason CXX is gcc on cygwin 1.1.4
CXX = g++49
endif
ifeq ($(ISX86),1)
GCC42_OR_LATER = $(shell $(CXX) -v 2>&1 | $(EGREP) -c "^gcc version (4.[2-9]|[5-9])")
INTEL_COMPILER = $(shell $(CXX) --version 2>&1 | $(EGREP) -c "\(ICC\)")
ICC111_OR_LATER = $(shell $(CXX) --version 2>&1 | $(EGREP) -c "\(ICC\) ([2-9][0-9]|1[2-9]|11\.[1-9])")
IS_SUN_CC = $(shell $(CXX) -V 2>&1 | $(EGREP) -c "CC: Sun")
GAS210_OR_LATER = $(shell echo "" | $(AS) -v 2>&1 | $(EGREP) -c "GNU assembler version (2\.[1-9][0-9]|[3-9])")
GAS217_OR_LATER = $(shell echo "" | $(AS) -v 2>&1 | $(EGREP) -c "GNU assembler version (2\.1[7-9]|2\.[2-9]|[3-9])")
GAS219_OR_LATER = $(shell echo "" | $(AS) -v 2>&1 | $(EGREP) -c "GNU assembler version (2\.19|2\.[2-9]|[3-9])")
ISMINGW = $(shell $(CXX) --version 2>&1 | $(EGREP) -c "mingw")
ifneq ($(GCC42_OR_LATER),0)
ifeq ($(UNAME),Darwin)
CXXFLAGS += -arch x86_64 -arch i386
else
CXXFLAGS += -march=native
endif
endif
ifneq ($(INTEL_COMPILER),0)
CXXFLAGS += -wd68 -wd186 -wd279 -wd327
ifeq ($(ICC111_OR_LATER),0)
# "internal error: backend signals" occurs on some x86 inline assembly with ICC 9 and some x64 inline assembly with ICC 11.0
# if you want to use Crypto++'s assembly code with ICC, try enabling it on individual files
CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
endif
endif
ifeq ($(GAS210_OR_LATER),0) # .intel_syntax wasn't supported until GNU assembler 2.10
CXXFLAGS += -DCRYPTOPP_DISABLE_ASM
else
ifeq ($(GAS217_OR_LATER),0)
CXXFLAGS += -DCRYPTOPP_DISABLE_SSSE3
else
ifeq ($(GAS219_OR_LATER),0)
CXXFLAGS += -DCRYPTOPP_DISABLE_AESNI
endif
endif
ifeq ($(UNAME),SunOS)
CXXFLAGS += -Wa,--divide # allow use of "/" operator
endif
endif
ifeq ($(ISMINGW),1)
LDLIBS += -lws2_32
endif
endif # ISX86
ifeq ($(UNAME),) # for DJGPP, where uname doesn't exist
CXXFLAGS += -mbnu210
else
CXXFLAGS += -pipe
endif
ifeq ($(UNAME),Linux)
LDFLAGS += -pthread
ifneq ($(shell uname -i | $(EGREP) -c "(_64|d64)"),0)
M32OR64 = -m64
endif
endif
ifeq ($(UNAME),Darwin)
AR = libtool
ARFLAGS = -static -o
CXX = c++
IS_GCC2 = $(shell $(CXX) -v 2>&1 | $(EGREP) -c gcc-932)
ifeq ($(IS_GCC2),1)
CXXFLAGS += -fno-coalesce-templates -fno-coalesce-static-vtables
LDLIBS += -lstdc++
LDFLAGS += -flat_namespace -undefined suppress -m
endif
endif
ifeq ($(UNAME),SunOS)
LDLIBS += -lnsl -lsocket
M32OR64 = -m$(shell isainfo -b)
endif
ifneq ($(IS_SUN_CC),0) # override flags for CC Sun C++ compiler
CXXFLAGS = -DNDEBUG -O -g0 -native -template=no%extdef $(M32OR64)
LDFLAGS =
AR = $(CXX)
ARFLAGS = -xar -o
RANLIB = true
SUN_CC10_BUGGY = $(shell $(CXX) -V 2>&1 | $(EGREP) -c "CC: Sun .* 5\.10 .* (2009|2010/0[1-4])")
ifneq ($(SUN_CC10_BUGGY),0)
# -DCRYPTOPP_INCLUDE_VECTOR_CC is needed for Sun Studio 12u1 Sun C++ 5.10 SunOS_i386 128229-02 2009/09/21 and was fixed in May 2010
# remove it if you get "already had a body defined" errors in vector.cc
CXXFLAGS += -DCRYPTOPP_INCLUDE_VECTOR_CC
endif
endif
SRCS = $(wildcard *.cpp)
ifeq ($(SRCS),) # workaround wildcard function bug in GNU Make 3.77
SRCS = $(shell echo *.cpp)
endif
OBJS = $(SRCS:.cpp=.o)
# test.o needs to be after bench.o for cygwin 1.1.4 (possible ld bug?)
TESTOBJS = bench.o bench2.o test.o validat1.o validat2.o validat3.o adhoc.o datatest.o regtest.o fipsalgt.o dlltest.o
LIBOBJS = $(filter-out $(TESTOBJS),$(OBJS))
DLLSRCS = algebra.cpp algparam.cpp asn.cpp basecode.cpp cbcmac.cpp channels.cpp cryptlib.cpp des.cpp dessp.cpp dh.cpp dll.cpp dsa.cpp ec2n.cpp eccrypto.cpp ecp.cpp eprecomp.cpp files.cpp filters.cpp fips140.cpp fipstest.cpp gf2n.cpp gfpcrypt.cpp hex.cpp hmac.cpp integer.cpp iterhash.cpp misc.cpp modes.cpp modexppc.cpp mqueue.cpp nbtheory.cpp oaep.cpp osrng.cpp pch.cpp pkcspad.cpp pubkey.cpp queue.cpp randpool.cpp rdtables.cpp rijndael.cpp rng.cpp rsa.cpp sha.cpp simple.cpp skipjack.cpp strciphr.cpp trdlocal.cpp
DLLOBJS = $(DLLSRCS:.cpp=.export.o)
LIBIMPORTOBJS = $(LIBOBJS:.o=.import.o)
TESTIMPORTOBJS = $(TESTOBJS:.o=.import.o)
DLLTESTOBJS = dlltest.dllonly.o
all: cryptest.exe
test: cryptest.exe
./cryptest.exe v
clean:
$(RM) cryptest.exe libcryptopp.a $(LIBOBJS) $(TESTOBJS) cryptopp.dll libcryptopp.dll.a libcryptopp.import.a cryptest.import.exe dlltest.exe $(DLLOBJS) $(LIBIMPORTOBJS) $(TESTIMPORTOBJS) $(DLLTESTOBJS)
install:
$(MKDIR) -p $(PREFIX)/include/cryptopp $(PREFIX)/lib $(PREFIX)/bin
$(CP) *.h $(PREFIX)/include/cryptopp
$(CP) *.a $(PREFIX)/lib
$(CP) *.so $(PREFIX)/lib
$(CP) *.exe $(PREFIX)/bin
libcryptopp.a: $(LIBOBJS)
$(AR) $(ARFLAGS) $# $(LIBOBJS)
$(RANLIB) $#
libcryptopp.so: $(LIBOBJS)
$(CXX) -shared -o $# $(LIBOBJS)
cryptest.exe: libcryptopp.a $(TESTOBJS)
$(CXX) -o $# $(CXXFLAGS) $(TESTOBJS) -L. -lcryptopp $(LDFLAGS) $(LDLIBS)
nolib: $(OBJS) # makes it faster to test changes
$(CXX) -o ct $(CXXFLAGS) $(OBJS) $(LDFLAGS) $(LDLIBS)
dll: cryptest.import.exe dlltest.exe
cryptopp.dll: $(DLLOBJS)
$(CXX) -shared -o $# $(CXXFLAGS) $(DLLOBJS) $(LDFLAGS) $(LDLIBS) -Wl,--out-implib=libcryptopp.dll.a
libcryptopp.import.a: $(LIBIMPORTOBJS)
$(AR) $(ARFLAGS) $# $(LIBIMPORTOBJS)
$(RANLIB) $#
cryptest.import.exe: cryptopp.dll libcryptopp.import.a $(TESTIMPORTOBJS)
$(CXX) -o $# $(CXXFLAGS) $(TESTIMPORTOBJS) -L. -lcryptopp.dll -lcryptopp.import $(LDFLAGS) $(LDLIBS)
dlltest.exe: cryptopp.dll $(DLLTESTOBJS)
$(CXX) -o $# $(CXXFLAGS) $(DLLTESTOBJS) -L. -lcryptopp.dll $(LDFLAGS) $(LDLIBS)
adhoc.cpp: adhoc.cpp.proto
ifeq ($(wildcard adhoc.cpp),)
cp adhoc.cpp.proto adhoc.cpp
else
touch adhoc.cpp
endif
%.dllonly.o : %.cpp
$(CXX) $(CXXFLAGS) -DCRYPTOPP_DLL_ONLY -c $< -o $#
%.import.o : %.cpp
$(CXX) $(CXXFLAGS) -DCRYPTOPP_IMPORTS -c $< -o $#
%.export.o : %.cpp
$(CXX) $(CXXFLAGS) -DCRYPTOPP_EXPORTS -c $< -o $#
%.o : %.cpp
$(CXX) $(CXXFLAGS) -c $<
ifeq ($(CXX),gcc) # for some reason CXX is gcc on cygwin 1.1.4
CXX = g++49
endif
If I recall correctly, CXX is g++ or c++ on the BSDs, so you will never enter the ifeq block.
The easiest thing to do would probably be:
# GNUmakefile
CXXFLAGS = -DNDEBUG -g -O2 -fPIC
CXX=g++49
...
It looks like you are using Crypto++ 5.6.2 or less because of this line:
CXXFLAGS = -DNDEBUG -g -O2
5.6.3 and above works harder at honoring user's preferences. For example, in 5.6.3 GNUmakefile (which is being tested for release):
# Base CXXFLAGS used if the user did not specify them
CXXFLAGS ?= -DNDEBUG -g2 -O2
The next-easiest thing to do would be to grab the 5.6.3 GNUmakefile, and then peform the following (g++49 must be on-path):
export CXX=g++49
make
I can assure you that works on 5.6.3 because I made the changes to facilitate testing under different compilers. You can also tweak CXXFLAGS:
export CXX=/opt/intel/bin/icpc
export CXXFLAGS="-DNDEBUG -g2 -O3 -wd68 -wd186"
make
5.6.3 should be available in a couple of weeks. We are finishing up the mitigations for a Coverity scan/analysis. Once they are mitigated, we have to perform a final round or Release Testing.

Resources