diff --git a/contrib/cmake/examples/c++/CMakeLists.txt b/contrib/cmake/examples/c++/CMakeLists.txt
index 85bbd77c7..fdc5cf387 100644
--- a/contrib/cmake/examples/c++/CMakeLists.txt
+++ b/contrib/cmake/examples/c++/CMakeLists.txt
@@ -1,4 +1,9 @@
+# FIXME: We should build this as an external project and consume
+# Z3 as `find_package(z3 CONFIG)`.
 add_executable(cpp_example EXCLUDE_FROM_ALL example.cpp)
 target_link_libraries(cpp_example PRIVATE libz3)
 target_include_directories(cpp_example PRIVATE "${CMAKE_SOURCE_DIR}/src/api")
 target_include_directories(cpp_example PRIVATE "${CMAKE_SOURCE_DIR}/src/api/c++")
+if (NOT BUILD_LIBZ3_SHARED)
+  z3_append_linker_flag_list_to_target(cpp_example ${Z3_DEPENDENT_EXTRA_CXX_LINK_FLAGS})
+endif()
diff --git a/contrib/cmake/examples/c/CMakeLists.txt b/contrib/cmake/examples/c/CMakeLists.txt
index 1a14573ac..fc6eaee18 100644
--- a/contrib/cmake/examples/c/CMakeLists.txt
+++ b/contrib/cmake/examples/c/CMakeLists.txt
@@ -1,3 +1,9 @@
+# FIXME: We should build this as an external project and consume
+# Z3 as `find_package(z3 CONFIG)`.
 add_executable(c_example EXCLUDE_FROM_ALL test_capi.c)
 target_link_libraries(c_example PRIVATE libz3)
 target_include_directories(c_example PRIVATE "${CMAKE_SOURCE_DIR}/src/api")
+# This is needed for when libz3 is built as a static library
+if (NOT BUILD_LIBZ3_SHARED)
+  z3_append_linker_flag_list_to_target(c_example ${Z3_DEPENDENT_EXTRA_C_LINK_FLAGS})
+endif()