1

I have built the latest version Z3 (https://github.com/Z3Prover/z3) using make and GCC without any problems in the Ubuntu system.

However, I got the following message error when trying to build a small C project that uses the Z3 api:

CMake Error at CMakeLists.txt:9 (find_package):
  By not providing "FindZ3.cmake" in CMAKE_MODULE_PATH this project has asked
  CMake to find a package configuration file provided by "Z3", but CMake did
  not find one.

  Could not find a package configuration file provided by "Z3" with any of
  the following names:

    Z3Config.cmake
    z3-config.cmake

  Add the installation prefix of "Z3" to CMAKE_PREFIX_PATH or set "Z3_DIR" to
  a directory containing one of the above files.  If "Z3" provides a separate
  development package or SDK, be sure it has been installed.

The CMakeLists.txt file looks like this:

cmake_minimum_required(VERSION 3.14)
project(Z3APITest C CXX)

set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_EXTENSIONS OFF)


find_package(Z3 REQUIRED CONFIG /home/roscai/Documents/Tools/Z3/cmake)
message(STATUS "Z3_FOUND: ${Z3_FOUND}")
message(STATUS "Found Z3 ${Z3_VERSION_STRING}")
message(STATUS "Z3_DIR: ${Z3_DIR}")


add_executable(Z3APITest EXCLUDE_FROM ALL main.c)


option(FORCE_CXX_LINKER "Force linker with C++ linker" OFF)
if (FORCE_CXX_LINKER)
    # This is a hack for avoiding UBSan linking errors
    message(STATUS "Forcing use of C++ linker")
    set_target_properties(c_example
            PROPERTIES
            LINKER_LANGUAGE CXX
            )
endif()

include_directories("${Z3_C_INCLUDE_DIR}")
include_directories("${Z3_INCLUDE_DIR}")

target_link_libraries(c_example PRIVATE ${Z3_LIBRARIES})
target_include_directories(c_example PRIVATE ${Z3_C_INCLUDE_DIRS})

UPDATE:

After fixing a type in the code, I got the following error:

 CMake Error at CMakeLists.txt:9 (find_package):
  find_package called with invalid argument
  "/home/roscai/Documents/Tools/Z3/cmake"


-- Z3_FOUND: 
-- Found Z3 
-- Z3_DIR: Z3_DIR-NOTFOUND
CMake Error at CMakeLists.txt:31 (target_link_libraries):
  Cannot specify link libraries for target "c_example" which is not built by
  this project. 

I appreciate any idea how to solve this matter.

Thank you!

  • According to Z3 [source code](https://github.com/Z3Prover/z3/blob/master/CMakeLists.txt#L599), the file `Z3Config.cmake` is a part of z3 installation. Do you have this file? At which path? – Tsyvarev Jul 11 '19 at 10:04
  • Yes, I have it at the following path: ~/Documents/Tools/z3/cmake. It can only be seen when the command ls -al is run. – Roxana Mafteiu-Scai Jul 11 '19 at 11:26
  • It seems that you installed `z3` into **non-system wide** location (`$HOME/Documents/Tools`). You need to inform CMake about that location, and exactly this is described in the paragraph `"Add the installation prefix ...`. E.g. you may set `CMAKE_PREFIX_PATH`, as described in [that my answer](https://stackoverflow.com/questions/34795816/hinting-findname-cmake-files-with-a-custom-directory/34797156#34797156). – Tsyvarev Jul 11 '19 at 11:40
  • Please, fix the typo in the code in the question post and add that error into the post. On Stack Overflow comments are not suitable (and not intended) for the multi-line code. – Tsyvarev Jul 11 '19 at 12:06
  • CMake tells you that your last parameter to `find_package` doesn't fit to the specification of that function, which you can find in the [documentation](https://cmake.org/cmake/help/v3.7/command/find_package.html). If you want to hint `find_package()` about `Z3` location on your machine, you may use `PATH /home/roscai/Documents/Tools/Z3/cmake` option instead. Also note on the error message about `CMakeLists.txt:31` line: you call `target_link_libraries` for target `c_example`, but previous `add_executable` creates `Z3APITest` target. – Tsyvarev Jul 11 '19 at 12:31

0 Answers0