howto compile cryptopp 5.6.2 with mingw - c++

I am trying to build cryptopp 5.6.1 with mingw 4.8.1 (sjlj). I've changed GNUMakefile from Crypto++ & MinGW
But there are several issue:
I've compile error if I try to build it as shared library;
On my machine it works (intel i5 (2nd generation) with Windows 7 ) but on Windows Xp on an Intel atom D2500 an error occured (no entry point for memmove_s in msvcrt.dll )
When I try to build as shared library I've the following error:
make dll
make: *** No rule to make target 'cryptopp.dll', needed by 'cryptest.import.exe'. Stop.
make libcryptopp.dll
// ...
g++ -std=c++11 -DNDEBUG -O3 -m32 -msse2 -msse3 -mssse3 -DCRYPTOPP_EXPORTS -c hex.cpp -o hex.export.o
g++ -std=c++11 -DNDEBUG -O3 -m32 -msse2 -msse3 -mssse3 -DCRYPTOPP_EXPORTS -c hmac.cpp -o hmac.export.o
g++ -std=c++11 -DNDEBUG -O3 -m32 -msse2 -msse3 -mssse3 -DCRYPTOPP_EXPORTS -c integer.cpp -o integer.export.o
g++ -std=c++11 -DNDEBUG -O3 -m32 -msse2 -msse3 -mssse3 -DCRYPTOPP_EXPORTS -c iterhash.cpp -o iterhash.export.o
g++ -std=c++11 -DNDEBUG -O3 -m32 -msse2 -msse3 -mssse3 -DCRYPTOPP_EXPORTS -c misc.cpp -o misc.export.o
g++ -std=c++11 -DNDEBUG -O3 -m32 -msse2 -msse3 -mssse3 -DCRYPTOPP_EXPORTS -c modes.cpp -o modes.export.o
make: *** No rule to make target 'modexppc.export.o', needed by 'libcryptopp.dll'. Stop.
Does someone has compiled succeful crypto++ with mingw 4.8.1? This is the snippet of my makefile:
CXXFLAGS = -std=c++11 -DNDEBUG -O3 -m32 -msse2 -msse3 -mssse3
ARFLAGS = rc
LDLIBS += -lws2_32
LDFLAGS =
MKDIR = mkdir
CP = copy
SRCS = $(wildcard *.cpp)
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
lib: libcryptopp.a
all: cryptest.exe
test: cryptest.exe
cryptest.exe v
install: lib
$(CP) *.h include\cryptopp
$(CP) *.a lib
clean:
del cryptest.exe libcryptopp.a $(LIBOBJS) $(TESTOBJS) cryptopp.dll libcryptopp.dll.a libcryptopp.import.a cryptest.import.exe dlltest.exe $(DLLOBJS) $(LIBIMPORTOBJS) $(TESTIMPORTOBJS) $(DLLTESTOBJS)
libcryptopp.a: $(LIBOBJS)
$(AR) $(ARFLAGS) $# $(LIBOBJS)
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
libcryptopp.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)
%.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 $<
Edit
To let it work I've forced the funcion memmove_s defined in misc.h (of cryptopp) to be defined inlined and now works also on windows xp (where memmove_s is not defined in msvcrt.dll).
Question: Can I change the mscvrt.dll of windows xp with one defined on Windows 7?

A way to build it is using qmake:
I removed GNUMakefile,
qmake -project
I open the pro file into QtCreator, changed TEMPLATE to lib and added ws2_32 to lib
The pro file now looks something this
TEMPLATE = lib
INCLUDEPATH += .
CONFIG -= qt
HEADERS += ...
SOURCES += ...
win32-g++ {
QMAKE_CXXFLAGS += -msse -msse2 -msse3 -mssse3
LIBS += -lws2_32
}
It seems work.

