adepierre / Botcraft

Botcraft is a cross-platform C++ library to create bots that connect and interact with Minecraft servers with (optional) integrated OpenGL renderer
GNU General Public License v3.0
405 stars 43 forks source link

Can't find_package Botcraft in CMake after installing it - The following imported targets are referenced, but are missing: protocolCraft #148

Closed GEOEGII555 closed 1 month ago

GEOEGII555 commented 1 month ago

Hi, I recently decided to try out Botcraft, it compiled and installed successfully, however, when I tried to import it, I was hit with a following error:

[cmake] CMake Error at CMakeLists.txt:3 (find_package):
[cmake]   Found package configuration file:
[cmake] 
[cmake]     C:/Program Files (x86)/Botcraft/lib/cmake/botcraft/botcraft-config.cmake
[cmake] 
[cmake]   but it set Botcraft_FOUND to FALSE so package "Botcraft" is considered to
[cmake]   be NOT FOUND.  Reason given by package:
[cmake] 
[cmake]   The following imported targets are referenced, but are missing:
[cmake]   protocolCraft
[cmake] 

I followed the build instructions in the README file, I only disabled encryption and enabled the OpenGL UI. Here's my CMake lists file:

cmake_minimum_required(VERSION 3.29)
project(Bot)

find_package(Botcraft REQUIRED)

add_executable(Bot "main.cpp")
target_include_directories(Bot Botcraft)
target_link_libraries(Botcraft)
adepierre commented 1 month ago

Hello, you also need to find_package protocolCraft for it to work. It is installed at the same time but I'm not sure why it is not automatically added in the cmake find for botcraft.

GEOEGII555 commented 1 month ago

Didn't work, I added find_package(protocolCraft REQUIRED), and this showed up instead:

[cmake] CMake Error at CMakeLists.txt:4 (find_package):
[cmake]   By not providing "FindprotocolCraft.cmake" in CMAKE_MODULE_PATH this
[cmake]   project has asked CMake to find a package configuration file provided by
[cmake]   "protocolCraft", but CMake did not find one.
[cmake] 
[cmake]   Could not find a package configuration file provided by "protocolCraft"
[cmake]   with any of the following names:
[cmake] 
[cmake]     protocolCraftConfig.cmake
[cmake]     protocolcraft-config.cmake
[cmake] 
[cmake]   Add the installation prefix of "protocolCraft" to CMAKE_PREFIX_PATH or set
[cmake]   "protocolCraft_DIR" to a directory containing one of the above files.  If
[cmake]   "protocolCraft" provides a separate development package or SDK, be sure it
[cmake]   has been installed.
adepierre commented 1 month ago

Just to be sure, could you also try with lowercase protocolcraft ?

GEOEGII555 commented 1 month ago

Just to be sure, could you also try with lowercase protocolcraft ?

Same error about it being not found. I'll try reinstalling Botcraft to see if that would somehow fix it (that works sometimes)

GEOEGII555 commented 1 month ago

I got it to work, but it wasn't as simple as copy pasting the commands from the install guide. The cmake install script seems a bit broken. Can't pinpoint the exact issue tho

Edit: the build system fucked itself up once again (I turned on static linking). I also tried to use the add_subdirectory method, but that didn't work for me either, as I got an error about duplicate symbols. I guess I can't use botcraft (I saw the working examples, so it may be an issue on my side)

Edit2: Got it to work with the pre-built version and the following build command: cl /DPROTOCOL_VERSION=767 /MTd /std:c++20 /Ibotcraft\include /EHsc /options:strict /MP /Zi botcraft\lib\protocolCraft.lib botcraft\lib\botcraft.lib main.cpp

Edit3: Now I got it to work with CMake too.