How to use/install GNU binutils (objdump) - windows

I need to use the objdump and readelf commands in my application that runs on windows. I know I can install cygwin in order to use them. The reason why I don't want to use cygwin is because I want to make it essay to deploy. Plus I don't know how to make a silent install of cygwin. As a result I believe that what I need is GNU Utilities For Win32 as the link states those libraries are serverless. "executables do only depend on the Microsoft C-runtime (msvcrt.dll) and not an emulation layer like that provided by Cygwin tools"
Anyways once I go to that link I don't know how to install it. Specifically I will like to use >this tool<
I will appreciate if someone can point me on the right direction of how I will be able to use objdump and readelf (binutils in cygwin) on my application.

they are already compiled and they can be downloaded from here!
Once downloaded they will be located in the bin directory:
and then you will use it the same way you use it on linux by passing the same args.

Related

JSON-C build on Windows Platform

Disclaimer: Please read question carefully, This question has a twist so read it till end.
So JSON-C is one of the highly popular library to work on JSON using C programming. Basic illustration on current work, whatever code building here is for multi-platform. Currently Linux & Windows are supported platform and I have small issue with Windows related JSON-C part.
I'm using Cygwin for Windows development, and when I compile JSON-C code as per provided instruction on it's GitHub page, using CMAKE it works out quite good and build system is able generate DLLs for Windows. But if you have worked with Cygwin then you must know that whatever is built using Cygwin, will have dependency on it's run-time environment (cygwin1.dll) (Why does GCC-Windows depend on cygwin?) and it won't be an independent DLL that can be moved around to different system with same architecture. So with this dependency on Cygwin if my project is built on Windows platform, I have to carry around either Cygwin Run-Time Env. or I have to make sure Cygwin installed on target system for smooth execution. This sort of dependency I do not wish to have for my project, it can ruin user experience.
So what I want as help here, Is there a way to build JSON-C independent of Cygwin (run-time environment)??
NOTE: I already know that, if using Cygwin one wishes to create such an independent DLL for Windows then that can be done using few parameters to compiler and some additional macros placed in-front of function declaration as described here Creating a DLL in GCC or Cygwin?
But I don't see such support in source code JSON-C for Windows. So I was just wondering if JSON-C Dev team has kept some provision via build-system then I'm keen to know that part.
PS: I have not dipped into JSON-C build system yet due to my other development, so if anyone out there (my beloved community) has anything on this then please share, that would be terrific.
EDIT
Forgot to mention the version I'm using :p
json-c-0.13.1-20180305
I am able to build JSON-C 0.14-20200419 (from https://github.com/json-c/json-c) under MSYS2 with MinGW-w64 - both static and shared - using these instructions (replace /usr/local as needed):
INSTALLPREFIX=/usr/local
mkdir -p build_static build_shared &&
cmake.exe -Wno-dev -GNinja -DCMAKE_INSTALL_PREFIX:PATH=$INSTALLPREFIX -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_TESTING:BOOL=OFF -S. -Bbuild_static &&
cmake.exe -Wno-dev -GNinja -DCMAKE_INSTALL_PREFIX:PATH=$INSTALLPREFIX -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=ON -DBUILD_TESTING:BOOL=OFF -S. -Bbuild_shared &&
ninja -Cbuild_static install/strip &&
ninja -Cbuild_shared install/strip &&
echo Success
If you don't have ninja you can probably also use -G"MSYS Makefiles" and use make instead of ninja.
Note that MinGW-w64 is different from Cygwin in that it compiles to native Windows binaries without dependancies on a compatibility layer (like Cygwin's cygwin1.dll). The following screenshots illustrates this:

Linux install command for mingw?

When trying to build a library from source using make and MinGW, I realized (from errors) that I don't have the install command, which I understand to be a combination of cp, chown, chmod, strip, and maybe some other stuff. I figured, hey, someone's got to have a copy of that out there, right? But unfortunately the name of the binary makes it near impossible to search for with any search engine.
Does anyone know of an existing MinGW-compatible version of install?
If you are running MinGW as a cross-compiler, hosted on Linux, (as your question title might be construed to imply), the native /usr/bin/install on the Linux host itself serves admirably; (FWIW, this is exactly how my own MinGW development platform is set up).
OTOH, if you really mean "where can I find a Linux-like install utility to accompany MinGW running on MS-Windows?", then (as Diego notes) you will find it among MinGW.org's MSYS tools; running mingw-get install msys-base will install it for you, (assuming you are using mingw-get to manage your MinGW installation).

How to compile a yacc (.y) file using Bison in Windows environment?

I've read http://dinosaur.compilertools.net/bison/bison_5.html#SEC25. But following those instruction i can not compile my yacc file using bison
How do i compile my file in windows 7 ... ?
Please help me to do this.
There is a common reason why bison will not operate properly on Windows and is mentioned in the install instructions but often overlooked. It is important that the name of the location of the directory that bison (and flex) is installed in (the path) does not contain a space. in particular this means that it cannot be placed under C:\Program Files\. The problem is that this directory might be suggest as the default install location. It is sometimes necessary to manually change the default to somethings else (like C:\GnuWin\ or similar). It is also usually necessary to manually add the appropriate directory to the PATH environment variable. Once this has been done there should be no problems in running bison and flex from the command prompt. It would normally be used in the following way:
flex lang.l
bison lang.y
gcc -o lang.exe lang.tab.c -lfl
It is not necessary to install MinGW, Cygwin or use Powershell or a VM or use linux as indicated by #DavidHefferman
If you still can't get it right, I even have an instructional video!
Using those Unix commands in Windows PowerShell might work, but I'm not sure and I'm currently not on Windows, so I can't check it.
If that fails you could try installing Cygwin (a basic Linux environment in Windows). You'd have to select the bison package during installation. It comes with its own shell that you can use.
Actually my personal favorite when programming under Windows is setting up a virtual machine with VirtualBox. That way you could use a real Linux environment without actually leaving Windows.
Good luck!

Cygwin: How to actually use gcc-mingw

Since "gcc -mno-cygwin" does not work anymore, I was looking for a way to get a MinGW-targeted GCC running within my Cygwin environment. (Running a MSYS environment is not an option at this point.)
The Cygwin installer offers a package "gcc-mingw", which installs, among others:
lib/gcc/i686-pc-mingw32/3.4.4/cc1.exe
lib/gcc/i686-pc-mingw32/3.4.4/collect2.exe
lib/gcc/i686-pc-mingw32/3.4.4/crtbegin.o
lib/gcc/i686-pc-mingw32/3.4.4/crtend.o
What is absent is the "gcc" frontend. So, how do I actually invoke this compiler? I hopefully don't have to go through "cc1" manually, have I?
I googled, but couldn't find anything relevant on the subject...
As you already found, you can use gcc-3 with -mno-cygwin. The other possibility is to install the 32-bit and/or 64-bit toolchains from the MinGW-w64 project, which have been packaged for Cygwin very recently and hence are available through setup.exe now. Don't be put off by the rather confusing executable names: i686-w64-mingw32-gcc is the 32-bit compiler and x86_64-w64-mingw32-gcc is the 64-bit one.
Further searches revealed that the MinGW-targeted cross-compiler is not ready yet, and that one has to either use GCC v3 with -mno-cygwin, or install a cross-compiler manually (see link above)...
After installing the MingW g++ package for Cygwin (mingw64-x86_64-gcc-g++), I also struggled to figure out how to invoke it.
Thanks to this wiki, I found out the command was x86_64-w64-mingw32-g++. Then I did alias g++='x86_64-w64-mingw32-g++' and g++ started working as expected.
Cygwin homepage says that "Individual packages like bash, gcc, less, etc. are released independently of the DLL.".
Here you can find how to install gcc under cygwin, so you should also select gcc package during install not only gcc-mingw.

Compiling with gcc (cygwin on windows)

I have cygwin on windows through which I run gcc. But after creating .exe files, if I run them on other computers which dont have cygwin, it says cygwin1.dll not found. Is there a way to compile them so that they run on any system?
You need to compile for MinGW (Minimal GNU Win32) mode. You do that by either installing mingw instead of (or in addition to) cygwin, or by passing the --mno-cygwin compiler option to the cygwin gcc.
In your case, try to copy cygwin1.dll as well (but it could depend on other DLLs as well) (of course you must comply with Cygwin's license with regards to distributing cygwin1.dll)
In cygwin, you can always check the needed modules using:
objdump -p a.exe | grep 'DLL Name'
OR
cygcheck ./a.exe
or for windows in general, use something like this tool: Dependency Walker
You can try compiling with the command line option -mno-cygwin.
See the Cygwin FAQ.
From http://cygwin.com/faq/faq.html#faq.programming.win32-no-cygwin
How do I compile a Win32 executable that doesn't use Cygwin?
The compilers provided by the mingw-gcc, mingw64-i686-gcc, and mingw64-x86_64-gcc packages link against standard Microsoft DLLs instead of Cygwin. This is desirable for native Windows programs that don't need a UNIX emulation layer.
This is not to be confused with 'MinGW' (Minimalist GNU for Windows), which is a completely separate effort.

Resources