Build In Time Mac OS


This document instructs you on how to set up a Java programming environment for your Mac OS X computer. It also provides a step-by-step guide for creatingand compiling a Java program in IntelliJ and executing itfrom the command line.

You will need a Mac runningMac OS X 10.13 (High Sierra) to Mac OS X 10.15 (Catalina).

You can change the look of the menu bar, desktop picture, Dock, and built-in apps by choosing a light or dark appearance in System Preferences. During downtime, or if you reach the time limit set for apps in Screen Time preferences, app icons are dimmed and an hourglass icon is shown. See Schedule downtime in Screen Time. “Puma” Mac OS X 10.1 (Puma) is the second major release of the Mac OS X, which was released on.


0. Install the Java Programming Environment


The installer installs and configures a Java programming environment, includingOpenJDK 11 andIntelliJ IDEA, Community Edition 2020.1.

  • Log in to the user account in which you will be programming.Your account must have Administrator privileges.
  • Download the Mac OS X installerlift-java.pkg.
  • Double-click lift-java.pkg to install the software.Enter your Mac OS X password when prompted and use all of the default options.

    Warning

    If you have previously used IntelliJ,run this installer only if you want a clean re-install.The installer overwrites IntelliJ IDEA CE.app andany previous IntelliJ 2020.1 settings.

  • Delete lift-java.pkg (if it is not automatically deleted).

1. Open a Project in IntelliJ


You will develop your Java programs in an application called IntelliJ IDEA, Community Edition.

IntelliJ organizes Java programs into projects.In our context, each project corresponds to one programming assignment.A typical project contains Java programs, associated data files, andcourse-specific settings (such as compiler options, style rules, and textbook libraries).

  • Download the project for your programming assignment to a convenient location(such as the Desktop).

    [ sample project for COS 126 (Princeton) ]

    [ sample project for COS 226 (Princeton) ]

    [ sample project for Computer Science: Programming with a Purpose (Coursera) ]

    [ sample project for Algorithms, Part I (Coursera) ]

    • hello.zip

    Double click the zip file to unzip.This creates a project folder with thename of the corresponding programming assignment (such as helloor percolation).Delete the zip file.


    Warning

    The project folders contain course-specific information. Be sure to downloadthe one corresponding to your institution and course.


  • Launch IntelliJ via Finder → Applications → IntelliJ IDEA CE.app.
  • When you launch IntelliJ for the first time,
    • IntelliJ may displaytheJetBrains privacy policy.Scroll down and Accept.
    • IntelliJ may ask if you want to send anonymous usage statistics to JetBrains. Choose your preferred option.
  • To open a project from the Welcome screen,click Open and select the project folder.You should see an assignment logo (in the main editor window) and a list of project files (in the Project View sidebar at left).
    When you launch IntelliJ for the first time,it may take a minute or two to index your files;some features (such as auto importing) will be unavailable until this process completes.


    Warning

    Do not select Create New Project;this option is intended for advanced programmers.Also, always use Open with a project folder, not an individual file.

  • When you are finished working, select the menu optionIntelliJ IDEA → Quit IntelliJ IDEA (⌘Q) to exit IntelliJ.The next time you launch IntelliJ, your recent projectswill appear in the Welcome screen for easy access.

2. Create a Program in IntelliJ


Now you are ready to write your first Java program.IntelliJ features many specialized programming toolsincluding line numbering, syntax highlighting, bracket matching, auto indenting,auto formatting, auto importing, variable renaming, and continuous code inspection.

  • To create a new Java program:
    • Re-open IntelliJ and the project (if you closed it in the previous step).
    • Click the project name in the Project View sidebar (at left), so that itbecomes highlighted.


    • Select the menu option LIFT → New Java Class.When prompted, type HelloWorld for the Name and click OK.


  • In the main editor window, complete the Java programHelloWorld.java exactly as it appears below.(IntelliJ generates the gray boilerplate code automatically,along with the course header block comment.)If you omit even a semicolon, the program won’t work.
  • As you type, IntelliJ highlights different syntactic elementsin different colors.When you type a left bracket, IntelliJ adds the matching right bracket.When you begin a new line, IntelliJ indents it.


  • To save the file, select the menu option File → Save All (⌘S).When you save the file, IntelliJ re-formats it (if necessary).

3. Compile and Execute the Program (from IntelliJ)


Now, it is time to execute (or run) your program.This is the exciting part, where your computer follows the instructionsspecified by your program.Before doing so, you must compile your program intoa form more amenable for execution on a computer.

  • Select the program that you wish to compile and execute in the the Project View sidebar. The program should now appear in the main editor window.
  • To compile your program,select the menu optionLIFT → Recompile 'HelloWorld.java' (⌘B).If the compilation succeeds, you will receive confirmationin the status bar (at bottom).

    If the compilation fails, a Recompile panel will open up (at bottom),highlighting the compile-time errors or warnings.Check your program carefully for typos, using the error messages as a guide.

  • To execute your program,select the menu option LIFT → Run 'HelloWorld' with Arguments (⌘E).Since this program takes no command-line arguments, click OK.

    You should see the output of the program (in white), along with a messagethat the program finished normally (with exit code 0).


