How can I compile "Triangle" using makefiles on a Windows machine - makefile

I have just discovered a mesh generator called triangle, found here http://www.cs.cmu.edu/~quake/triangle.html
I am having some issues building this using the make files that are provided. When I passed in the makefile to my visual studio via the command prompt, I got an error
Microsoft (R) Program Maintenance Utility Version 11.00.50727.1
Copyright (C) Microsoft Corporation. All rights reserved.
NMAKE : fatal error U1073: don't know how to make './triangle.c'
Stop.
I have no idea how to debug this.

Eh? Did you read the copious comments in makefile? Just remove -DLINUX from CSWITCHES. Do not try to build showme. Use gcc.
So, with cygwin installed (don't forget the make and gcc packages):
C> bash --login
$ vim makefile
Remove -DLINUX, then
$ make triangle
cc -O -I/usr/X11R6/include -L/usr/X11R6/lib -o ./triangle ./triangle.c -lm
$ make tricall
cc -O -I/usr/X11R6/include -L/usr/X11R6/lib -DTRILIBRARY -c -o ./triangle.o \
./triangle.c
cc -O -I/usr/X11R6/include -L/usr/X11R6/lib -o ./tricall ./tricall.c \
./triangle.o -lm
$ ./triangle.exe
triangle [-prq__a__uAcDjevngBPNEIOXzo_YS__iFlsCQVh] input_file
-p Triangulates a Planar Straight Line Graph (.poly file).
-r Refines a previously generated mesh.
...
Easy, no?

That is a makefile. nmake is not actually a make program, or to be clear, it doesn't conform to the POSIX definition of make. It can't be used with this makefile. Assuming you don't want to go find a POSIX-based system (GNU/Linux, Mac OSX, Solaris, etc.) to work with this on, you'll need to either (a) compile it by hand (it doesn't look like there are too many files) or (b) get a copy of make for your Windows system. There are various ports of GNU make for Windows; probably the easiest one for you to get is from MinGW: http://sourceforge.net/projects/mingw/files/MinGW/Extension/make/make-3.82-mingw32/

Compiling this on windows is gonna make your head sore... It's not portable. I think I saw a few Linux Syscalls in there.
So like the previous answer said, either install a Linux distribution or get yourself MiniGW or CygWin - My Personal favorite.

I agree with getack that building on Windows in general is a recipe for headaches. But triangle by Jonathan Richard Shewchuk is (an awesome) single-file program with no dependencies, so in this case you are fine:
1) Install the microsoft SDK (it's free for the command line stuff).
2) Then create the following file build.bat in the folder with the unpacked source files:
REM Compile Triangle using Microsoft C compiler
REM You must install the msvc SDK
REM Janus, 2013
"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd"
cl /DNO_TIMER /DCPU86 triangle.c
3) Run the build.bat file. This should create a nice triangle.exe.
Background: The call to C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd is required to set up the environment for the microsoft build system. Alternatively the SDK installs a Windows SDK 7.1 Command Prompt where SetEnv is run. See this page for details.

Janus answer worked for after some work. If you are having issues using the bat file he wrote, open SetEnv.cmd (Paste C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd in any file-browser / cmd and hit enter). Then navigate to the project with "cd Path". Than type "cl /DNO_TIMER /DCPU86 triangle.c". Basically its the bat file executed manually. (The bat didnt work for me)

Related

CMake-generated MinGW Makefile has quoting errors