it's a try
put modexppc.cpp to your CRYPTOPP folder.
modexppc.cpp
// modexppc.cpp - written and placed in the public domain by Wei Dai
#include "pch.h"
#ifndef CRYPTOPP_IMPORTS
#include "modexppc.h"
#include "asn.h"
NAMESPACE_BEGIN(CryptoPP)
NAMESPACE_END
#endif

I sent a patch fixing memmove_s in Windows XP to the MinGW developer team. It's been accepted and it will soon appear in the newer MinGW builds. By now it should be available on the CentOS 7 MinGW distribution and Fedora 21 MinGW.
Crypto++ 5.6.2 now builds fine without modification on MinGW, using make (and setting CC, CXX and PATH environment variables correctly). Tested on CentOS 7, which uses MinGW 4.9 IIRC.

Related

Barrier file not found (C++ Makefile)

I am trying to compile a project however the make command returns with the error
fatal error: 'barrier' file not found
and after changing clang versions and changing my platform, nothing seems to help. Therefore I would like to ask for assistance regarding this issue.
Here is my makefile:
CC = clang
CXX = clang++
CFLAGS := $(CFLAGS) -g -O3 -Wall -Wextra -pedantic -Werror -std=c18 -pthread
CXXFLAGS := $(CXXFLAGS) -stdlib=libc++ -g -O3 -Wall -Wextra -pedantic -Werror -std=c++20 -pthread
all: project
SRCS = main.cpp input.cpp output.cpp project.cpp
project: $(SRCS:%=%.o)
$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $#
.PHONY: clean
clean:
rm -f *.o project
DEPDIR := .deps
DEPFLAGS = -MT $# -MMD -MP -MF $(DEPDIR)/$<.d
COMPILE.c = $(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
COMPILE.cpp = $(CXX) $(DEPFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
%.c.o: %.c
%.c.o: %.c $(DEPDIR)/%.c.d | $(DEPDIR)
$(COMPILE.c) $(OUTPUT_OPTION) $<
%.cpp.o: %.cpp
%.cpp.o: %.cpp $(DEPDIR)/%.cpp.d | $(DEPDIR)
$(COMPILE.cpp) $(OUTPUT_OPTION) $<
$(DEPDIR): ; #mkdir -p $#
DEPFILES := $(SRCS:%=$(DEPDIR)/%.d) $(DEPDIR)/client.c.d
$(DEPFILES):
include $(wildcard $(DEPFILES))
EDIT
The platform details:
clang --version output:
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
OS details:
NAME="Ubuntu"
VERSION="18.04.6 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.6 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
Full error:
clang++ -MT project.cpp.o -MMD -MP -MF .deps/project.cpp.d -stdlib=libc++ -g -O3 -Wall -Wextra -pedantic -Werror -std=c++1z -pthread -c -o project.cpp.o project.cpp
In file included from project.cpp:1:
./project.hpp:9:10: fatal error: 'barrier' file not found
#include <barrier>
^~~~~~~~~
1 error generated.
Makefile:33: recipe for target 'project.cpp.o' failed
make: *** [project.cpp.o] Error 1
EDIT-2
flag c++20 gives off error: invalid value 'c++20' in '-std=c++20'

SDL Max OSX via Homebrew, Makefile not quite working

I have installed SDL through homebrew, and it works perfectly with my test program if I enter the following command directly in the terminal:
g++ -O3 -g -Wall -Wextra -std=c++1y hello.cpp hello_main.cpp `sdl2-config --cflags --libs` -o hello
but unfortunately my attempts to write a makefile (I will definitely need one) have yielded unsuccessful/unexplained results.
I am following this, but my configuration is different/I am not specifying Cocoa (I don't need to) so I expect that the issues I am encountering are probably due in part to my different requirements:
Compiling SDL on OS X with makefile
Example:
CC=g++
CFLAGS=-c -Wall
SDLFLAGS=`sdl-config --cflags --libs` -framework Cocoa
SOURCES=main.cpp Game.cpp IO.cpp Board.cpp Pieces.cpp Piece.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=tetris
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(OBJECTS) $(SDLFLAGS) -o $#
.cpp.o:
$(CC) $(CFLAGS) $< -o $#
clean:
rm -rf *.o $(EXECUTABLE)
My makefile so far:
CXX = g++
CXXFLAGS = -c -O3 -g -Wall -Wextra -std=c++1y
SDLFLAGS = `sdl2-config --cflags --libs`
SOURCES = hello_main.cpp hello.cpp
OBJECTS = $(SOURCES:.cpp=.o)
EXECNAME = hello
all: $(SOURCES) $(EXECNAME)
$(EXECUTABLE): $(OBJECTS)
$(CXX) $ (OBJECTS) $(SDLFLAGS) -o $#
.cpp.o:
$(CXX) $(CXXFLAGS) $< -o $#
clean :
-rm -f *.o *.core $(EXECNAME)
In my .hpp header file if I #include <SDL.h> and run the one-liner command, everything is successful. If I try my makefile above, cannot be found, but if I then change the directive into #include <SDL2/SDL.h> the library is discovered. Yet the console output is the following:
g++ -c -O3 -g -Wall -Wextra -std=c++1y hello.cpp -o hello
which is odd.
Running ./hello yields a "permission denied" error, which confirms that the linking and compilation were not successful.
Everyone's system is a little bit different and the questions I've found so far don't help in this case.
I am very close to having this working (but then again, how would I start using this in an IDE? I suppose that as long as I can import the fixed makefile or build from the terminal/edit only from the IDE, I am fine.)
What changes in the makefile do I need to make?
Thank you.
EDIT:
Variation 1:
CXX = g++
CXXFLAGS = -O3 -g -Wall -Wextra -std=c++1y -c
SDLCFLAGS = `sdl2-config --cflags`
SDLLIBFLAGS = `sdl2-config --libs`
SOURCES = hello_main.cpp hello.cpp
OBJECTS = $(SOURCES:.cpp=.o)
EXECNAME = hello
all: $(SOURCES) $(EXECNAME)
$(EXECUTABLE): $(OBJECTS)
$(CXX) $ (OBJECTS) $(SDLLIBFLAGS) -o $#
.cpp.o:
$(CXX) $(CXXFLAGS) $(SDLCFLAGS) $< -o $#
clean :
-rm -f *.o *.core $(EXECNAME)
I chatted with a friend and figured what was wrong: a bunch of typos and rule oddities. The following works, for anyone out there who needs a basic makefile:
CXX = g++
CXXFLAGS = -O3 -g -Wall -Wextra -std=c++1y
#LDFLAGS = -lSDL2_image
SDLCFLAGS = $(shell sdl2-config --cflags)
SDLLIBFLAGS = $(shell sdl2-config --libs)
SOURCES = hello_main.cpp hello.cpp
OBJECTS = $(SOURCES:.cpp=.o)
EXECNAME = hello
all: $(EXECNAME)
$(EXECNAME): $(OBJECTS)
$(CXX) $(OBJECTS) $(SDLLIBFLAGS) $(LDFLAGS) -o $#
%.o: %.cpp
$(CXX) -c $(CXXFLAGS) $(SDLCFLAGS) $< -o $#
clean :
-rm -f *.o *.core $(EXECNAME)
You should split your sdl2-config into two - as there are two steps. sdl2-config --cflags should go in the compiler step - thats is the .cpp:.o line in your example. The linking step should be sdl2-config --libs then. The second one seems fine for your case, the additional --cflags there does no harm but is not required.

how do I set compilingflags in a makefile?

I'm used to program in IDEs, but switched to vim and plugins recently. Now I try to write a makefile for a c++ project, but somehow if I run make I always get the error
g++ -c -o *.o createOutput.cpp
In file included from /usr/include/c++/4.8/thread:35:0,
from createOutput.cpp:5:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support for the \
^
This is my makefile:
CC = clang++
# compiler flags
CFLAGS = -O3 -Wall -Werror -std=c++11
CFLAGS_SFML = -lsfml-graphics -lsfml-window -lsfml-system
all: program.exe clean
program.exe: *.o
$(CC) -o program.exe *.o $(CFLAGS) $(CFLAGS_SFML)
getInput.o: getInput.cpp
$(CC) -c getInput.cpp $(CFLAGS)
createOutput.o: createOutput.cpp
$(CC) -c createOutput.cpp $(CFLAGS)
main.o: main.cpp
$(CC) -c main.cpp $(CFLAGS)
.PHONY: clean
clean:
rm *.o
#echo clean done
Where is my error? Why is it using g++ instead of clang? And why isn't it using the -std=c++11 parameter? Sorry for the beginner questions, I unfortunately can't find a solution with google.
You want to set CXXFLAGS, that gets picked up automatically by make (and sent to your compiler (eg g++, clang++, etc).
make tried to make target '*.o'.
So, instead of that, you can specify sources list explicitly:
CC = clang++
#compiler flags
CFLAGS = -O3 -Wall -Werror -std=c++11
CFLAGS_SFML = -lsfml-graphics -lsfml-window -lsfml-system
SRCS = getInput.cpp createOutput.cpp main.cpp
OBJS = $(SRCS:.cpp=.o)
all: program.exe
program.exe: $(OBJS)
$(CC) -o program.exe *.o $(CFLAGS) $(CFLAGS_SFML)
getInput.o: getInput.cpp
$(CC) -c getInput.cpp $(CFLAGS)
createOutput.o: createOutput.cpp
$(CC) -c createOutput.cpp $(CFLAGS)
main.o: main.cpp
$(CC) -c main.cpp $(CFLAGS)
.PHONY : clean
clean:
rm *.o
#echo clean done
Note definition of variables OBJS and SRCS.

How to compile arduino core library with makefile?

I want to create library files (.a) of the arduino core library, eventually also the other libraries (SPI, ...), with a makefile, but I can't get it to work!
This is my makefile:
CC=avr-gcc
CPP=avr-g++
MCU=-mmcu=atmega328p
CPU_SPEED=-DF_CPU=16000000UL
CFLAGS=$(MCU) $(CPU_SPEED) -g2 -gstabs -Os -Wall \
-ffunction-sections -fdata-sections -fno-exceptions
INCLUDE=-I./arduinoCORE
CFILES=$(wildcard ./arduinoCORE/*.c)
CPPFILES=$(wildcard ./arduinoCORE/*.cpp)
OBJ=$(CFILES:.c=.o) $(CPPFILES:.cpp=.o)
default: $(OBJ)
avr-ar -r libarduinoUNO.a $^
%.o : %.c
$(CC) $< $(CFLAGS) -c -o $#
%.o : %.cpp
$(CPP) $< $(CFLAGS) -c -o $#
(all header and source files are in arduinoCORE; even pins_arduino.h)
After $ make in directory above arduinoCORE I get this error message:
avr-g++ arduinoCORE/CDC.cpp -mmcu=atmega328p -DF_CPU=16000000UL -g2 -gstabs -Os -Wall -ffunction-sections -fdata-sections -fno-exceptions -c -o arduinoCORE/CDC.o
In file included from arduinoCORE/Print.h:27:0,
from arduinoCORE/Stream.h:26,
from arduinoCORE/HardwareSerial.h:28,
from arduinoCORE/Arduino.h:193,
from arduinoCORE/Platform.h:15,
from arduinoCORE/CDC.cpp:19:
arduinoCORE/Printable.h:23:17: fatal error: new.h: No such file or directory
#include <new.h>
^
compilation terminated.
make: *** [arduinoCORE/CDC.o] Error 1
The problem is, that new.h is actually in arduinoCORE!
Does anyone know how to manage this?
I had a different error with your code. It displayed Arduino.h as not being present. I fixed it after actually adding the INCLUDE variable to CFLAGS and CPPFLAGS (yours was defined but not added).
I also used CFLAGS and CPPFLAGS as per the Arduino Specification. The code is:
CC=avr-gcc
CPP=avr-g++
MCU=-mmcu=atmega328p
CPU_SPEED=-DF_CPU=16000000UL
INCLUDE=-I./
CFLAGS = -c -g -Os -w -ffunction-sections -fdata-sections -MMD $(MCU) $(CPU_SPEED) $(INCLUDE)
CPPFLAGS = -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD $(MCU) $(CPU_SPEED) $(INCLUDE)
CFILES=$(wildcard ./*.c)
CPPFILES=$(wildcard ./*.cpp)
OBJ=$(CFILES:.c=.o) $(CPPFILES:.cpp=.o)
default: $(OBJ)
avr-ar rcs core.a $^
%.o : %.c
$(CC) $< $(CFLAGS) -c -o $#
%.o : %.cpp
$(CPP) $< $(CPPFLAGS) -c -o $#
Which creates the archive successfully (not tested, just created).

Makefile without specifying the source file

I have a makefile as follows:
# Makefile for VocabLearn
MACHTYPE=$(shell uname -m)
GCC = g++
CC=gcc
# OPTFLAGS=-g2
OPTFLAGS=-O3 -ffast-math -Wall -mfpmath=sse -msse2 -funroll-loops -march=core2
OTHERFLAGS=-Wall -fopenmp
INCLUDE_PATH=-I../lib/ann_1.1/include/ANN -I../lib/ann_1.1_char/include/ANN \
-I../lib/imagelib -I../VocabLib -I../lib/zlib/include
LIB_PATH=-L../lib -L../VocabLib -L../lib/zlib/lib
OBJS=VocabLearn.o
LIBS=-lvocab -lANN -lANN_char -limage -lz
CPPFLAGS=$(INCLUDE_PATH) $(LIB_PATH) $(OTHERFLAGS) $(OPTFLAGS)
BIN=VocabLearn
all: $(BIN)
$(BIN): $(OBJS)
g++ -o $(CPPFLAGS) -o $(BIN) $(OBJS) $(LIBS)
clean:
rm -f *.o *~ $(LIB)
When I 'make' it in the prompt, it works fine and output the following info:(I use Mac OS, c++ means clang compiler)
c++ -I../lib/ann_1.1/include/ANN -I../lib/ann_1.1_char/include/ANN
-I../lib/imagelib -I../VocabLib -I../lib/zlib/include -L../lib -L../VocabLib -L../lib/zlib/lib -Wall -fopenmp -O3 -ffast-math -Wall -mfpmath=sse -msse2 -funroll-loops -march=core2 -c -o VocabLearn.o VocabLearn.cpp
g++ -o -I../lib/ann_1.1/include/ANN -I../lib/ann_1.1_char/include/ANN
-I../lib/imagelib -I../VocabLib -I../lib/zlib/include -L../lib -L../VocabLib -L../lib/zlib/lib -Wall -fopenmp -O3 -ffast-math -Wall -mfpmath=sse -msse2 -funroll-loops -march=core2 -o VocabLearn VocabLearn.o -lvocab -lANN -lANN_char -limage -lz
I just want to know how this makefile works. As you can see, since this makefile doesn't specify which source code to compile, how does the compiler know it is 'VocabLearn.cpp' that it should process? (My guess is that it will search source file according to the name of the object file, VocabLearn.o) Also this line seems a bit strange for me:
g++ -o $(CPPFLAGS) -o $(BIN) $(OBJS) $(LIBS)
Why is there a '-o' before '$(CPPFLAGS)'?
This makefile is using implicit rules to compile the source files. The rule:
$(BIN): $(OBJS)
asks for the object files in OBJS, and make already knows how to build VocabLearn.o if there is a file VocabLean.cpp.
Basically there is an implicit rule to convert *.cpp files to *.o files, however you have to have *.o as a dependency in one your targets. In the given Makefile, you have VocabLearn.o as a dependency for $(BIN). So, VocabLearn.o gets auto-generated from VocabLearn.cpp file.