Tip

Use the LIFT menu to compile and execute your program from IntelliJ.The Build and Run menus support additional options for advanced programmers.

Also be sure that the main editor window is active before using the LIFTmenu (e.g., by clicking the code you want to compile or execute).

Build In Time Mac OS
4. Compile and Execute the Program (from the command line)


The command line is a simple and powerful mechanism forcontrolling your programs (e.g., command-line arguments,file redirection, and piping).IntelliJ supplies an embedded terminalfor easy access to the command line.

  • Select the menu option View → Tool Windows → Terminal (⌘2).
  • This will launch a Bash terminal where you type commands.You will see a command prompt that looks something like this:

    The ~/Desktop/hello is the current working directory, where~ is shorthand for your home directory.

  • To compile your program,type the following javac command.More specifically, type the text in yellow that appears on the same line as thecommand prompt.Assuming that the file HelloWorld.java is in the current working directory,you should not see any compile-time errors or warnings.
  • To execute your program,type the following java command:You should see the output of your program beneath the line on which you typed the command.


    Tip

    Typically, you should compile from IntelliJ(because IntelliJ highlights the lines on which anycompile-time errors or warnings occur) and execute from the command line(because the command line makes it is easy to specify command-line argumentsand use file redirection).


5. Textbook Libraries (from the command line)


