How do i perform make file in windows - c

i want to use this library https://github.com/json-c/json-c with my C program in codeblocks(windows) but i dont know how to make makefile/cmake on windows.
I dont know how to do it in this particular example. There is only something like "Config.cmake.in".
Any ideas?

You didn't state what kind of build environment you are using on Windows.
So find below a short description how i built the 32-bit version of json library on Windows 10 using cmake 3.14.3 and Visual Studio 2015. CMake supports several generators for Visual Studio as well as MinGW (see CMake documentation).
Open command window (cmd.exe) change to root directory of json-c library source.
Setup build configuration for 32 bit target in directory "build" using command line "cmake -G "Visual Studio 14 2015" -A Win32 -B build"
Open command window for Visual Studio 2015 x86 environment (link at start menu) and change to build directory created during previous step.
Run "msbuild json-c.sln" to build Debug version of json-c dynamic library
Run "msbuild json-c.sln /p:Configuration=Release" to build Release version of json-c dynamic library
After that you should be able to add the built library to your project.

Related

compile putty 0.78 for windows

in the new version of putty there is no Makefile.vc or project file for visual studio. How can I compile putty under visual studio 2019? can someone help me?
link to zipped source
I tried to open the windows folder in visual studio with the following error:
Severity Code Description Project File Line Suppression State
Error CMake Error at C:\Usersuser\Downloads\Compressed\putty-src\windows\CMakeLists.txt:3 (add_sources_from_current_dir):
Unknown CMake command "add_sources_from_current_dir". C:\Users\user\Downloads\Compressed\putty-src\windows\CMakeLists.txt 3
You don't need to open Visual Studio or any IDE to compile the executables.
Download cmake and make sure Visual C compiler is installed.
Unzip the .zip file, open a command prompt where the readme and CMakeLists.txt reside
Then, as the readme states:
run these commands in the source directory:
cmake .
cmake --build .
In the Debug directory, you'll find a lot of .exe files.
Then, to install in the simplest way on Linux or Mac:
cmake --build . --target install
I didn't need that part. I suppose that it copies the executables & other files somewhere in the path.
Problem with creating a distro using Microsoft compiler is that the executables then require a lot of Microsoft runtime DLLs. For instance if you deploy the executables on other machines it may not work.
An alternative is to use gcc and make to build the executables.
First:
install a recent gcc for windows
install make
Installing a recent MinGW distribution should do it. Personally I used another gcc distribution so I had to grab make too.
Now, I followed Setting default compiler in CMake, the key part being to enable mingw makefiles: -G "MinGW Makefiles", else cmake ignores your compiler requirements and keeps on using Microsoft compiler.
cmake -DCMAKE_MAKE_PROGRAM=/path/to/make/make.exe -DCMAKE_C_COMPILER=/path/to/gcc/gcc.exe -G "MinGW Makefiles" .
Note that specifying full paths require that / are used. Backslashes conflict with escaping in cmake/make files.
Then
cmake --build .

installing GSL library for C programming in windows

