Skip to content

How to: Build a pylon-Based Application with CMake on macOS#

Issue#

If you set up the pylon include directory manually for CMake, compiling your project may fail with the following error message:

/Library/Frameworks/pylon.framework/Headers/PylonIncludes.h:23:10: fatal error: 'Base/GCTypes.h'

Solution#

Create a pylon directory in /Library/Frameworks/pylon.framework/Headers and copy all header files from /Library/Frameworks/pylon.framework/Headers into the new directory. Example:

cp /Library/Frameworks/pylon.framework/Headers/*.h /Library/Frameworks/pylon.framework/Headers/pylon

Then create a CMakeLists.txt file using the following template. The script below compiles a "Grab.cpp" code sample, which you can download here.

cmake_minimum_required (VERSION 2.6)
project (Grab)

# The version number.
set (Tutorial_VERSION_MAJOR 1)
set (Tutorial_VERSION_MINOR 0)

set(CMAKE_CXX_STANDARD 11)

#set(PYLON_LIBRARY_DIR "/Library/Frameworks")
#set(PYLONINCLUDEPATH, "${PYLON_LIBRARY_DIR}/pylon.framework/Headers/")

include_directories(/Library/Frameworks/pylon.framework/Headers/ /Library/Frameworks/pylon.framework/Headers/GenICam/)

#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl, -E")

set(BESLER_LIBRARIES
 pylonbase
 pylonutility
 GenApi_gcc_v3_1_Basler_pylon_v5_1
 GCBase_gcc_v3_1_Basler_pylon_v5_1
)

link_directories(/Library/Frameworks/pylon.framework/Libraries/)

# add the executable
add_executable(Grab Grab.cpp)
target_link_libraries(Grab ${BESLER_LIBRARIES})

Set the following environment variable to make sure that the pylon-based application finds the pylon libs in runtime.

export DYLD_LIBRARY_PATH="/Library/Frameworks/pylon.framework/Libraries"

To build the test sample:

  1. Copy both Grab.cpp and the CMakeLists.txt file to the target system into a directory of your choice.
  2. Create a build subdirectory
  3. Change your working directory to build
  4. Call cmake ...

Back to Knowledge Articles