To make our textbook libraries accessible to Java from the command line,you will use our wrapper scripts.

  • Computer Science: An Interdisciplinary Approach (including COS 126 students).The programBarnsley.javauses our standard drawing and standard random libraries in stdlib.jar to draw aBarnsley fern.First download Barnsley.java.Then, use the Finder to move itto a project folder (such as hello).Finally, to compile and execute it,type the following commands in the terminal:When you execute the program, a standard drawing window will appearand an image like this one will be generated, one point at a time:

    To get your command prompt back, close the standard drawing window.

  • Algorithms, 4th Edition (including COS 226 and Coursera students).The programCollidingDisks.javauses various libraries in algs4.jarto simulate the motion of n disks subject to the lawsof elastic collision.First download CollidingDisks.javaThen, use the Finder to move it to a project folder (such as percolation).Finally, to compile and execute it,type the following commands in the terminal:When you execute the program, a standard drawing window will appearwith an animation of 20 colliding disks.To get your command prompt back, close the standard drawing window.


    Frequently Asked Questions



    I installed IntelliJ and Java using the lift-java.pkg installerlast semester or year. Should I rerun this semester?
    Yes. This installer includes IntelliJ 2020.1and Java 11.The old installer may have used an earlier version of IntelliJ or Java.
    I previously used either the introcs.app or algs4.app installer.Should I use the lift-java.pkg installer?
    Yes. This installer includes IntelliJand Java 11 (instead of DrJava and Java 8).
    What happens if I rerun the lift-java.pkg installer?
    It will re-install and re-configure OpenJDK 11, IntelliJ,SpotBugs, PMD, Checkstyle, our textbook libraries,and wrapper scripts.
    The installer failed. How can I investigate why?
    Check the installer log at /var/log/lift.log.
    I have Mac OS X 10.12 (Sierra). Is that too old?
    Yes.Yes. IntelliJ 2020.1 requires Mac OS X 10.13 (or newer).
    How long will the installer take to complete installation?
    Once downloaded, it should take about a minute.If you have anti-malware protection software running (such as McAfee Endpoint), it couldtake 5–10 minutes.
    What does the lift-java.pkg installer do?
    In short, it installs and configures Java, IntelliJ,SpotBugs,PMD,Checkstyle,and our textbook libraries,along with accompanying command-line tools.Here is a more detailed list:
    • Installs OpenJDK 11.0.7.
    • InstallsIntelliJ 2020.1.1with customized user preferences,available indepedently as lift-intellij.pkg.
    • Installs the following command-line tools for Java, available independently aslift-cli.pkg.
      • The textbook librariesstdlib.jar andalgs4.jar.
      • Java wrapper scripts, includingjavac-algs4 and java-algs4.
      • Custom.bashrc,.bash_profile, and.inputrc files.As a precaution, the installer will do this only if detects no preexistingbash configuration files.
      • SpotBugs 4.0.3;our SpotBugs configuration file spotbugs.xml;and wrapper script spotbugs.
      • PMD 6.15.0;our PMD configuration file pmd.xml;and wrapper script pmd.
      • Checkstyle 8.31;various configuration files(checkstyle-cos126.xml,checkstyle-cos226.xml,checkstyle-coursera.xml, andcheckstyle-suppressions.xml);custom checks checkstyle-lift.jar;and wrapper script checkstyle.
    How is the software licensed?
    All of the included software is licensed under various open-source licenses.
    • IntelliJ IDEA, Community Edition is licensed under theApache License, Version 2.0.
    • OpenJDK 11 is licensed under theGNU General Public License,version 2, with the Classpath Exception.
    • SpotBugs is licensed under theGNU Lesser Public License, Version 2.1.
    • Checkstyle is licensed under theGNU Lesser Public License, Version 2.1.
    • PMD is licensed under a BSD-style license.
    • stdlib.jar and algs4.jar are licensed under theGNU General Public License, Version 3.
    What’s the sha256sum of lift-java.pkg?
    e5ef947039280e0b0520fd7bd3aff8a0373719b96b1745c08a42441f6554fafe
    Can I run the installer from the command line?
    Yes. Use the command sudo installer -verbose -pkg lift-java.pkg -target /
    How can I uninstall the software?
    • To uninstall OpenJDK 11,delete the following directory:
      • /Library/Java/JavaVirtualMachines/jdk-11.0.7.jdk/
    • To uninstall IntelliJ, delete the following:
      • /Applications/IntelliJ IDEA CE.app
      • ~/Library/Application Support/JetBrains/IdeaIC2020.1/
      • ~/Library/Caches/JetBrains/IdeaIC2020.1/
      • ~/Library/Logs/JetBrains/IdeaIC2020.1/
    • To uninstall SpotBugs, PMD, Checkstyle,and our textbook libraries, delete the following directory:
      • /usr/local/lift/
    • To uninstall our wrapper scripts, delete the following files:
      • /usr/local/bin/javac-{algs4,introcs}
      • /usr/local/bin/java-{algs4,introcs}
      • /usr/local/bin/jshell-{algs4,introcs}
      • /usr/local/bin/spotbugs
      • /usr/local/bin/pmd
      • /usr/local/bin/checkstyle
    Java FAQ
    Can I use a vendor and version of Java other than OpenJDK 11?
    Yes.You may use any version of Java 8, Java 9, Java 10, or Java 12, from either Oracle or OpenJDK.However, if you do so, you will need to manually configure the Platform SDK and Project SDK viaIntelliJ via File → Project Structure.
    How can I check which version of Java is installed (and where it is installed)?
    Type the following commands in the terminal:It’s important that the Java version numbers match and that you see the number11,but the rest is not critical.
    How does this custom version of IntelliJ different from the standard one?
    IntelliJis an industrial-strength integrated development environment (IDE),suitable for use by professional programmers.The installer configures your user preferences to make itmore suitable for use by novice programmers:
    • Disables all built-in plugins except Terminal and JUnit. Installs the SpotBugs, Checkstyle-IDEA, Run-with-Arguments, Save-Actions, and Archive browser plugins.
    • Eliminates or reduces various popup elements (lightbulbs, code folding, breadcrumbs, gutter markers, notifications, parameter hints).
    • Simplifies menus and toolbars, hiding advanced options.
    • Disables live templates and postfix completion.
    • Adopts the Obsidian Black color scheme.
    • Auto-configures Java upon installation.
    • Adds a few keyboard shortcuts.

    The course-specific project folders perform additional customizations:

    • Streamlines autocomplete to display only relevant libraries(such as java.lang,java.util, and algs4.jar).
    • Configures SpotBugs and Checkstyle with course-specific rules.
    • Provides course-specific libraries (such as algs4.jar).
    • Enables auto-formatting of code on save.
    • Enables auto-importing of Java libraries.
    How can I manually configure the Platform SDK and Project SDK in IntelliJ?
    The installer should configure the Platform SDK automatically.To configure it manually,
    • Navigate to File → Project Structure → Platform Settings → SDKs.
    • Click the + symbol (top left) to add an SDK.
    • Locate an SDK. A typical location for a Java SDK onMac OS X is /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/.
    • Use the shorthand name suggested by IntelliJ(e.g., 11 for version 11.0.7).

    To manually configure the Project SDK,

    • Navigate to File → Project Structure → Project Settings → Project.
    • Choose the desired Project SDK from the drop-down list.
    • Be sure to use 8 as the Project language level, as our autogradercurrently supports only Java 8 features.
    Which are the most important IntelliJ menu options to remember?
    Here are the most important ones (and their shortcuts).
    • LIFT → New Java Class (⌘N). Create a new Java class.
    • LIFT → Recompile (⌘B). Compile the current program.
    • LIFT → Run with Arguments (⌘E). Run the current program with command-line arguments.
    • LIFT → Open in Terminal (⌘T). Open a new Terminal tab.
    • File → Save All (⌘S). Save (and reformat) all open files.
    • View → Tool Windows → Project (⌘1). Show/hide the Project View sidebar.
    • View → Tool Windows → Terminal (⌘2). Show/hide the Terminal window.
    Any special characters to avoid when naming IntelliJ projects or files?
    Do not use an exclamation point (!) as the last characterin the project folder (or any directory name along the path to your project folder);that will confuse both IntelliJ and Checkstyle.
    How can I create a new project in IntelliJ?
    If you want to inherit all of the properties of an existing project,
    • Use the Finder to copy the project folder,giving it your preferred name.
    • Delete any unwanted files.
    • Be sure to keepthe .iml file (which defines the project),the .idea subdirectory (which containsthe IntelliJ course preferences), andthe .lift subdirectory (which contains the courselibraries).

    To create a new project from scratch, you can use the Create New Project option from theWelcome screen. But, we do not recommend this approach for novice programmers.

    Can I use a version of IntelliJ that is more recent than 2020.1.1?
    Yes, though if it is 2020.2 (or above),you will need to migrate your user preferences.
    How I can I restore the original IntelliJ settings(instead of the abbreviated novice-friendly ones)?
    • To restore the menus and toolbars: Preferences → Appearances & Behavior → Menus and Toolbars → Restore All Defaults.
    • To restore all settings: Help → Find Action → Restore Default Settings.
    Command-Line / Embedded Terminal FAQ
    When I compile or execute a program from the command line that uses one of thetextbook libraries, I get an error that it cannot find the library. How can I fix this?
    Make sure that you are using the appropriate wrapper script,such as javac-algs4or java-algs4.
    How should I configure Bash?
    If you followed our instructions, our wrapper scripts (such asjavac-algs4 andjava-algs4)should already be available.

    Our autoinstaller customizes the command line in a few ways by copying these three configuration files:.bashrc,.bash_profile, and.inputrc.Note that the autoinstaller will copy these files only if none of them already exists.If you had previous versions and wish to replace your versions with ours, type the following commands:

    How do I break out of a program in an infinite loop?
    Type Ctrl-C.
    How do I specify EOF to signal that standard input is empty?
    On Mac OS X and Linux, type EnterCtrl-D.On Windows, type EnterCtrl-ZEnter,even in Git Bash.
    How can I run SpotBugs, PMD, and Checkstyle from the command line?
    The installer includes wrapper scripts to simplify this process.
    • To run SpotBugs 4.0.3, type the following command in the terminal:The argument must be a list of .class files.Here is a list ofbug descriptions.
    • To run PMD 6.15.0, type the following command in the terminal:The argument must be either a single .java file ora directory containing one or more .java files.Here is a list of bug patterns.
    • To run Checkstyle 8.31, type one ofthe following commands in the terminal, depending on whether you are COS 126, COS 226, or Coursera student:The argument must be a list of .java files.Here is a list ofavailable checks.

      Due to a bug in the autoinstaller, for this to work, you must update the Checkstyle configfiles to be compatible with Checkstyle 8.31. On OS X, the command is

