How to Compile Ncurses Program for Native Windows Use - windows

I'm trying to compile a C program using Ncurses on Windows. I compiled it successfully using GCC and it works perfectly if I run it in Cygwin or MSYS2. However, if I try to run it in the Windows Command Prompt, I get this error:
Error opening terminal: xterm-256color.
Is it possible to compile it to run using the native Windows console? This is how I've been compiling it:
gcc -o PROGRAMNAME main.c -lncurses
I also have the Cygwin and Msys dlls for Ncurses copied into the directory of the compiled executable.
Update
So I figured out how to get the program to run. I deleted all the DLLs from the project folder and then added "C:\msys64\usr\bin" to my PATH environment variable. However, I would still like to know if there's a way to get this to work if I were to distribute it, since it's still relying on my installation of MSYS2.
Update 2
Gave up and just used pdcurses and it works fine.
Update 3
Nevermind, found a solution! See below.

I figured out a solution. I'll post it here in case anyone else has this same issue. Thanks to Thomas Dickey for your help!
Install the mingw-w64 toolchain and any other packages you need to compile your project (this is mostly where I messed up)
Make sure to include the /mingw64/include/ncurses directory when compiling, or else gcc won't be able to find curses.h
Include /mingw64/bin as a static directory or copy over the necessary dlls to the same folder as the directory
I ended up with this to compile:
gcc -I/mingw64/include/ncurses -o PROGRAMNAME main.c -lncurses -L/mingw64/bin -static

Related

Compiling on Windows using g++ and finding dependent .dlls

I'm making a 3D printer from scratch, hardware and software. I am using mingw to compile on windows and it works. But the .exe it produces relies on a bunch of .dlls in mingw's bin folder. So that means that either I'm doing something wrong or just don't know which .dlls need to go with my .exe.
The command I run to compile is:
g++ -o Slicer.exe "d:\Programming And Creativity\Slicer\main.cpp" "d:\Programming And Creativity\Slicer\slice.cpp" "d:\Programming And Creativity\Slicer\face.cpp" "d:\Programming And Creativity\Slicer\line.cpp" "d:\Programming And Creativity\Slicer\vertex.cpp"
If I try going to my project's folder and running g++ from there, it complains about a bunch of missing files. How can I reduce the numer of dll's needed to run the exe file?
I figured out a solution to my problem, I just had to add the --static flag.

Can't make FestVox compile due to missing -leststring and missing libeststring.a