I was trying to build zlib with CMake 3.9.0, output set to MinGW Makefiles, and noticed upon trying to call mingw32-make in the output dir that there was a weird error message which very much looks like a quoting error to me.
D:\zlib-1.2-11> mingw32-make
[ 2%] Generating zlib1rc.obj
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
C:\Program Files\mingw-w64\x86_64-7.1.0-win32-seh-rt_v5-rev0\mingw64\bin\windres.exe: preprocessing failed.
CMakeFiles\zlib.dir\build.make:60: recipe for target 'zlib1rc.obj' failed
mingw32-make[2]: *** [zlib1rc.obj] Error 1
CMakeFiles\Makefile2:103: recipe for target 'CMakeFiles/zlib.dir/all' failed
mingw32-make[1]: *** [CMakeFiles/zlib.dir/all] Error 2
Makefile:139: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
What could be the cause of this error and how can I fix it? If it were only zlib, I could scrape the net for pre-built binaries, but this has happened with some other builds, too.
This appears to be a bug in MinGW's version of windres.exe, although I'm also going to heap some blame onto CMake for it's appalling method of invoking windres, which is what is causing this to fail.
The Problem
CMake understands that Windows Resource .rc files are a thing, and that they are compiled with the Windows Resource Compiler (aka windres.exe), which it wraps in the default variable CMAKE_RC_COMPILER.
The problem is, that rather than just invoking windres like a normal person, CMake thinks it's being clever by invoking it like so...
cmd.exe /C "cd /D C:\Users\username\zlib-1.2.11\build && "C:\Program Files\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev0\mingw64\bin\windres.exe" -D GCC_WINDRES -I C:/Users/username/zlib-1.2.11 -I C:/Users/username/zlib-1.2.11/build -o C:/Users/username/zlib-1.2.11/build/zlib1rc.obj -i C:/Users/username/zlib-1.2.11/win32/zlib1.rc"
Evidently it doesn't understand the notion of the current working directory, or the system path variable (which it used to find windres in the first place). If we were to simplify the command, it would look like this...
windres -D GCC_WINDRES -I.. -I. -ozlib1rc.obj -i ../win32/zlib1.rc
Those two commands carry the exact same meaning, except the second one actually works.
The Solution
We have to step in and stop CMake from trying to be clever.
cmake .. -DCMAKE_RC_COMPILER=windres
I have MSVC 2017 installed, and CMake assumes that I want to use that by default, despite none of its environment variables being set and it not being in the path (in normal usage, one must invoke the vcvars64.bat file before using MSVC, this behaviour predates CMake). So I have to use -G "MinGW Makefiles", except that I also have sh.exe in my path (because Git), and that just blows CMake's mind, so I need the command...
cmake .. -G"MSYS Makefiles" -DCMAKE_RC_COMPILER=windres
The CMake file author should have quoted strings containing unknown filesystem paths, i.e. variables and the VERBATIM option also avoids headaches:
if(MINGW)
# This gets us DLL resource information when compiling on MinGW.
if(NOT CMAKE_RC_COMPILER)
set(CMAKE_RC_COMPILER windres.exe)
endif()
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj"
COMMAND "${CMAKE_RC_COMPILER}"
-D GCC_WINDRES
-I "${CMAKE_CURRENT_SOURCE_DIR}"
-I "${CMAKE_CURRENT_BINARY_DIR}"
-o "${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj"
-i "${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc"
VERBATIM)
set(ZLIB_DLL_SRCS "${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj")
endif(MINGW)

How do I fix the error ' "VC" machine not recognized' for perl Configure [duplicate]