The following page is a combination of the INSTALL file provided with the OpenSSL library and notes from the field. If you have questions about what you are doing or seeing, then you should consult INSTALL since it contains the commands and specifies the behavior by the development team.

OpenSSL uses a custom build system to configure the library. Configuration will allow the library to set up the recursive makefiles from makefile.org. Once configured, you use make to build the library. You should avoid custom build systems because they often miss details, like each architecture and platform has a unique opensslconf.h and bn.h generated by Configure.

You must use a C compiler to build the OpenSSL library. You cannot use a C++ compiler. Later, once the library is built, it is OK to create user programs with a C++ compiler. But the library proper must be built with a C compiler.

There are two generations of build system. First is the build system used in OpenSSL 1.0.2 and below. The instructions below apply to it. Second is the build system for OpenSSL 1.1.0 and above. The instructions are similar, but not the same. For example, the second generation abandons the monolithic Configure and places individual configurations in the Configurations directory. Also, the second generation is more platform agnostic and uses templates to produce a final, top level build file (Makefile, descrip.mms, what have you).

After you configure and build the library, you should always perform a make test to ensure the library performs as expected under its self tests. If you are building OpenSSL 1.1.0 and above, then you will also need PERL 5.10 or higher (see README.PERL for details).

OpenSSL's build system does not rely upon autotools or libtool. Also see Why aren't tools like 'autoconf' and 'libtool' used? in the OpenSSL FAQ.

  • 2Configuration
  • 3Configure Options
  • 4Compilation
  • 5Platfom specific
    • 5.1Linux
    • 5.2Windows
    • 5.3OpenSSL 1.1.0
    • 5.4OpenSSL 1.0.2
    • 5.6iOS
    • 5.8More