I want to install the GSL library (https://www.gnu.org/software/gsl/) in windows. I have downloaded the files but i do not know what to do apart from that in order to be able to use the functions of the library (apart from the #include <...> in my program.c file).
I am using visual studio code and i have installed mingw.
Thanks in advance
EDIT
I am adding more information about this issue. I am not the original poster, but I have the same problem.
I am trying to use the GSL and I work with Visual Studio Code on Windows 10.
I have already installed the basic packages to work with C/C++ in
Visual Studio Code. More precisely, if I am not wrong, VS Code is
using the compiler gcc.exe from mingw64 (last version). This was
installed using an 'extension' available at VS Code (https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools).
I downloaded the last version of the GSL (2.7) and unzipped it.
I get stuck when I try to follow the installation instructions. When I
execute either .\configure or ./configure in the DOS command line,
I get an error of "unknown command" (even if I am placed in the same directory where the file is stored).
When I execute .\configure in PowerShell, I get a message asking me
which programme should be used to open this file.
And here is where I get lost. :/
I have discovered an alternate path, which is installing GSL from vcpkg (https://vcpkg.io/). This is suggested by VS Code, actually. This vcpkg seems to be a programme by Microsoft to make it easier to install third-party C/C++ packages in Windows.
The specifications to install vcpkg are (https://vcpkg.io/en/getting-started.html):
Windows 7 or newer
Git
Visual Studio 2015 Update 3 or newer
I can try this path, but first I would like to be sure there is no easier way (installing Visual Studio to not really use it seems a lot to me!).

Where do g++, make and GDB get installed with MinGW?

Please note: Although I'm specifically talking about the Eclipse CDT plugin, I'm almost 100% confident that any Windows/C/MinGW programmer can answer this question.
I'm on Windows 7 and am trying to write and compile a simple "Hello, C!" C application using Eclipse's CDT plugin. I'm reading their docs which state that having GCC installed is a prerequisite.
I just installed MinGW, making sure to include the following packages:
mingw-developer-toolkit
mingw32-base
mingw32-gcc-g++
msys-base
Back in the CDT docs (under the section titled Windows configuration), it states that I need to add g++, make and GDB to my PATH.
I'm wondering where MinGW installs these utilities, so that I can add them to my system PATH, and make the Eclipse CDT recognize their location at startup.
When using the Eclipse CDT plugin, you need GCC and its 3 specific utilities installed locally. These three utilities are: g++, make and gdb.
On Windows you can choose to install these utilities via Cygwin or MinGW. For a MinGW-based solution, go to their site and download the MinGW Package Manager. Then open the manager and install the following packages:
mingw-developer-toolkit
mingw32-base
mingw32-gcc-g++
msys-base
Then go to File >> Apply Updates and apply them. This will install the 3 utilities to the following directories on your machine:
C:\MinGW\bin\g++
C:\MinGW\bin\gdb
C:\MinGW\msys\1.0\make
Add these 3 binaries to your system PATH, restart Eclipse and you are all set.

Windows: How to build X264.lib instead of .dll

I downloaded the X264 source and installed mingw.
Step 1:
Executed this in the MINGW bash:
./configure --disable-cli --enable-shared --enable-win32thread -
-extra-ldflags=-Wl,--output-def=libx264.def
and then 'make'
Step 2:
Renamed the libx264-142.dll to libx264.dll and Opened up VS2012 Command Prompt and executed this:
LIB /DEF:libx264.def
which gave me libx264.lib and object libx264.exp
Step 3:
Included the lib file in a VS2012 project which uses the X264 API.
Problem:
When I start the project I get the following error message:
"The program can't start because libx264.dll is missing from your computer"
Question:
Why is it looking for the dll when I'm linking the static library in?
How do I resolve this? I would like to build a static X264 library which I can link in with my project.
EDIT:
I just had to put the dll in the same directory as the project executable.
However - My question still stands: How do I build a static x264 library? So I don't need the dll?
After the latest update of x264 you can build static library usable by MSVS project. For such library compilation you will need:
MSYS and MSVS 2013 Update 2 (express version [for Windows Desktop] would also work if you install Update 2)
run "VS2013 x86 Native Tools Command Prompt" or "VS2013 x64 Native Tools Command Prompt" depending what version (32 or 64-bit) you want to build
change dir to x264 path and run MSYS shell (sh)
from shell run "CC=cl ./configure --disable-cli --enable-static" for x264 configuring
run "make" which should build libx264.lib usable from MSVS
P.S. MSVS builds would be a little bit slower than one build by MinGW
Matthew Oliver has a GIT repository of a patched x264 source tree (https://github.com/ShiftMediaProject/x264) that compiles natively in VS2013 update 2 and later. It requires installing a YASM version for VS.
It worked pretty much straight out of the box for me, though I did have to change the VSYASM parameter "-f Win32" to "-f win32" for a 32bit build
Take a look here: http://siliconandlithium.blogspot.no/2014/03/building-x264-on-windows-with-visual.html
Static lib is not possible in windows as per my knowledge.

Cross compile GTK+ application from Linux to Windows?

How can I cross compile my GTK+ app (written in C) from Linux to Windows? Could I just replace the "gcc" command with "mingw32"?
Fedora has a great mingw32 cross-compiler toolchain which comes with lots of precompiled libraries, including GTK+ and gtkmm. For most applications you just need to install the cross-compiler and the cross-compiled GTK+ libraries:
yum install mingw32-gcc mingw32-gtk2
Once everything needed is installed, compiling your application is just the matter of running "mingw32-configure" followed with "make".
More information at the project page https://fedoraproject.org/wiki/MinGW
You can use mingw-cross-env - all you have to do then is to change your CC/CXX environment path to use the i686-mingw32- prefix and export the mingw-cross-env bin dirs (both) to your PATH variable (or if you are using autotool it's even easier) - see the documentation on the homepage.
There is actually a project called MXE that does exactly this.
Pre-build package
You can download my pre-build binaries if you want.
Build from source
You can also build the code from scratch ideally also applying this PR to update to the latest GTK 3.24 version.
MXE has a easy wrapper (x86_64-w64-mingw32.static-cmake) to cross-build your project towards Windows, while using Linux. Allowing to evenly statically build your project into a single .exe file! Of course shared builds (x86_64-w64-mingw32.shared-cmake) are also supported. The example wrapper scripts are meant for CMake based projects.
Before you can build your project with MXE, you need to build the GTK3 from source-code. (There are some Linux packages available, but mostly out-dated). If you are using C++, you can also build gtkmm3. Since you are in place C, you only need to build gtk3.
git clone https://github.com/mxe/mxe.git
Become root user: su
mv mxe /opt/mxe
cd /opt/mxe
Build the MXE project yourself:
For static builds under Windows 64-bit for GTK3 & Gtkmm3:
sudo make gtk3 gtkmm3 -j 16 MXE_TARGETS='x86_64-w64-mingw32.static' MXE_PLUGIN_DIRS='plugins/gcc12'
For shared build to Windows 64-bit (again GTK3 + Gtkmm3):
sudo make gtk3 gtkmm3 -j 16 MXE_TARGETS='x86_64-w64-mingw32.shared' MXE_PLUGIN_DIRS='plugins/gcc12'
More info see the tutorial steps on MXE.cc.
Once you done the cross-compile environment / MXE build. Now you can use the CMake wrapper scripts I mentioned earlier. Those scripts are located in the /opt/mxe/usr/bin/ directory.
The scripts (like x86_64-w64-mingw32.static-cmake) can now be used to compile your project towards Windows, while using the Linux operating system. The build result would be an Windows .exe.
Disclaimer: I personally created this PR for MXE to update GTK to the latest 3.24.x release.

Resources