INSTALL.md (15365B)
1 ``` 2 ___ __ _ _ __ ___ ___ 3 / __| ___ / _` | '__/ _ \/ __| 4 | (_ |___| (_| | | | __/\__ \ 5 \___| \__,_|_| \___||___/ 6 7 How To Compile 8 ``` 9 10 Installing Binary Packages 11 ========================== 12 13 Lots of people download binary distributions of c-ares. This document 14 does not describe how to install c-ares using such a binary package. 15 This document describes how to compile, build and install c-ares from 16 source code. 17 18 Building from Git 19 ================= 20 21 If you get your code off a Git repository rather than an official 22 release tarball, see the [GIT-INFO](GIT-INFO) file in the root directory 23 for specific instructions on how to proceed. 24 25 In 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 27 you will need a local installation of Autotools. If using CMake the steps are 28 the same for both Git and official release tarballs. 29 30 AutoTools Build 31 =============== 32 33 ### General Information, works on most Unix Platforms (Linux, FreeBSD, etc.) 34 35 A normal Unix installation is made in three or four steps (after you've 36 unpacked the source archive): 37 38 ./configure 39 make 40 make install 41 42 You probably need to be root when doing the last command. 43 44 If you have checked out the sources from the git repository, read the 45 [GIT-INFO](GIT-INFO) on how to proceed. 46 47 Get a full listing of all available configure options by invoking it like: 48 49 ./configure --help 50 51 If you want to install c-ares in a different file hierarchy than /usr/local, 52 you need to specify that already when running configure: 53 54 ./configure --prefix=/path/to/c-ares/tree 55 56 If you happen to have write permission in that directory, you can do `make 57 install` without being root. An example of this would be to make a local 58 installation in your own home directory: 59 60 ./configure --prefix=$HOME 61 make 62 make install 63 64 ### More Options 65 66 To force configure to use the standard cc compiler if both cc and gcc are 67 present, run configure like 68 69 CC=cc ./configure 70 # or 71 env CC=cc ./configure 72 73 To force a static library compile, disable the shared library creation 74 by running configure like: 75 76 ./configure --disable-shared 77 78 If you're a c-ares developer and use gcc, you might want to enable more 79 debug options with the `--enable-debug` option. 80 81 ### Special Cases 82 83 Some versions of uClibc require configuring with `CPPFLAGS=-D_GNU_SOURCE=1` 84 to get correct large file support. 85 86 The 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 95 Dan Fandrich) 96 97 Download and unpack the c-ares package. 98 99 `cd` to the new directory. (e.g. `cd c-ares-1.7.6`) 100 101 Set environment variables to point to the cross-compile toolchain and call 102 configure with any options you need. Be sure and specify the `--host` and 103 `--build` parameters at configuration time. The following script is an 104 example of cross-compiling for the IBM 405GP PowerPC processor using the 105 toolchain from MonteVista for Hardhat Linux. 106 107 ```sh 108 #! /bin/sh 109 110 export PATH=$PATH:/opt/hardhat/devkit/ppc/405/bin 111 export CPPFLAGS="-I/opt/hardhat/devkit/ppc/405/target/usr/include" 112 export AR=ppc_405-ar 113 export AS=ppc_405-as 114 export LD=ppc_405-ld 115 export RANLIB=ppc_405-ranlib 116 export CC=ppc_405-gcc 117 export 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 126 You may also need to provide a parameter like `--with-random=/dev/urandom` 127 to configure as it cannot detect the presence of a random number 128 generating device for a target system. The `--prefix` parameter 129 specifies where c-ares will be installed. If `configure` completes 130 successfully, do `make` and `make install` as usual. 131 132 In some cases, you may be able to simplify the above commands to as 133 little as: 134 135 ./configure --host=ARCH-OS 136 137 138 ### Cygwin (Windows) 139 140 Almost identical to the unix installation. Run the configure script in the 141 c-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 144 Run `make` 145 146 147 ### QNX 148 149 (This section was graciously brought to us by David Bentham) 150 151 As QNX is targeted for resource constrained environments, the QNX headers 152 set conservative limits. This includes the `FD_SETSIZE` macro, set by default 153 to 32. Socket descriptors returned within the c-ares library may exceed this, 154 resulting in memory faults/SIGSEGV crashes when passed into `select(..)` 155 calls using `fd_set` macros. 156 157 A good all-round solution to this is to override the default when building 158 c-ares, by overriding `CFLAGS` during configure, example: 159 160 # configure CFLAGS='-DFD_SETSIZE=64 -g -O2' 161 162 163 ### RISC OS 164 165 The 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 171 where `riscos-gcc` and `riscos-ar` are links to the gccsdk tools. 172 You can then link your program with `c-ares/lib/.libs/libcares.a`. 173 174 175 ### Android 176 177 Method 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 210 CMake builds 211 ============ 212 213 Current releases of c-ares introduce a CMake v3+ build system that has been 214 tested on most platforms including Windows, Linux, FreeBSD, macOS, AIX and 215 Solaris. 216 217 In the most basic form, building with CMake might look like: 218 219 ```sh 220 cd /path/to/cmake/source 221 mkdir build 222 cd build 223 cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/cares .. 224 make 225 sudo make install 226 ``` 227 228 Options 229 ------- 230 231 Options to CMake are passed on the command line using "-D${OPTION}=${VALUE}". 232 The 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 246 Ninja 247 ----- 248 249 Ninja is the next-generation build system meant for generators like CMake that 250 heavily parallelize builds. Its use is very similar to the normal build: 251 252 ```sh 253 cd /path/to/cmake/source 254 mkdir build 255 cd build 256 cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/cares -G "Ninja" .. 257 ninja 258 sudo ninja install 259 ``` 260 261 Windows MSVC Command Line 262 ------------------------- 263 264 ``` 265 cd \path\to\cmake\source 266 mkdir build 267 cd build 268 cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=C:\cares -G "NMake Makefiles" .. 269 nmake 270 nmake install 271 ``` 272 273 Windows MinGW-w64 Command Line via MSYS 274 --------------------------------------- 275 ``` 276 cd \path\to\cmake\source 277 mkdir build 278 cd build 279 cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=C:\cares -G "MSYS Makefiles" .. 280 make 281 make install 282 ``` 283 284 285 Platform-specific build systems 286 =============================== 287 288 Win32 289 ----- 290 291 ### Building Windows DLLs and C run-time (CRT) linkage issues 292 293 As a general rule, building a DLL with static CRT linkage is highly 294 discouraged, and intermixing CRTs in the same app is something to 295 avoid at any cost. 296 297 Reading and comprehension of the following Microsoft Learn article 298 is a must for any Windows developer. Especially 299 important is full understanding if you are not going to follow the 300 advice 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 304 If your app is misbehaving in some strange way, or it is suffering 305 from memory corruption, before asking for further help, please try 306 first to rebuild every single library your app uses as well as your 307 app using the debug multithreaded dynamic C runtime. 308 309 310 ### MSYS 311 312 Building is supported for native windows via both AutoTools and CMake. When 313 building with autotools, you can only build either a shared version or a static 314 version (use `--disable-shared` or `--disable-static`). CMake can build both 315 simultaneously. 316 317 All of the MSYS environments are supported: `MINGW32`, `MINGW64`, `UCRT64`, 318 `CLANG32`, `CLANG64`, `CLANGARM64`. 319 320 ### MingW32 321 322 Make sure that MinGW32's bin dir is in the search path, for example: 323 324 set PATH=c:\mingw32\bin;%PATH% 325 326 then run 'make -f Makefile.m32' in the root dir. 327 328 329 ### MSVC 6 caveats 330 331 If you use MSVC 6 it is required that you use the February 2003 edition PSDK: 332 http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdk-full.htm 333 334 335 ### MSVC from command line 336 337 Run the `vcvars32.bat` file to get a proper environment. The 338 `vcvars32.bat` file is part of the Microsoft development environment and 339 you may find it in `C:\Program Files\Microsoft Visual Studio\vc98\bin` 340 provided that you installed Visual C/C++ 6 in the default directory. 341 342 Further details in [README.msvc](README.msvc) 343 344 345 ### Important static c-ares usage note 346 347 When building an application that uses the static c-ares library, you must 348 add `-DCARES_STATICLIB` to your `CFLAGS`. Otherwise the linker will look for 349 dynamic import symbols. 350 351 352 DOS 353 --- 354 355 c-ares supports building as a 32bit protected mode application via 356 [DJGPP](https://www.delorie.com/djgpp/). It is recommended to use a DJGPP 357 cross compiler from [Andrew Wu](https://github.com/andrewwutw/build-djgpp) 358 as building directly in a DOS environment can be difficult. 359 360 It is required to also have [Watt-32](https://www.watt-32.net/) available 361 built using the same compiler. It is recommended to build the latest `master` 362 branch from [GitHub](https://github.com/sezero/watt32/tree/master). 363 364 Finally, the `DJ_PREFIX` and `WATT_ROOT` environment variables must be set 365 appropriately before calling `make Makefile.dj` to build c-ares. 366 367 Please refer to our CI 368 [GitHub Actions Workflow](https://github.com/c-ares/c-ares/blob/main/.github/workflows/djgpp.yml) 369 for a full build example, including building the latest Watt-32 release. 370 371 372 IBM OS/2 373 -------- 374 375 Building under OS/2 is not much different from building under unix. 376 You 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 387 If during the linking you get an error about `_errno` being an undefined 388 symbol referenced from the text segment, you need to add `-D__ST_MT_ERRNO__` 389 in your definitions. 390 391 If you're getting huge binaries, probably your makefiles have the `-g` in 392 `CFLAGS`. 393 394 395 NetWare 396 ------- 397 398 To 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 409 Set a search path to your compiler, linker and tools; on Linux make 410 sure 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 414 VCPKG 415 ===== 416 417 You 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 427 The 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 429 WATCOM 430 ===== 431 432 To 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 434 After 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 442 After running wmake, you should get adig.exe, ahost.exe, and the static and dynamic versions of libcares. 443 444 PORTS 445 ===== 446 447 This is a probably incomplete list of known hardware and operating systems 448 that c-ares has been compiled for. If you know a system c-ares compiles and 449 runs 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 466 Useful 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/