Retrieve source code[edit]

The OpenSSL source code can be downloaded from OpenSSL Source Tarballs or any suitable ftp mirror. There are various versions including stable as well as unstable versions.

The source code is managed via Git. It's referred to as Master. The repository is

git://git.openssl.org/openssl.git

The source is also available via a GitHub mirror. This repository is updated every 15 minutes.

Configuration[edit]

OpenSSL is configured for a particular platform with protocol and behavior options using Configure and config.

You should avoid custom build systems because they often miss details, like each architecture and platform has a unique opensslconf.h and bn.h generated by Configure.

Supported Platforms[edit]

You can run Configure LIST to see a list of available platforms.

If your platform is not listed, then use a similar platform and tune the $cflags and $ldflags by making a copy of the configure line and giving it its own name. $cflags and $ldflags correspond to fields 2 and 6 in a configure line. An example of using a similar configure line is presented in Using RPATHs.

Configure & Config[edit]

You use Configure and config to tune the compile and installation process through options and switches. The difference between is Configure properly handles the host-arch-compiler triplet, and config does not. config attempts to guess the triplet, so it's a lot like autotool's config.guess.

You can usually use config and it will do the right thing (from Ubuntu 13.04, x64):

Mac OS X can have issues (it's often a neglected platform), and you will have to use Configure:

You can also configure on Darwin by exporting KERNEL_BITS:

If you provide a option not known to configure or ask for help, then you get a brief help message:

And if you supply an unknown triplet:

Dependencies[edit]

If you are prompted to run make depend, then you must do so. For OpenSSL 1.0.2 and below, it's required to update the standard distribution once configuration options change.

OpenSSL 1.1.0 and above performs the dependency step for you, so you should not see the message. However, you should perform a make clean to ensure the list of objects files is accurate after a reconfiguration.

Configure Options[edit]

OpenSSL has been around a long time, and it carries around a lot of cruft. For example, from above, SSLv2 is enabled by default. SSLv2 is completely broken, and you should disable it during configuration. You can disable protocols and provide other options through Configure and config, and the following lists some of them.

Note: if you specify a non-existent option, then the configure scripts will proceed without warning. For example, if you inadvertently specify no-sslv2 rather than no-ssl2 no-ssl3, the script will configure with SSLv2 and without warning for the unknown no-sslv2.

Note: when building a shared object, both the static archive and shared objects are built. You do not need to do anything special to build both when shared is specified.

OpenSSL Library Options
Option Description
--prefix=XXX See PREFIX and OPENSSLDIR in the next section (below).
--openssldir=XXX See PREFIX and OPENSSLDIR in the next section (below).
-d Debug build of the library. Optimizations are disabled (no -O3 or similar) and libefence is used (apt-get install electric-fence or yum install electric-fence). TODO: Any other features?
shared Build a shared object in addition to the static archive. You probably need a RPATH when enabling shared to ensure openssl uses the correct libssl and libcrypto after installation.
enable-ec_nistp_64_gcc_128 Use on little endian platforms when GCC supports __uint128_t. ECDH is about 2 to 4 times faster. Not enabled by default because Configure can't determine it. Enable it if your compiler defines __SIZEOF_INT128__, the CPU is little endian and it tolerates unaligned data access.
enable-capieng Enables the Microsoft CAPI engine on Windows platforms. Used to access the Windows Certificate Store. Also see Using Windows certificate store through OpenSSL on the OpenSSL developer list.
no-ssl2 Disables SSLv2. OPENSSL_NO_SSL2 will be defined in the OpenSSL headers.
no-ssl3 Disables SSLv3. OPENSSL_NO_SSL3 will be defined in the OpenSSL headers.
no-comp Disables compression independent of zlib. OPENSSL_NO_COMP will be defined in the OpenSSL headers.
no-idea Disables IDEA algorithm. Unlike RC5 and MDC2, IDEA is enabled by default
no-asm Disables assembly language routines (and uses C routines)
no-dtls Disables DTLS in OpenSSL 1.1.0 and above
no-dtls1 Disables DTLS in OpenSSL 1.0.2 and below
no-shared Disables shared objects (only a static library is created)
no-hw Disables hardware support (useful on mobile devices)
no-engine Disables hardware support (useful on mobile devices)
no-threads Disables threading support.
no-dso Disables the OpenSSL DSO API (the library offers a shared object abstraction layer). If you disable DSO, then you must disable Engines also
no-err Removes all error function names and error reason text to reduce footprint
no-npn/no-nextprotoneg Disables Next Protocol Negotiation (NPN). Use no-nextprotoneg for 1.1.0 and above; and no-npn otherwise
no-psk Disables Preshared Key (PSK). PSK provides mutual authentication independent of trusted authorities, but it's rarely offered or used
no-srp Disables Secure Remote Password (SRP). SRP provides mutual authentication independent of trusted authorities, but it's rarely offered or used
no-ec2m Used when configuring FIPS Capable Library with a FIPS Object Module that only includes prime curves. That is, use this switch if you use openssl-fips-ecp-2.0.5.
no-weak-ssl-ciphers Disables RC4. Available in OpenSSL 1.1.0 and above.
-DXXX Defines XXX. For example, -DOPENSSL_NO_HEARTBEATS.
-DPEDANTIC Defines PEDANTIC. The library will avoid some undefined behavior, like casting an unaligned byte array to a different pointer type. This define should be used if building OpenSSL with undefined behavior sanitizer (-fsanitize=undefined).
-DOPENSSL_USE_IPV6=0 Disables IPv6. Useful if OpenSSL encounters incorrect or inconsistent platform headers and mistakenly enables IPv6. Must be passed to Configure manually.
-DNO_FORK Defines NO_FORK. Disables calls to fork. Useful for operating systems like AppleTVOS, WatchOS, AppleTVSimulator and WatchSimulator.
-Lsomething, -lsomething, -Ksomething, -Wl,something Linker options, will become part of LDFLAGS.
-anythingelse, +anythingelse Compiler options, will become part of CFLAGS.

Note: on older OSes, like CentOS 5, BSD 5, and Windows XP or Vista, you will need to configure with no-async when building OpenSSL 1.1.0 and above. The configuration system does not detect lack of the Posix feature on the platforms.

Note: you can verify compiler support for __uint128_t with the following:

PREFIX and OPENSSLDIR[edit]

--prefix and --openssldir control the configuration of installed components. The behavior and interactions of --prefix and --openssldir are slightly different between OpenSSL 1.0.2 and below, and OpenSSL 1.1.0 and above.

The rule of thumb to use when you want something that 'just works' for all recent versions of OpenSSL, including OpenSSL 1.0.2 and 1.1.0, is:

  • specify both--prefix and --openssldir
  • set --prefix and --openssldir to the same location

One word of caution is avoid--prefix=/usr when OpenSSL versions are notbinary compatible. You will replace the distro's version of OpenSSL with your version of OpenSSL. It will most likely break everything, including the package management system.


OpenSSL 1.0.2 and below

It is usually not necessary to specify --prefix. If --prefix is not specified, then --openssldir is used. However, specifying only--prefix may result in broken builds because the 1.0.2 build system attempts to build in a FIPS configuration.

You can omit If --prefix and use --openssldir. In this case, the paths for --openssldir will be used during configuration. If --openssldir is not specified, the the default /usr/local/ssl is used.

The takeaway is /usr/local/ssl is used by default, and it can be overridden with --openssldir. The rule of thumb applies for path overrides: specify both--prefix and --openssldir.


OpenSSL 1.1.0 and above

OpenSSL 1.1.0 changed the behavior of install rules. You should specify both --prefix and --openssldir to ensure make install works as expected.

The takeaway is /usr/local/ssl is used by default, and it can be overridden with both--prefix and --openssldir. The rule of thumb applies for path overrides: specify both--prefix and --openssldir.

Debug Configuration[edit]

From the list above, it's possible to quickly configure a 'debug' build with ./config -d. However, you can often get into a more amicable state without the Electric Fence dependency by issuing:

Don't be alarmed about both -O3 and -O0. The last setting 'sticks', and that's the -O0.

If you are working in Visual Studio and you can't step into library calls, then see Step into not working, but can force stepping after some asm steps on Stack Overflow.

Modifying Build Settings[edit]

Sometimes you need to work around OpenSSL's selections for building the library. For example, you might want to use -Os for a mobile device (rather than -O3), or you might want to use the clang compiler (rather than gcc).

In case like these, its' often easier to modify Configure and Makefile.org rather than trying to add targets to the configure scripts. Below is a patch that modifies Configure and Makefile.org for use under the iOS 7.0 SDK (which lacks gcc in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/):

  • Modifies Configure to use clang
  • Modifies Makefile.org to use clang
  • Modifies CFLAG to use -Os
  • Modifies MAKEDEPPROG to use $(CC) -M

Setting and resetting of LANG is required on Mac OSX to work around a sed bug or limitation.

After modification, be sure to dclean and configure again so the new settings are picked up:

Using RPATHs[edit]

RPATH's are supported by default on the BSD platforms, but not others. If you are working on Linux and compatibles, then you have to manually add an RPATH. One of the easiest ways to add a RPATH is to configure with it as shown below.

Build in time mac os x

For modern Linux you should also use -Wl,--enable-new-dtags. The linker option sets a RUNPATH as opposed to a RPATH. A RUNPATH allows library path overrides at runtime, while a RPATH does not.

Note well: you should use a RPATH or RUNPATH when building both OpenSSL and your program. If you don't add a RPATH or RUNPATH to both, then your program could runtime-link to the wrong version of OpenSSL. Linking against random versions of a security library is not a good idea.

You can also add an RPATH or RUNPATH by hard coding the RPATH into a configure line. For example, on Debian x86_64 open the file Configure in an editor, copy linux-x86_64, name it linux-x86_64-rpath, and make the following change to add the -rpath option. Notice the addition of -Wl,-rpath=... in two places.

Above, fields 2 and 6 were changed. They correspond to $cflag and $ldflag in OpenSSL's builds system.

Then, Configure with the new configuration:

Finally, after make, verify the settings stuck:

Once you perform make install, then ldd will produce expected results:

FIPS Capable Library[edit]

If you want to use FIPS validated cryptography, you download, build and install the FIPS Object Module (openssl-fips-2.0.5.tar.gz) according to the FIPS User Guide 2.0 and FIPS 140-2 Security Policy. You then download, build and install the FIPS Capable Library (openssl-1.0.1e.tar.gz).

When configuring the FIPS Capable Library, you must use fips as an option:

If you are configuring the FIPS Capable Library with only prime curves (openssl-fips-ecp-2.0.5.tar.gz), then you must configure with no-ec2m:

Compile Time Checking[edit]

If you disable an option during configure, you can check if it's available through OPENSSL_NO_* defines. OpenSSL writes the configure options to <openssl/opensslconf.h>. For example, if you want to know if SSLv3 is available, then you would perform the following in your code:

Compilation[edit]

After configuring the library, you should run make. If prompted, there's usually no need to make depend since you are building from a clean download.

Quick[edit]

Various options can be found examining the Configure file (there is a well commented block at its top). OpenSSL ships with SSLv2, SSLv3 and Compression enabled by default (see my $disabled), so you might want to use no-ssl2 no-ssl3, no-ssl3, and no-comp.

Platfom specific[edit]

Linux[edit]

Intel[edit]

ARM[edit]

X32 (ILP32)[edit]

X32 uses the 32-bit data model (ILP32) on x86_64/amd64. To properly configure for X32 under current OpenSSL distributions, you must use Configure and use the x32 triplet:

Then:

If using an amd64-compatible processor and GCC with that supports __uint128_t, then you usually add enable-ec_nistp_64_gcc_128 in addition to your other flags.

Windows[edit]

3noch wrote a VERY good guide in 2012 here (PLEASE NOTE: the guide was written in 2012 and is no longer available at the original location; the link now points to an archived version at the Internet Archive Wayback Machine).

Like he said in his article, make absolutely sure to create separate directories for 32 and 64 bit versions.

W32 / Windows NT - Windows 9x[edit]

type INSTALL.W32

  • you need Perl for Win32. Unless you will build on Cygwin, you will need ActiveState Perl, available from http://www.activestate.com/ActivePerl.
  • one of the following C compilers:
    • Visual C++
    • Borland C
    • GNU C (Cygwin or MinGW)
  • Netwide Assembler, a.k.a. NASM, available from http://nasm.sourceforge.net/ is required if you intend to utilize assembler modules. Note that NASM is now the only supported assembler.

W64[edit]

Read first the INSTALL.W64 documentation note containing some specific 64bits information.See also INSTALL.W32 that still provides additonnal build information common to both the 64 and 32 bit versions.

You may be surprised: the 64bit artefacts are indeed output in the out32* sub-directories and bear names ending *32.dll. Fact is the 64 bit compile target is so far an incremental change over the legacy 32bit windows target. Numerous compile flags are still labelled '32' although those do apply to both 32 and 64bit targets.

The important pre-requisites are to have PERL available (for essential file processing so as to prepare sources and scripts for the target OS) and of course a C compiler like Microsoft Visual Studio for C/C++. Also note the procedure changed at OpenSSL 1.1.0 and is more streamlined. Also see Why there is no msdo_ms.bat after perl Configure VC-WIN64A on Stack Overflow.

OpenSSL 1.1.0[edit]

For OpenSSL 1.1.0 and above perform these steps:

  1. Ensure you have perl installed on your machine (e.g. ActiveState or Strawberry), and available on your %PATH%
  2. Ensure you have NASM installed on your machine, and available on your %PATH%
  3. Extract the source files to your folder, here cd c:myPathopenssl
  4. Launch Visual Studio tool x64 Cross Tools Command prompt
  5. Goto your defined folder cd c:myPathopenssl
  6. Configure for the target OS with perl Configure VC-WIN64A or other configurations to be found in the INSTALL file (e.g. UNIX targets).
    1. For instance: perl Configure VC-WIN64A.
  7. (Optional) In case you compiled before on 32 or 64-bits, make sure you run nmake clean to prevent trouble across 32 and 64-bits which share output folder.
  8. Now build with: nmake
  9. Output can be found in the root of your folder as libcrypto-1_1x64.dll and libssl-1_1-x64.dll (with all the build additionals such as .pdb .lik or static .lib). You may check this is true 64bit code using the Visual Studio tool 'dumpbin'. For instance dumpbin /headers libcrypto-1_1x64.dll more, and look at the FILE HEADER section.
  10. Test the code using the 'test' make target, by running nmake test.
  11. Reminder, clean your code to prevent issues the next time you compile for a different target. See step 7.

Windows CE[edit]

Not specified

OpenSSL 1.0.2[edit]

For OpenSSL 1.0.2 and earlier the procedure is as follows.

  1. Ensure you have perl installed on your machine (e.g. ActiveState or Strawberry), and available on your %PATH%
  2. Ensure you have NASM installed on your machine, and available on your %PATH%
  3. launch a Visual Studio tool x64 Cross Tools Command prompt
  4. change to the directory where you have copied openssl sources cd c:myPathopenssl
  5. configure for the target OS with the command perl Configure VC-WIN64A. You may also be interested to set more configuration options as documented in the general INSTALL note (for UNIX targets). For instance: perl Configure VC-WIN64A.
  6. prepare the target environment with the command: msdo_win64a
  7. ensure you start afresh and notably without linkable products from a previous 32bit compile (as 32 and 64 bits compiling still share common directories) with the command: nmake -f msntdll.mak clean for the DLL target and nmake -f msnt.mak clean for static libraries.
  8. build the code with: nmake -f msntdll.mak (respectively nmake -f msnt.mak )
  9. the artefacts will be found in sub directories out32dll and out32dll.dbg (respectively out32 and out32.dbg for static libraries). The libcrypto and ssl libraries are still named libeay32.lib and ssleay32.lib, and associated includes in inc32 ! You may check this is true 64bit code using the Visual Studio tool 'dumpbin'. For instance dumpbin /headers out32dll/libeay32.lib more, and look at the FILE HEADER section.
  10. test the code using the various *test.exe programs in out32dll. Use the 'test' make target to run all tests as in nmake -f msntdll.mak test
  11. we recommend that you move/copy needed includes and libraries from the '32' directories under a new explicit directory tree for 64bit applications from where you will import and link your target applications, similar to that explained in INSTALL.W32.

Build In Time Mac Os Download

Windows CE[edit]

OS X[edit]

The earlier discussion presented a lot of information (and some of it had OS X information). Here are the TLDR versions to configure, build and install the library.

If configuring for 64-bit OS X, then use a command similar to:

If configuring for 32-bit OS X, then use a command similar to:

If you want to build a multiarch OpenSSL library, then see this answer on Stack Overflow: Build Multiarch OpenSSL on OS X.

iOS[edit]

The following builds OpenSSL for iOS using the iPhoneOS SDK. The configuration avoids the dynamic library the DSO interface and engines.

If you run make install, then the headers will be installed in /usr/local/openssl-ios/include and libraries will be installed in /usr/local/openssl-ios/lib.

32-bit[edit]

For OpenSSL 1.1.0 and above, a 32-bit iOS cross-compiles uses the ios-cross target, and options similar to --prefix=/usr/local/openssl-ios.

If you are working with OpenSSL 1.0.2 or below, then use the iphoneos-cross target.

64-bit[edit]

For OpenSSL 1.1.0 , a 64-bit iOS cross-compiles uses the ios64-cross target, and --prefix=/usr/local/openssl-ios64. ios64-cross. There is no built-in 64-bit iOS support for OpenSSL 1.0.2 or below.

Android[edit]

Visit Android and FIPS Library and Android.

Build In Time Mac Os X

More[edit]

VAX/VMS[edit]

I you wonder what are files ending with .com like test/testca.com those are VAX/VMX scripts.This code is still maintained.

OS/2[edit]

NetWare[edit]

Build In Time Mac Os Catalina

5.x 6.x

HP-UX[edit]

Autoconf[edit]

OpenSSL uses its own configuration system, and does not use Autoconf. However, a number of popular projects use both OpenSSL and Autoconf, and it would be useful to detect either OPENSSL_init_ssl or SSL_library_init from libssl. To craft a feature test for OpenSSL that recognizes both OPENSSL_init_ssl and SSL_library_init, you can use the following.

Many thanks to the Postgres folks for donating part of their configure.in. Also see How to tell Autoconf “require symbol A or B” from LIB? on Stack Overflow.

Build In Time Mac Os 11

Retrieved from 'https://wiki.openssl.org/index.php?title=Compilation_and_Installation&oldid=3168'