After following the instructions in INSTALL.W64 I have two problems:
The code is still written to the "out32" folder. I need to be able to link to both 32-bit and 64-bit versions of the library on my workstation, so I don't want the 64-bit versions to clobber the 32-bit libs.
The output is still 32-bit! This means that I get "unresolved external symbol" errors when trying to link to the libraries from an x64 app.
To compile the static libraries (both release and debug), this is what you need to do:
Install Perl - www.activestate.com
Run the "Visual Studio 2008 x64 Cross Tools Command Prompt" (Note: The regular command prompt WILL NOT WORK.)
Configure with
perl Configure VC-WIN64A no-shared no-idea
Run: ms\do_win64a
EDIT ms\nt.mak and change "32" to "64" in the output dirs:
# The output directory for everything intersting
OUT_D=out64.dbg
# The output directory for all the temporary muck
TMP_D=tmp64.dbg
# The output directory for the header files
INC_D=inc64
INCO_D=inc64\openssl
EDIT ms\nt.mak and remove bufferoverflowu.lib from EX_LIBS if you get an error about it.
Run: nmake -f ms\nt.mak
EDIT the ms\do_win64a file and ADD "debug" to all lines, except the "ml64" and the last two lines
Run: ms\do_win64a
Repeat steps 4 and 5
EDIT the ms\nt.mak file and ADD /Zi to the CFLAG list!
Run: nmake -f ms\nt.mak
I solved the problem this way, using the 1.0.1c source:
Add this block to util/pl/VC-32.pl, just before the $o='\\'; line.
if ($debug)
{
$ssl .= 'd';
$crypto .= 'd';
}
Add this block to util/pl/VC-32.pl, just before the if ($debug) line.
if ($FLAVOR =~ /WIN64/)
{
$out_def =~ s/32/64/;
$tmp_def =~ s/32/64/;
$inc_def =~ s/32/64/;
}
Then build all varieties:
setenv /x86 /release
perl Configure VC-WIN32 --prefix=build -DUNICODE -D_UNICODE
ms\do_ms
nmake -f ms\ntdll.mak
setenv /x64 /release
perl Configure VC-WIN64A --prefix=build
ms\do_win64a.bat
nmake -f ms\ntdll.mak
setenv /x86 /debug
perl Configure debug-VC-WIN32 --prefix=build -DUNICODE -D_UNICODE
ms\do_ms
move /y ms\libeay32.def ms\libeay32d.def
move /y ms\ssleay32.def ms\ssleay32d.def
nmake -f ms\ntdll.mak
setenv /x64 /debug
perl Configure debug-VC-WIN64A --prefix=build
ms\do_win64a.bat
move /y ms\libeay32.def ms\libeay32d.def
move /y ms\ssleay32.def ms\ssleay32d.def
nmake -f ms\ntdll.mak
Use Conan. It is very simple to install and use.
You can request the files ready for use. For example for Linux x64 or usage with Visual Studio 2012. Here a sample instruction:
conan install OpenSSL/1.0.2g#lasote/stable -s arch="x86_64" -s build_type="Debug" -s compiler="gcc" -s compiler.version="5.3" -s os="Linux" -o 386="False" -o no_asm="False" -o no_rsa="False" -o no_cast="False" -o no_hmac="False" -o no_sse2="False" -o no_zlib="False" ...
According to the official documentation:
"You may be surprised: the 64bit artefacts are indeed output in the out32* sub-directories and bear names ending *32.dll. Fact is the 64 bit compile target is so far an incremental change over the legacy 32bit windows target. Numerous compile flags are still labelled "32" although those do apply to both 32 and 64bit targets."
So the first answer is no longer necessary.
Instructions can be found here:
https://wiki.openssl.org/index.php/Compilation_and_Installation#W64
At the time of writing this how-to the most recent version of OpenSSL is 1.1.1a.
Environment:
Windows 10
MS Visual Studio 2017
Prerequisites:
Install ActivePerl - Community edition is fine
Install NASM
Make sure both Perl and NASM are in PATH environment variable.
Compiling x64:
Open x64 Native Tools Command Prompt
perl Configure VC-WIN64A --prefix=e:\projects\bin\OpenSSL\vc-win64a --openssldir=e:\projects\bin\OpenSSL\SSL
nmake
nmake test
nmake install
Step 4 is optional.
Compiling x86:
Open x86 Native Tools Command Prompt
perl Configure VC-WIN32 --prefix=e:\projects\bin\OpenSSL\vc-win32 --openssldir=e:\projects\bin\OpenSSL\SSL
nmake
nmake test
nmake install
Step 4 is optional.
If you're building in cygwin, you can use the following script, assume MSDEVPATH has already been set to your Visual Studio dir
echo "Building x64 OpenSSL"
# save the path of the x86 msdev
MSDEVPATH_x86=$MSDEVPATH
# and set a new var with x64 one
MSDEVPATH_x64=`cygpath -u $MSDEVPATH/bin/x86_amd64`
# now set vars with the several lib path for x64 in windows mode
LIBPATH_AMD64=`cygpath -w $MSDEVPATH_x86/lib/amd64`
LIBPATH_PLATFORM_x64=`cygpath -w $MSDEVPATH_x86/PlatformSDK/lib/x64`
# and set the LIB env var that link looks at
export LIB="$LIBPATH_AMD64;$LIBPATH_PLATFORM_x64"
# the new path for nmake to look for cl, x64 at the start to override any other msdev that was set previously
export PATH=$MSDEVPATH_x64:$PATH
./Configure VC-WIN64A zlib-dynamic --prefix=$OUT --with-zlib-include=zlib-$ZLIB_VERSION/include --with-zlib-lib=zlib-$ZLIB_VERSION/x64_lib
# do the deed
ms/do_win64a.bat
$MSDEVPATH_x86/bin/nmake -f ms/ntdll.mak ${1:-install}
The build instructions have changed since this question was originally asked. The new instructions can be found here. Note that you will need to have perl and NASM installed, and you will need to use the developer command prompt.
You can also use MSYS+mingw-w64:
1) download and extract msys to C:\msys
2) download and extract mingw-w64 to c:\mingw64
3) run msys postinstall script. When it asks for your mingw installation, point it to C:\mingw64\bin
4) Extract an openssl daily snapshot (1.0.0 release has a bug). In the source dir run
configure mingw64
make
make check
make install
5) openssl is installed to /local/