So I have installed / compiled speech_tools, and Festival (2.3) using Cygwin on my Win8.1 machine to the point that I can successfully produce speech using this command:
echo "hello world" | \src\main\festival --tts
The next step is for me to get FestVox running. I have downloaded FestVox 2.6 and I have run ./configure; however, the 'make' step is giving me trouble, producing this error:
gcc -O3 -Wall -o phonealign phonealign_main.o -LC:/cygwin64/Festival/build
/speech_tools/lib -lestools -lestbase -leststring -lncurses -lstdc++ -lm -lwinmm -luser32
/usr/bin/ld: cannot find -leststring
collect2: error: ld returned 1 exit status
Makefile:80: recipe for target 'phonealign' failed
So, I looked at my Makefile at where it might be trying to look for this file, and it looks like in that directory (build\speech_tools\lib) I am missing a libeststring.a partner for my libeststring.lib. Both libestbase and libestools have .lib and .a files in that directory.
At what step did I go wrong?? Should a libeststring.a have been created at some point??? When? How can I fix this?
I think the problem is that you should use compiler in Windows instead of gcc within Cygwin. The role in Cygwin for building Festival is to run configure to generate a Makefile for VC. Then run nmake in Windows command line not make within Cygwin.
Cygwin cannot build a native Windows application like what MINGW does. Application build in Cygwin can only run within Cygwin.
*.a is the static library for Linux, which is built by gcc. *.lib is the static library for Windows, which is built by VC.
So I suggest you taking a look at README, INSTALL files in FestVox. To find whether there is description for make a Makefile for Windows like process "3. Make makefile for VC in Cygwin" in my document (http://www.eguidedog.net/doc_build_win_festival.php)
Cameron

gcc fails with spawn: No such file or directory

I downloaded
Ruben’s build of
Cygwin GCC.
However upon running it seems unable to compile any files
$ touch foo.c
$ gcc foo.c
gcc: error: spawn: No such file or directory
As a workaround, I found this to work
i686-w64-mingw32-gcc foo.c
I had the same problem and solved it by installing the g++ package in addition to gcc-core
I had this same problem on Cygwin64, and the solution was PATH related..kinda.
Turns out, there are copies of gcc in /usr/bin and /bin (at least, there is in my install).
Executing /bin/gcc failed with the error above -- I'm guessing due to incorrectly assumed relative paths???
Executing /usr/bin/gcc works as expected!
In my case, the "problem" was that I had inadvertently injected "/bin" into my PATH environment variable, resulting in /bin/gcc being executed, instead of /usr/bin/gcc. Removing the "/bin" from the path solved the problem.
Still unclear why there are two gcc binaries (which appear to be identical) in different places... but maybe the Cygwin gurus can answer that; or maybe my installation is just foo-barred.
Ruben's builds are not Cygwin GCC packages, rather they are cross-compilers which run on various platforms but target native Windows using the MinGW-w64 toolchain.
In any case, you shouldn't be using them on Cygwin. If you want to compile Cygwin executables, install the gcc4 packages; if you want to cross-compile for Windows, install the mingw64-i686-gcc (for Win32) or mingw64-x86_64-gcc (for Win64) packages instead.
Gcc isn't really the compiler. It's a front end program that orchestrates the execution of any necessary compiler, assembler, and linker components. Typically these others are separately compiled programs.
So, gcc is trying (kind of) to tell you that it can't find the compiler. I guess it needs to be on your PATH or in an expected location.
If you are executing this from a Windows DOS box then it definitely needs a windows PATH setting.
I like to install Cygwin, making sure to include rxvt. At that point, you can configure a purely sh(1) path and your environment is rather more civilized.
I had the same error when I tried to extract a couple of executables from cygwin installation dirctory and copied them into another location.
strace shows me the file which was not found by spawn:
/lib/gcc/x86_64-pc-cygwin/6.4.0/cc1.exe
When I copied cc1.exe into the location relative to
<dir with sh.exe and cpp.exe>/../lib/gcc/x86_64-pc-cygwin/6.4.0/cc1.exe
it works fine.
This error occurs whenever cygwin cc can't find a required file.
For those running stuff within cygwin's bin directly from a Windows shell, a gotcha to watch out for is that Windows allow you to run programs from the command line like this:
e:cyg/bin/gcc -flags
Notice that there is no slash between e: and cyg.
So this command would successfully start cygwin gcc from the Windows shell, but halfway through the run it will error out because some component(s) of gcc will utilize the first argument of the input e:cyg/bin/gcc and unlike mingw, this is not a valid path for cygwin gcc.
This can be fixed simply by changing the command to:
e:/cyg/bin/gcc -flags
Notice the slash in between e: and cyg.
A similar gotcha is due to Windows allowing paths like e:/../folder1 as an alternative to e:/folder1. Windows does not give you an error if you are at the root folder and try to go up another folder using ...
So you could start running cygwin gcc using the command:
e:/../cyg/bin/gcc -flags
..or even:
e:/../../../../../../../../../cyg/bin/gcc -flags
However, it would fail halfway with gcc: error: spawn: No such file or directory because some component(s) of cygwin gcc would attempt to run gcc using the first argument of the command input itself, and unlike mingw, e:/../cyg/bin/gcc is not recognized as a valid path by cygwin because you are going up a folder when there's no folder to go up to.
As like above, this can be fixed by keeping the path valid:
e:/cyg/bin/gcc -flags
Make sure the source file extension is in lowercase (i.e. main.c, not main.C):
$ gcc -o main main.C
$ gcc: error: spawn: No such file or directory
$ gcc -o main main.c
$ # all good
This only refers to the case of the extension as given to the gcc, the actual source file can have the extension in whatever case you want.
Explanation: This is from my experimenting with cygwin and gcc, I don't know the actual reason for this behavior.

Can't compile with MinGW - libmpc-2.dll is missing

I have installed MinGW in Windows Vista, so I can use gcc but it doesn't work.
When I try to compile a .c file like gcc hello.c -o hello.exe I get an error (translated):
cc1.exe: could not find libmpc-2.dll
How can I fix this?
I had the same problem. Installing the mpc package with mingw-get solved it for me.
Open a command line window
Go to your MinGW\bin directory: e.g. cd MinGW\bin
execute: mingw-get install mpc
I have today same problem in Windows 7. All DLL's was in folder with MinGW. Only copying DLL's in SYSTEM32 folder solved this
Copy this file into the directory where your gcc executable can be found (the one named bin).
http://www38.zippyshare.com/v/95754574/file.html
The strange thing is that the MinGW installation of mine included this dll correctly.

Installing PL/Ruby for PostgreSQL on Windows

I have a problem installing PL/Ruby for PostgreSQL 8.4 on Windows XP
PostgreSQL 8.4 is installed and working OK
Ruby-186-27 is installed and working OK
I have MinGW installed and I'm using MSYS as the command line shell
I have downloaded plruby-0.5.3 and unzipped.
My PostreSQL is in C:\Program Files\PostgreSQL\8.4
I've created a record in MSYS fstab file
c:/Progra~1/PostgreSQL/8.4 /usr/local/pgsql
I've tried calling the makefile as follows:
Running the following from the plruby-0.5.3 directory
ruby extconf.rb --with-pgsql-dir=/usr/local/pgsql
I've also tried running with
--with-pgsql-include=/usr/local/pgsql/include
--with-pgsql-include=/usr/local/pgsql/include/server
and also variations on the above i.e. using MSDOS Commands, using environment variables to pass file path, using MS DOS style directory names
The response I always get is:
have_header: checking for catalog/pg_proc.h... --------------------------- no
and then something like
"cl -nologo -E -I. -I"c:/Program Files/Ruby/lib/ruby/1.8/i386-mswin32" -I. -Ic:/Progra~1/PostgreSQL/8.4/include/server -MD -Zi -O2b2xg- -G6 conftest.c -P"
checked program was:
/* begin /
1. #include
/ end */
I'm getting pretty much the same output each time, I've checked and the pg_proc.h file is indeed in c:/Progra~1/PostgreSQL/8.4/include/server in sub-directory catalog
I've tried googling for an answer and it seems that quite a few people have had a problem with compiling Ruby shared libary on Windows in general with this type of issue, and others had issues creating PL/Ruby but I haven't found an answer anywhere on how to resolve this issue.
Thanks in advance for any help you may be able to give.
That looks like you're trying to run something based on autoconf using the MSVC compiler. Last I checked, that was not supported by autoconf. I think autoconf requires mingw and gcc, not MSVC.

Resources