How to compile libevent2 on Windows? - c++

I am trying to compile this libevent2 package to Windows, but currently I can't because the configure script is a shell script (/bin/sh; can't be run in Windows).
Is there any way I can compile it or obtain a pre-compiled package? I currently have MinGW, CMake and MS C++ installed.
EDIT: I have managed to compile libevent2 using nmake Makefile.nmake but it hasn't produced any Windows binaries/libraries. Only .lib.
The makefile is as follows -
# WATCH OUT! This makefile is a work in progress. It is probably missing
# tons of important things. DO NOT RELY ON IT TO BUILD A GOOD LIBEVENT.
# Needed for correctness
CFLAGS=/IWIN32-Code /Iinclude /Icompat /DWIN32 /DHAVE_CONFIG_H /I.
# For optimization and warnings
CFLAGS=$(CFLAGS) /Ox /W3 /wd4996 /nologo
# XXXX have a debug mode
LIBFLAGS=/nologo
CORE_OBJS=event.obj buffer.obj bufferevent.obj bufferevent_sock.obj \
bufferevent_pair.obj listener.obj evmap.obj log.obj evutil.obj \
strlcpy.obj signal.obj bufferevent_filter.obj evthread.obj \
bufferevent_ratelim.obj evutil_rand.obj
WIN_OBJS=win32select.obj evthread_win32.obj buffer_iocp.obj \
event_iocp.obj bufferevent_async.obj
EXTRA_OBJS=event_tagging.obj http.obj evdns.obj evrpc.obj
ALL_OBJS=$(CORE_OBJS) $(WIN_OBJS) $(EXTRA_OBJS)
STATIC_LIBS=libevent_core.lib libevent_extras.lib libevent.lib
all: static_libs tests
static_libs: $(STATIC_LIBS)
libevent_core.lib: $(CORE_OBJS) $(WIN_OBJS)
lib $(LIBFLAGS) $(CORE_OBJS) $(WIN_OBJS) /out:libevent_core.lib
libevent_extras.lib: $(EXTRA_OBJS)
lib $(LIBFLAGS) $(EXTRA_OBJS) /out:libevent_extras.lib
libevent.lib: $(CORE_OBJS) $(WIN_OBJS) $(EXTRA_OBJS)
lib $(LIBFLAGS) $(CORE_OBJS) $(EXTRA_OBJS) $(WIN_OBJS) /out:libevent.lib
clean:
del $(ALL_OBJS)
del $(STATIC_LIBS)
cd test
$(MAKE) /F Makefile.nmake clean
tests:
cd test
$(MAKE) /F Makefile.nmake

A .lib file is a Windows binary file. It's a static library file, and is used by the linker in your application to statically link against (i.e. "use" in layman terms) the library.
Since libevent2 is not a program, you won't get a .exe output - it'll be either a big .dll + small .lib (for dynamic linking) or a big .lib (for static linking).

Use Cygwin to compile. It's a Linux emulation like.

Related

NMAKE: How do I force a debug build? [7ZIP]

The suggested way of building 7Zip is on the command line via the nmake command line utility. 7zip doesn't seem to come with a working visual studio solution.
I have seen invocations such as nmake NEW_COMPILER=1 MY_STATIC_LINK=1 suggested for initiating a build using the various nested .MAK files.
Using this command line interface how might I force a build with debug symbols?
If there is no standard way to accomplish this via nmake, I'd be glad to receive help with regards to 7Zip in particular. I am much less familiar with .MAK than GNU make, and have thus far been unable to find something akin to a "debug target" in the GNU make sense in 7ZIP.
To make a project that uses visual studio nmake build a debug output you need to edit the makefile and make 2 changes.
First you need to add /Zi to the list of flags used when compiling
CFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -W4 -WX -EHsc -Gy -GR- -GF /Zi
Second you need to add /debug to list of options for the linker e.g.
LFLAGS = $(LFLAGS) -nologo -OPT:REF -OPT:ICF /DEBUG
I tested this on a different library, I assume there will be similarities here.
7zip archiver gives great compression and performance results, but unfortunately have lack of documentation nor for building process nor at the entire code.
I know that the question asked 1.5 yrs ago but I hope to save someone time for digging around in the 7z.
To build 7z from sources you need the Microsoft Visual Studio and do following steps:
Start Tools Command Prompt for VS 2019
Navigate to sources folder cd c:\sources\7z
Invoke nmake /f makefile
Otherwise you can convert MSVC 6.0 dsw/dsp files to modern .vcxproj format. Just open dsw file in the MSVC 2019 and it will do the conversion automatically.
The trick is that you need to navigate into project directory to do that. The 7z build system hard tied to relative directory structure and gets build parameters from top level main Build.mak file.
So, if you need to modify build parameters for all projects it is enough to modify that file.
For 7z version 19.00 you need to edit these lines in CPP/Build.mak file:
Add /Zi fag to line CFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -W4 -WX -EHsc -Gy -GR- -GF /Zi
Add /DEBUG LFLAGS = $(LFLAGS) -nologo -OPT:REF -OPT:ICF /DEBUG
Change -O1 and -O2 for flags CFLAGS_O1 CFLAGS_O2
!IF "$(PLATFORM)" == "x64"
CFLAGS_O1 = $(CFLAGS) -Od
!ELSE
CFLAGS_O1 = $(CFLAGS) -Od
!ENDIF
CFLAGS_O2 = $(CFLAGS) -Od