Error fatal - No such file or directory

I have installed the cds library with command ./build.sh -b 64 -z '-std=c++0x' -l '-L /usr/lib/x86_64-linux-gnu' --with-boost /usr/include/boost --amd64-use-128bit at build folder.
After I tried to compile the example init.cpp of src folder, I typed this in terminal: g++ init.cpp -o init, and terminal showed: fatal error: cds/init.h: No such file or directory.
What should I do for compilation command in this case?
Thanks.
For general troubleshooting in cases like this, i would recommend finding where on the system the file got installed (if your build.sh actually installed the file). You would be able to find the missing header file using
find / -path '*/cds/init.h' 2>/dev/null
Then you need to supply two parameters to g++:
First one gets the compiler to know about the include files from the install directory
-I path_to_folder_one_step_above_cds_folder
Second one gets the linker to know about the librarys location. If the library file is called libcds.so, you can find it by running
find / -name libcds.so 2>/dev/null
So for linking, you supply the flag
-L path_to_folder_one_step_above_libcds.so
In your case you might not need the -L flag, since most of your library supposedly is header only.
UPDATE: the build.sh script is printing out important information at the top, starting with "Building with the following options:". The important bits will be "Compile options:" and "Link options:". Those should be enough to solve your specific option.
UPDATE2: build.sh also exports some flags which might include more options. You can print them out directly after running build.sh by running
echo LDFLAGS=$LDFLAGS
echo CFLAGS=$CFLAGS
echo CXXFLAGS=$CXXFLAGS
you are likely to need to pass all these options to g++ when compiling and linking against that library. LDFLAGS are specific to the linker only. Both the other ones are needed for compiling c++ files.

Visual Studio Compiler and recursive Make

I've got a really scary error message while using the visual studio compiler with recursive make.
This is my setup:
Top level Makefile:
.PHONY: test
test:
$(MAKE) -C subdir
Makefile in subdir:
.PHONY: all
all:
cl.exe /nologo /c src/interface.cpp
The compilation succeeds but I always recieve this warning:
unrecognized source file type 'cl', object file assumed
This warning only appears when I invoke make using the top level Makfile. If I change the directoy to subdir and run make no error appears.
cl.exe is known to make by running vcvarsall.bat before running make.
I really hope you can help me.
Thanks in advance.
The problem was, that I had a variable holding the filename of the compiler and I exported that variable from Make. So the command was cl.exe cl.exe... Thanks!

Cannot Execute File in Terminal OSX

I can run compile in OSX terminal using g++ -Wall -c pa1.cpp -o pa1. Which creates pa1, so I know my compilation works in terminal but I am having issues with execution. I have tried ./pa1 , ./a.out, pa1 and few others. I believe the issue is with Xcode, yet the fact that my code will compile in terminal and creates an executable makes me unsure. Thought, I would ask here for suggestions before reinstalling Xcode.
Use g++ pa1.cpp -o pa1 and then you'll be able to run your new executable as ./pa1. This require that your whole program is in pa1.cpp. If it is spread in multiple files, you'll have to list all of them on the command-line.
As said in the comments, the -c option means compile, ie. Create an object file that can be passed to the linker to build an executable. If you don't use this option, g++ will first compile any source file, then invoke the linker on all the object files to create an executable named a.out by default (name comes from historical reason).
You can see that the output of your command was not an executable binary but an intermediate object file by using the file util.

Resources