Skip to content

CopperSpice Journal

CopperSpice Journal

Compile, Link, and Run  (Gui Example 1)

Posted on December 22, 2021April 1, 2025 By Barbara Geller

The basic steps to create a executable program, in a computer language like C++, requires first compiling the source code and then linking this output with various libraries. The result will be an executable binary file.

The file structure for the first few examples should look similar to the following layout.

  • example_1
    • build ( note A )
    • deploy ( note B )
    • main.cpp ( note C )
    • CMakeLists.txt ( note D )

Note A: Folder created in the build script shown below
Note B: Folder created in the build script shown below
Note C: This file was created in Source Code (Gui Example 1)
Note D: This file was created in Build File (Gui Example 1)

We are using CMake as our build system so this process will require configuring CMake and then building the program. Select the appropriate section to proceed.

  • Building an Application on Debian
  • Building an Application on Fedora
  • Building an Application on Ubuntu
  • Building an Application on Arch
  • Building an Application on FreeBSD
  • Building an Application on Rocky
  • Building an Application on Windows using MSVC
  • Building an Application on Windows using MinGW
  • Building an Application on Mac OS X

Building an Application on Unix or Linux

The directions to build and run an application which will link with CopperSpice is the same procedure for all Unix and Linux platforms. We suggest saving the following commands to a script.

mkdir -p build
cd build

cmake -G "Ninja" \
   -DCMAKE_PREFIX_PATH=~/cs_lib/lib/cmake/CopperSpice \
   -DCMAKE_BUILD_TYPE=Release \
   -DCMAKE_INSTALL_PREFIX=../deploy \
   ..

ninja install

Line 5 sets a CMake variable indicating a path where the build system can find the CopperSpice CMake export files. You will need to adjust this path to match the exact location where CS is installed on your system.

CMake will generate several temporary files in the build directory. The deploy directory will contain all the files necessary to run the program. If you are distributing this program every file in the deploy folder must be provided.

Building an Application on Windows using MSVC

We suggest saving the following commands to a batch file.

md build
cd build

cmake -G "Ninja" ^
   -DCMAKE_PREFIX_PATH=c:\cs_lib\cmake\CopperSpice ^
   -DCMAKE_BUILD_TYPE=Release ^
   -DCMAKE_INSTALL_PREFIX=..\deploy ^
   ..

ninja install

Line 5 sets a CMake variable indicating a path where the build system can find the CopperSpice CMake export files. You will need to adjust this path to match the exact location where CS is installed on your system.

CMake will generate several temporary files in the build directory. The deploy directory will contain all the files necessary to run the program. If you are distributing this program every file in the deploy folder must be provided.

Building an Application on Windows

We suggest saving the following commands to a bash script.

mkdir -p build
cd build

cmake -G "Ninja" \
   -DCMAKE_PREFIX_PATH=/c/cs_lib/cmake/CopperSpice \
   -DCMAKE_BUILD_TYPE=Release \
   -DCMAKE_INSTALL_PREFIX=../deploy \
   ..

ninja install

Line 5 sets a CMake variable indicating a path where the build system can find the CopperSpice CMake export files. You will need to adjust this path to match the exact location where CS is installed on your system.

CMake will generate several temporary files in the build directory. The deploy directory will contain all the files necessary to run the program. If you are distributing this program every file in the deploy folder must be provided.

Building an Application on Mac OS X

We suggest saving the following commands to a script.

mkdir -p build
cd build

cmake -G "Ninja" \ 
   -DCMAKE_PREFIX_PATH=~/cs_lib \
   -DCMAKE_BUILD_TYPE=Release \
   -DCMAKE_INSTALL_PREFIX=../deploy \
   ..

ninja install

Line 5 sets a CMake variable indicating a path where the build system can find the CopperSpice CMake export files. You will need to adjust this path to match the exact location where CS is installed on your system.

CMake will generate several temporary files in the build directory. The deploy directory will contain all the files necessary to run the program. If you are distributing this program every file in the deploy folder must be provided.

Running the Example

The full source code, CMake build files, and bash scripts can be found in the following zip file.

https://download.copperspice.com/journal/example_01.zip

Uncategorized

Post navigation

Previous Post: Build File  (Gui Example 1)
Next Post: Source Code  (Gui Example 2)
  • CopperSpice Journal Homepage
    • Table of Contents
    • Example Source Code
    • Discussion Forum
  • CopperSpice Homepage
  • Github Repository
  • Videos About C++

Post comments or questions on our CopperSpice Forum

Copyright © 2021-2025 CopperSpice