g++ does not produce debug symbols

I am learning linux, and my first step is to adapt my project for running on linux. Here is simple makefile (in educational purposes mostly), which generates out file:
#------------------------BUILD VARIABLES-----------------------------
# Directories, containing headers
INCLUDE_DIR = ../Include/
# Output directory which will contain output compiled file
OUTPUT_DIR = ../Bin/Debug/
SOURCES = EngineManager.cpp Geometry.cpp Main.cpp Model.cpp \
Shaders.cpp TGAImage.cpp
HEADERS = EngineManager.h Geometry.h Line.h Model.h Shaders.h \
TGAImage.h Triangle.h
#------------------------BUILD_RULES---------------------------------
TinyRenderBuilding : $(addprefix $(INCLUDE_DIR), $(HEADERS)) $(SOURCES)
mkdir -p $(OUTPUT_DIR)
g++ -std=c++14 -o $(OUTPUT_DIR)TinyRender.out -g -I$(INCLUDE_DIR) $(SOURCES)
I cannot understand, why does g++ not generate debug symbols? -g option is presented
To include debug symbols when compiling with g++ you need to pass the -g option.
In a make make file this usually means adding it to to CXXFLAGS.
Also make sure you pass the -g option when you create the executable: when you compile you turn .cpp files into .o files, when you do the linking you turn those .o files into your executable).
If you change the options before running make again be sure to run a make clean cause otherwise it won't get recompiled.
Finally, make sure that you do not have additional steps like strips command run on the executable (which would remove debugging symbols).
you can use
objdump --syms <executable-file>
to check if an executable have symbols.
when it doesn't have symbols it will say something like:
SYMBOL TABLE:
no symbols
(I'm no experto of C / C++ programming, I just run into this while I was trying to debug someone else code)
According to your makefile g++ should produce debug symbols (-g option is presented). To confirm this you can run file on resulting binary:
$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=9fe588c18099ef418daf288931bb033cc287922e, with debug_info, not stripped
(Note with debug_info string in output)
I'm not entirely sure, but you can try -g or -ggdb.You can do some research on these. We were using these parameters to debug the C program with the gdb tool.

Clang 4.0 debugging using Visual Studio

I have a project that I am still trying to setup using Clang and Visual Studio on Windows. As a caveat, I've worked on several c++ projects but they've all been mature projects where I haven't had to be involved in setting up make files or resolving dependencies hence why I want some experience in doing so.
As a clarification, I am not using the LLVM built into visual studio thing. My goal was to have visual studio be a convenience on top of having a project that can be built with make files but not using CMake.
So far, I have a solution with a single nmake project. This nmake project calls a build.bat file which calls into a make file. This make file looks like this:
# Based on PUXAN tutorial
# http://www.puxan.com/web/howto-write-generic-makefiles/
# Compiler choice
CC = clang++ -g -O0
CC_OBJ_FLAGS = -w -v -c
# Name of our executable and also the main run target
EXEC = ../bin/output.exe
# Here we get every cpp file in the source directory to make a list of source files
SOURCES = $(wildcard ../src/*.cpp)
# Here we have mapped all the cpp files to o files and now have a list of o files
TMP_OBJECTS = $(SOURCES:.cpp=.o)
OBJECTS = $(foreach obj,$(TMP_OBJECTS),$(subst src,obj,$(obj)))
INC = -I../lib/glfw-3.2.1/include
LINK = -L../lib/glfw-3.2.1/lib-vc2015 -lglfw3dll -lglfw3 -lopengl32
# compile list of o files into executable
# NOTE: when make is run without a target, the first target is chosen. This target
# should remain the first at all times
$(EXEC): $(OBJECTS)
$(CC) $(LINK) $(OBJECTS) -o $(EXEC)
# As each o file becomes a target, compile the associated cpp file into the o file
../obj/%.o: ../src/%.cpp
$(CC) $(CC_OBJ_FLAGS) $(INC) $< -o $#
# Remove the entire list of objects and the executable
clean:
rm -f $(EXEC) $(OBJECTS)
rebuild:
make -B
You'll notice that I've included the -g and -O0 flags which should output symbols and sure enough, I get a pdb file generated for output.exe (and also all the o files but I can clean that up later). When I go to debug the project in Visual Studio however, it says the symbols for the module are loaded but breakpoints aren't hitting which I think is pointing to the pdb not having references to the source. Here is the debug output in Visual Studio:
'output.exe' (Win32): Loaded 'W:\Scratch\Engine\bin\output.exe'. Symbols loaded.
Posts about Clang from 2016 and earlier mention that it doesn't generate PDB files yet and that thats a work in progress and sure enough the Clang compability site (https://clang.llvm.org/docs/MSVCCompatibility.html) mentions how debug info is a work in progress but that I should be able to generate CodeView info using /Z with 7 or i. I have tried passing both /Zi and /Z7 to clang and to the linker directly but clang complains about them and the linker ignores them with a warning. This documentation claims to be from Clang 6 that is, from what I can tell, not released yet and is experimental. However, using Clang 4.0 with -g flag, I am indeed able to generate pdb files.
Does anyone have any further information on this? Is there anything else I can provide to determine if I have set all this up correctly? Am I just missing a flag that would correctly provide the sources or am I missing a setting in visual studio to pick the sources? I tried setting sources manually in visual studio at the project and solution level to no effect. Should I look at the pdb file with a pdb viewer of some kind and see if the source paths are there?
Thanks in advance to any help.
The clang option equivalent to -Z7/-Zi is called -gcodeview (and has to be used in addition to -g). For MSVC-style command line options, you need to use the clang-cl compiler driver instead.
For the MSVC Version ( https://llvm.org/builds/) it works like in the following picture but to set clang on VS2017 up you need to install Microsoft's Platform Toolset V1.40 first:
VS2017 Clang debug
Project -> Properties -> C/C++ -> Commandline -> Options: "/Z7"

CMake: Error running link command: %1 is not a valid Win32 application

I'm trying to build a NaCl extension on 64-bit Windows 8.1 using CMake. The same code works on Ubuntu without any problems. Everything goes well until CMake tries to link with this command:
cmake -E cmake_link_script link.txt
CMake: Error running link command: %1 is not a valid Win32 application
The link.txt is as follows:
C:/nacl_sdk/pepper_39/toolchain/win_pnacl/bin/pnacl-ar cr libfoo.a CMakeFiles/foo.dir/Foo.cc.o
C:/nacl_sdk/pepper_39/toolchain/win_pnacl/bin/pnacl-ranlib libfoo.a
This happens with both NMake and Unix makefile generators (the NaCl SDK contains make.exe for Windows).
If I run those commands manually, they succeed. What could be wrong here?
Just like eugensk00 suggested adding ".bat" in toolchain definitions seems to work. It is required to add both for ar and ranlib though:
set(CMAKE_AR "${PLATFORM_PREFIX}/bin/pnacl-ar.bat" CACHE STRING "")
set(CMAKE_RANLIB "${PLATFORM_PREFIX}/bin/pnacl-ranlib.bat" CACHE STRING "")

trouble installing old 2005 BOOST library

Gooday everyone
I'm fairly new to ubuntu C programing although I'm
rather experienced in C programing in windows.
I have recently come accross a number of codes written
in 2005 which I'm interested in learning how they work.
Those codes needs BOOST library to compile, however they won't
compile on the newest BOOST version present on my ubuntu 12.04.
I set the gcc compiler on lenient so that it ignores all those error
messages. The code did compile and ran afterwards.
However, when I used GDB debugger to watch how the program flows
I noticed that there are likely errors in the way the program runs
due to using a different BOOST version rather than it's original. Hence
I like to install the BOOST version corresponding to the code I downloaded.
To do that, I installed Ubuntu 5.04 and BOOST 1.33.0 which seemed to have been created in late 2005. I downloaded it
but I didnt found any detailed instruction on how to install it.
Only vague description on using BOOST jam, I played around with BOOST
jam for quite awhile without success.
And this old BOOST does not have installation commands like
"sudo apt-install boost-dev" style option
Thus I like to ask if anyone can give a easy to understand step by step instruction
on how to install the BOOST library downloaded from the above link.
like.....
step1: download boost jam from boost webpage
step2: unpack it in home/boost/ then type make configure
...and so on...
Big thanks for any useful info.
New Contents appended here
in response to the comments given
Hi, I went through the info given by your link and
managed to run the boost library examples given by your link.
That is, I can compile a single cpp file with the command
g++ -I boost_1_33_0 test.cpp -o test
(I'm keeping the boost library and the cpp file to be compiled in the
same folder)
However, the program package I'm interested in is build with make (not cmake).
I have some experience writting cmake files but not make files.
And I do not see any link to boost library command in the make file of the
program package. The readme file only has one sentence that says I
need to have boost installed without explaining what that meant.
I assume it means that either I have to build and do makeinstall the boost or
I could add some lines in the makefile for a link. I thought
maybe you can quickly point out whats missing in the makefile.
The readme file:
To compile, go into the moses directory and do 'make'. You'll need the
latest boost libraries. If compilation still fails for weird reasons,
you could try g++ with the -fpermissive (newer versions reject lots of
code that was ok with older ones). If you are going to be making
changes and recompiling frequently you'll probably want to disable -O3
in the makefile (I use templates liberally, so -O3 really speeds up
the code, but really slows down compilation).
And the makefile:
CC = g++
PROJ_NAME = moses
LINK_FLAGS = -Wall -Iutils/ -Itrees/ -Irewrite -I./ -Imodeling/ -Ifitness/ \
-Ialignment/ -Isim/ -Ilocal/ -O3
COMP_FLAGS = -Wall -Wno-sign-compare -Iutils/ -Itrees/ -Irewrite -I./ \
-Imodeling/ -Ifitness/ -Ialignment/ -Isim/ -Ilocal/ -O3
src := $(wildcard *.cc) $(wildcard utils/*.cc) $(wildcard trees/*.cc) $(wildcard modeling/*.cc) $(wildcard fitness/*.cc) $(wildcard alignment/*.cc) $(wildcard main/*.cc) $(wildcard rewrite/*.cc) $(wildcard sim/*.cc) $(wildcard local/*.cc)
obj := $(patsubst %.cc,%.o,$(src))
all: $(PROJ_NAME)
%.o: %.cc
$(CC) $(COMP_FLAGS) $< -c -o $#
$(PROJ_NAME): $(obj)
$(CC) $(LINK_FLAGS) $^ -o $(PROJ_NAME)
run:
$(PROJ_NAME)
clean:
find -regex ".*~\|.*\.o"|xargs rm -f
rm -f $(PROJ_NAME)
rm -f $(PROJ_NAME).exe*
depend:
makedepend -Y -- $(COMP_FLAGS) -- $(src)
utils/exceptions.o: utils/exceptions.h utils/utils.h
utils/io_util.o: utils/io_util.h utils/tree.h utils/basic_types.h
# ......lots more lines like that.........
I have an old instruction flying around here for Boost 1.34.1, which reads like this (project-specific stuff cut away):
unpack boost sources
cd into tools/jam/src
run ./build.sh to build bjam
cd into the main source directory
tools/jam/src/bin.linux/bjam threading=multi --layout=system --toolset=gcc --without-python variant=release --prefix=/usr/local install
The --without-python was necessary as the target system didn't have Python installed, which caused the build to fail messily.
Obviously you can / need to fiddle with the individual settings (like threading support, release vs. debug variant) to suit your needs, but it should be a good starting point.
If you need ICU support (for Boost.Regex and Boost.Locale), it gets more complicated...
Note that the build process has changed over the years; you shouldn't use the same procedure for more up-to-date boost versions. It's just what I used back then.
Edit:
As for the second part of your question, the Makefile doesn't need to refer to Boost explicitly if boost is installed in the standard system directories.
You do not have to state -I /usr/include for compilation as that is searched automatically; the same goes for -L /usr/lib during linkage.
The fact that the author of the Makefile copied the compiler flags into the linker flags verbatim doesn't really help intuitivity either... ;-)
If you have Boost in a custom directory (either the headers only, or by stating a custom directory in the --prefix option of my build instructions), you need to make the following modifications (look for "boost"):
LINK_FLAGS = -Wall -Iutils/ -Itrees/ -Irewrite -I./ -Imodeling/ -Ifitness/ \
-Ialignment/ -Isim/ -Ilocal/ -L /path/to/boost/libs -O3
COMP_FLAGS = -Wall -Wno-sign-compare -Iutils/ -Itrees/ -Irewrite -I./ \
-Imodeling/ -Ifitness/ -Ialignment/ -Isim/ -Ilocal/ \
-I /path/to/boost/includes -O3
That should do the trick. As the Makefile does not link any of the Boost binaries (e.g. -l boost_program_options or somesuch), it seems that it makes use of the Boost headers only, which would make the -L /path/to/boost/libs part (and, actually, the whole compilation step detailed above) superfluous. You should be able to get away with simply unpacking the sources and giving the header directory as additional include directory using -I /path/to/boost/headers.