1``` 2 ___ __ _ _ __ ___ ___ 3 / __| ___ / _` | '__/ _ \/ __| 4 | (_ |___| (_| | | | __/\__ \ 5 \___| \__,_|_| \___||___/ 6 7 How To Compile 8``` 9 10Installing Binary Packages 11========================== 12 13Lots of people download binary distributions of c-ares. This document 14does not describe how to install c-ares using such a binary package. 15This document describes how to compile, build and install c-ares from 16source code. 17 18Building from Git 19================= 20 21If you get your code off a Git repository rather than an official 22release tarball, see the [GIT-INFO](GIT-INFO) file in the root directory 23for specific instructions on how to proceed. 24 25In particular, if not using CMake you will need to run `./buildconf` (Unix) or 26`buildconf.bat` (Windows) to generate build files, and for the former 27you will need a local installation of Autotools. If using CMake the steps are 28the same for both Git and official release tarballs. 29 30AutoTools Build 31=============== 32 33### General Information, works on most Unix Platforms (Linux, FreeBSD, etc.) 34 35A normal Unix installation is made in three or four steps (after you've 36unpacked the source archive): 37 38 ./configure 39 make 40 make install 41 42You probably need to be root when doing the last command. 43 44If you have checked out the sources from the git repository, read the 45[GIT-INFO](GIT-INFO) on how to proceed. 46 47Get a full listing of all available configure options by invoking it like: 48 49 ./configure --help 50 51If you want to install c-ares in a different file hierarchy than /usr/local, 52you need to specify that already when running configure: 53 54 ./configure --prefix=/path/to/c-ares/tree 55 56If you happen to have write permission in that directory, you can do `make 57install` without being root. An example of this would be to make a local 58installation in your own home directory: 59 60 ./configure --prefix=$HOME 61 make 62 make install 63 64### More Options 65 66To force configure to use the standard cc compiler if both cc and gcc are 67present, run configure like 68 69 CC=cc ./configure 70 # or 71 env CC=cc ./configure 72 73To force a static library compile, disable the shared library creation 74by running configure like: 75 76 ./configure --disable-shared 77 78If you're a c-ares developer and use gcc, you might want to enable more 79debug options with the `--enable-debug` option. 80 81### Special Cases 82 83Some versions of uClibc require configuring with `CPPFLAGS=-D_GNU_SOURCE=1` 84to get correct large file support. 85 86The Open Watcom C compiler on Linux requires configuring with the variables: 87 88 ./configure CC=owcc AR="$WATCOM/binl/wlib" AR_FLAGS=-q \ 89 RANLIB=/bin/true STRIP="$WATCOM/binl/wstrip" CFLAGS=-Wextra 90 91 92### CROSS COMPILE 93 94(This section was graciously brought to us by Jim Duey, with additions by 95Dan Fandrich) 96 97Download and unpack the c-ares package. 98 99`cd` to the new directory. (e.g. `cd c-ares-1.7.6`) 100 101Set environment variables to point to the cross-compile toolchain and call 102configure with any options you need. Be sure and specify the `--host` and 103`--build` parameters at configuration time. The following script is an 104example of cross-compiling for the IBM 405GP PowerPC processor using the 105toolchain from MonteVista for Hardhat Linux. 106 107```sh 108#! /bin/sh 109 110export PATH=$PATH:/opt/hardhat/devkit/ppc/405/bin 111export CPPFLAGS="-I/opt/hardhat/devkit/ppc/405/target/usr/include" 112export AR=ppc_405-ar 113export AS=ppc_405-as 114export LD=ppc_405-ld 115export RANLIB=ppc_405-ranlib 116export CC=ppc_405-gcc 117export NM=ppc_405-nm 118 119./configure --target=powerpc-hardhat-linux \ 120 --host=powerpc-hardhat-linux \ 121 --build=i586-pc-linux-gnu \ 122 --prefix=/opt/hardhat/devkit/ppc/405/target/usr/local \ 123 --exec-prefix=/usr/local 124``` 125 126You may also need to provide a parameter like `--with-random=/dev/urandom` 127to configure as it cannot detect the presence of a random number 128generating device for a target system. The `--prefix` parameter 129specifies where c-ares will be installed. If `configure` completes 130successfully, do `make` and `make install` as usual. 131 132In some cases, you may be able to simplify the above commands to as 133little as: 134 135 ./configure --host=ARCH-OS 136 137 138### Cygwin (Windows) 139 140Almost identical to the unix installation. Run the configure script in the 141c-ares root with `sh configure`. Make sure you have the sh executable in 142`/bin/` or you'll see the configure fail toward the end. 143 144Run `make` 145 146 147### QNX 148 149(This section was graciously brought to us by David Bentham) 150 151As QNX is targeted for resource constrained environments, the QNX headers 152set conservative limits. This includes the `FD_SETSIZE` macro, set by default 153to 32. Socket descriptors returned within the c-ares library may exceed this, 154resulting in memory faults/SIGSEGV crashes when passed into `select(..)` 155calls using `fd_set` macros. 156 157A good all-round solution to this is to override the default when building 158c-ares, by overriding `CFLAGS` during configure, example: 159 160 # configure CFLAGS='-DFD_SETSIZE=64 -g -O2' 161 162 163### RISC OS 164 165The library can be cross-compiled using gccsdk as follows: 166 167 CC=riscos-gcc AR=riscos-ar RANLIB='riscos-ar -s' ./configure \ 168 --host=arm-riscos-aof --without-random --disable-shared 169 make 170 171where `riscos-gcc` and `riscos-ar` are links to the gccsdk tools. 172You can then link your program with `c-ares/lib/.libs/libcares.a`. 173 174 175### Android 176 177Method using a configure cross-compile (tested with Android NDK r7b): 178 179 - prepare the toolchain of the Android NDK for standalone use; this can 180 be done by invoking the script: 181 182 ./tools/make-standalone-toolchain.sh 183 184 which creates a usual cross-compile toolchain. Let's assume that you put 185 this toolchain below `/opt` then invoke configure with something 186 like: 187 188 ``` 189 export PATH=/opt/arm-linux-androideabi-4.4.3/bin:$PATH 190 ./configure --host=arm-linux-androideabi [more configure options] 191 make 192 ``` 193 - if you want to compile directly from our GIT repo you might run into 194 this issue with older automake stuff: 195 196 ``` 197 checking host system type... 198 Invalid configuration `arm-linux-androideabi': 199 system `androideabi' not recognized 200 configure: error: /bin/sh ./config.sub arm-linux-androideabi failed 201 ``` 202 this issue can be fixed with using more recent versions of `config.sub` 203 and `config.guess` which can be obtained here: 204 http://git.savannah.gnu.org/gitweb/?p=config.git;a=tree 205 you need to replace your system-own versions which usually can be 206 found in your automake folder: 207 `find /usr -name config.sub` 208 209 210CMake builds 211============ 212 213Current releases of c-ares introduce a CMake v3+ build system that has been 214tested on most platforms including Windows, Linux, FreeBSD, macOS, AIX and 215Solaris. 216 217In the most basic form, building with CMake might look like: 218 219```sh 220cd /path/to/cmake/source 221mkdir build 222cd build 223cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/cares .. 224make 225sudo make install 226``` 227 228Options 229------- 230 231Options to CMake are passed on the command line using "-D${OPTION}=${VALUE}". 232The values defined are all boolean and take values like On, Off, True, False. 233 234| Option Name | Description | Default Value | 235|-----------------------------|-----------------------------------------------------------------------|----------------| 236| CARES_STATIC | Build the static library | Off | 237| CARES_SHARED | Build the shared library | On | 238| CARES_INSTALL | Hook in installation, useful to disable if chain building | On | 239| CARES_STATIC_PIC | Build the static library as position-independent | Off | 240| CARES_BUILD_TESTS | Build and run tests | Off | 241| CARES_BUILD_CONTAINER_TESTS | Build and run container tests (implies CARES_BUILD_TESTS, Linux only) | Off | 242| CARES_BUILD_TOOLS | Build tools | On | 243| CARES_SYMBOL_HIDING | Hide private symbols in shared libraries | Off | 244| CARES_THREADS | Build with thread-safety support | On | 245 246Ninja 247----- 248 249Ninja is the next-generation build system meant for generators like CMake that 250heavily parallelize builds. Its use is very similar to the normal build: 251 252```sh 253cd /path/to/cmake/source 254mkdir build 255cd build 256cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/cares -G "Ninja" .. 257ninja 258sudo ninja install 259``` 260 261Windows MSVC Command Line 262------------------------- 263 264``` 265cd \path\to\cmake\source 266mkdir build 267cd build 268cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=C:\cares -G "NMake Makefiles" .. 269nmake 270nmake install 271``` 272 273Windows MinGW-w64 Command Line via MSYS 274--------------------------------------- 275``` 276cd \path\to\cmake\source 277mkdir build 278cd build 279cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=C:\cares -G "MSYS Makefiles" .. 280make 281make install 282``` 283 284 285Platform-specific build systems 286=============================== 287 288Win32 289----- 290 291### Building Windows DLLs and C run-time (CRT) linkage issues 292 293As a general rule, building a DLL with static CRT linkage is highly 294discouraged, and intermixing CRTs in the same app is something to 295avoid at any cost. 296 297Reading and comprehension of the following Microsoft Learn article 298is a must for any Windows developer. Especially 299important is full understanding if you are not going to follow the 300advice given above. 301 302 - [Use the C Run-Time](https://learn.microsoft.com/en-us/troubleshoot/developer/visualstudio/cpp/libraries/use-c-run-time) 303 304If your app is misbehaving in some strange way, or it is suffering 305from memory corruption, before asking for further help, please try 306first to rebuild every single library your app uses as well as your 307app using the debug multithreaded dynamic C runtime. 308 309 310### MSYS 311 312Building is supported for native windows via both AutoTools and CMake. When 313building with autotools, you can only build either a shared version or a static 314version (use `--disable-shared` or `--disable-static`). CMake can build both 315simultaneously. 316 317All of the MSYS environments are supported: `MINGW32`, `MINGW64`, `UCRT64`, 318`CLANG32`, `CLANG64`, `CLANGARM64`. 319 320### MingW32 321 322Make sure that MinGW32's bin dir is in the search path, for example: 323 324 set PATH=c:\mingw32\bin;%PATH% 325 326then run 'make -f Makefile.m32' in the root dir. 327 328 329### MSVC 6 caveats 330 331If you use MSVC 6 it is required that you use the February 2003 edition PSDK: 332http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdk-full.htm 333 334 335### MSVC from command line 336 337Run the `vcvars32.bat` file to get a proper environment. The 338`vcvars32.bat` file is part of the Microsoft development environment and 339you may find it in `C:\Program Files\Microsoft Visual Studio\vc98\bin` 340provided that you installed Visual C/C++ 6 in the default directory. 341 342Further details in [README.msvc](README.msvc) 343 344 345### Important static c-ares usage note 346 347When building an application that uses the static c-ares library, you must 348add `-DCARES_STATICLIB` to your `CFLAGS`. Otherwise the linker will look for 349dynamic import symbols. 350 351 352DOS 353--- 354 355c-ares supports building as a 32bit protected mode application via 356[DJGPP](https://www.delorie.com/djgpp/). It is recommended to use a DJGPP 357cross compiler from [Andrew Wu](https://github.com/andrewwutw/build-djgpp) 358as building directly in a DOS environment can be difficult. 359 360It is required to also have [Watt-32](https://www.watt-32.net/) available 361built using the same compiler. It is recommended to build the latest `master` 362branch from [GitHub](https://github.com/sezero/watt32/tree/master). 363 364Finally, the `DJ_PREFIX` and `WATT_ROOT` environment variables must be set 365appropriately before calling `make Makefile.dj` to build c-ares. 366 367Please refer to our CI 368[GitHub Actions Workflow](https://github.com/c-ares/c-ares/blob/main/.github/workflows/djgpp.yml) 369for a full build example, including building the latest Watt-32 release. 370 371 372IBM OS/2 373-------- 374 375Building under OS/2 is not much different from building under unix. 376You need: 377 378 - emx 0.9d 379 - GNU make 380 - GNU patch 381 - ksh 382 - GNU bison 383 - GNU file utilities 384 - GNU sed 385 - autoconf 2.13 386 387If during the linking you get an error about `_errno` being an undefined 388symbol referenced from the text segment, you need to add `-D__ST_MT_ERRNO__` 389in your definitions. 390 391If you're getting huge binaries, probably your makefiles have the `-g` in 392`CFLAGS`. 393 394 395NetWare 396------- 397 398To compile `libcares.a` / `libcares.lib` you need: 399 400 - either any gcc / nlmconv, or CodeWarrior 7 PDK 4 or later. 401 - gnu make and awk running on the platform you compile on; 402 native Win32 versions can be downloaded from: 403 http://www.gknw.net/development/prgtools/ 404 - recent Novell LibC SDK available from: 405 http://developer.novell.com/ndk/libc.htm 406 - or recent Novell CLib SDK available from: 407 http://developer.novell.com/ndk/clib.htm 408 409Set a search path to your compiler, linker and tools; on Linux make 410sure that the var `OSTYPE` contains the string 'linux'; set the var 411`NDKBASE` to point to the base of your Novell NDK; and then type 412`make -f Makefile.netware` from the top source directory; 413 414VCPKG 415===== 416 417You can build and install c-ares using [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager: 418 419```sh or powershell 420 git clone https://github.com/Microsoft/vcpkg.git 421 cd vcpkg 422 ./bootstrap-vcpkg.sh 423 ./vcpkg integrate install 424 ./vcpkg install c-ares 425``` 426 427The c-ares port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository. 428 429WATCOM 430===== 431 432To build c-ares with OpenWatcom, you need to have at least version 1.9 of OpenWatcom. You can get the latest version from [http://openwatcom.org/ftp/install/](http://openwatcom.org/ftp/install/). Install the version that corresponds to your current host platform. 433 434After installing OpenWatcom, open a new command prompt and execute the following commands: 435 436``` 437 cd \path\to\cmake\source 438 buildconf.bat 439 wmake -u -f Makefile.Watcom 440``` 441 442After running wmake, you should get adig.exe, ahost.exe, and the static and dynamic versions of libcares. 443 444PORTS 445===== 446 447This is a probably incomplete list of known hardware and operating systems 448that c-ares has been compiled for. If you know a system c-ares compiles and 449runs on, that isn't listed, please let us know! 450 451 - Linux (i686, x86_64, AARCH64, and more) 452 - MacOS 10.4+ 453 - iOS 454 - Windows 8+ (i686, x86_64) 455 - Android (ARM, AARCH64, x86_64) 456 - FreeBSD 457 - NetBSD 458 - OpenBSD 459 - Solaris (SPARC, x86_64) 460 - AIX (POWER) 461 - Tru64 (Alpha) 462 - IRIX (MIPS) 463 - Novell NetWare (i386) 464 465 466Useful URLs 467=========== 468 469 - c-ares: https://c-ares.org/ 470 - MinGW-w64: http://mingw-w64.sourceforge.net/ 471 - MSYS2: https://msys2.org 472 - OpenWatcom: http://www.openwatcom.org/ 473