stefanhaustein / TerminalImageViewer

Small C++ program to display images in a (modern) terminal using RGB ANSI codes and unicode block graphics characters
Other
1.56k stars 111 forks source link

Compilation fails with Cygwin on Windows 7 SP1 #18

Closed samschr closed 6 years ago

samschr commented 6 years ago

I followed the install instructions in the readme, but running "make" gave me a bunch of errors relating to pclose(file) and failed (I can paste the log if need be). I git checked out commit d543b3b and after going through the same steps found that it compiles just fine. After looking at a git diff between d543b3b and master I noticed some differences in the makefile. Namely, the parameter std=c++11 was added on commit 9ec066f. So I reset back to master, removed the -std=c++11 option, and compiled successfully.

It looks like that option was added to fix compilation on mac and Linux, but it seems to break it on windows. I don't know much about programming so I'm not sure if there's a different way to set the standard and fix compatibility with all OS's, but it looks like there may need to be a windows only branch with that option removed.

Here's exactly what I did to fix my error:

diff --git a/src/main/cpp/Makefile b/src/main/cpp/Makefile
index 2cd121f..3a8602d 100644
--- a/src/main/cpp/Makefile
+++ b/src/main/cpp/Makefile
@@ -1,7 +1,7 @@
 default: tiv

 tiv.o: tiv.cpp CImg.h
-       g++ -std=c++11 -Wall -fexceptions -O2 -c tiv.cpp -o tiv.o
+       g++ -Wall -fexceptions -O2 -c tiv.cpp -o tiv.o

 tiv : tiv.o
        g++ tiv.o -o tiv -pthread -s
stefanhaustein commented 6 years ago

Could cygwin be relatively old on Win7? What does g++ --version print?

samschr commented 6 years ago

Cygwin is up to date; I just ran the installer this morning.

GCC/g++ is 6.4.0

EDIT: Here's the log of the failed compilation https://pastebin.com/raw/Y5wqTKdS

stefanhaustein commented 6 years ago

+@profelis do you know which GCC version your change requires? Any ideas how to make this work independently of the GCC version? Does this work on Win10 as it is?

profelis commented 6 years ago

@samschr Add -fpermissive param to g++ in makefile

stefanhaustein commented 6 years ago

Hi, sorry for the delay. Should be fixed at head O:)

masbicudo commented 3 years ago

Hi, just to complement, I had to pass -lstdc++fs to the linker, to avoid an error complaining about not finding std::experimental::filesystem, when compiling with cygwin/g++. The commands to compile were:

g++ -Wall -fexceptions -O2 -c tiv.cpp -o tiv.o
g++ tiv.o -o tiv -pthread -s -lstdc++fs

Also, the gcc-g++ package must be installed in cygwin. If one forgets to install the package, then cygwin will happily use any version of gcc found in the path, even the native version for windows, which can't compile this source code.

Check that you have that installed using:

cygcheck -p bin/g++

If you don't have it, then install it using the cygwinsetup.exe located inside the cygwin folder.