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