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

Confusing CMake error. #47

Closed Whanos closed 3 years ago

Whanos commented 3 years ago

Hey there!

Having a fun issue when compiling the program.

I followed your example here: https://github.com/adepierre/Botcraft/discussions/45

When making the program, I encountered the error:

CMake Error at Botcraft/botcraft/CMakeLists.txt:127 (add_library):
  Target "botcraft" links to target "ZLIB::ZLIB" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

Full log: https://hastebin.com/yujutikefi.yaml

Thanks!

adepierre commented 3 years ago

That's weird indeed. By looking at the full log, I can see that cmake detected that you don't have Zlib. It triggers the clone/build of Zlib correctly. However, it seems that the build did not go well. I think the best clue is at line 39:

'C:\Program' is not recognized as an internal or external command

So basically the problem is that you have a space in the path to your mingw installation, and boom.

Installing mingw in a different location should workd. Alternatively, you could try this stack overflow solution that seems to be about the same issue (adding the path to windres.exe to your system path and specifying -DCMAKE_RC_COMPILER=windres in your cmake command).

Whanos commented 3 years ago

That fixed the issue, but now I have a new issue -

C:\Users\Whanos\AppData\Local\Temp\cc8fvn3S.s: Fatal error: can't write 166 bytes to section .text of CMakeFiles\protocolCraft.dir\src\BaseMessage.cpp.obj: 'File too big'
X:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/as.exe: CMakeFiles\protocolCraft.dir\src\BaseMessage.cpp.obj: too many sections (36192)

I believe this can be fixed using https://github.com/google/googletest/issues/1841#issuecomment-422342176 but I'm really not sure how - CMake is a mystery to me

adepierre commented 3 years ago

That's even wierder. Mingw is definitely full of surprises.

If you want to try the fix given in your link you just have to add

if (MINGW)
    target_compile_options(protocolCraft PRIVATE "-Wa,-mbig-obj")
endif()

in protocolCraft/CMakeLists.txt somewhere near line 310 (and if you have the same issue for Botcraft, it will be in botcraft/CMakeLists.txt at line 131).

Whanos commented 3 years ago

That worked!

For botcraft, insert

if (MINGW)
    target_compile_options(botcraft PRIVATE "-Wa,-mbig-obj")
endif()

at line 131, just before the if(MSVC)

buuuuut a new fun error has shown itself

X:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lZLIB::ZLIB
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Botcraft\botcraft\CMakeFiles\botcraft.dir\build.make:466: ../bin/libbotcraft_d.dll] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:201: Botcraft/botcraft/CMakeFiles/botcraft.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:156: BotCode/CMakeFiles/BotCode.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:168: BotCode] Error 2
adepierre commented 3 years ago

I'm sorry I've never used mingw and I've no idea on how it works (or doesn't). It seems that it does not understand that ZLIB::ZLIB is a target and not the name of the library? I don't know.

Could you try to add that at the end of cmake/zlib.cmake and reconfigure with cmake

if(NOT TARGET ZLIB::ZLIB)
    message(WARNING "ZLIB::ZLIB is not a target")
endif()
Whanos commented 3 years ago

Tried building: Output:

[ 44%] Built target protocolCraft
[ 46%] Linking CXX shared library ..\..\..\bin\libbotcraft_d.dll
X:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lZLIB::ZLIB
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Botcraft\botcraft\CMakeFiles\botcraft.dir\build.make:466: ../bin/libbotcraft_d.dll] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:201: Botcraft/botcraft/CMakeFiles/botcraft.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:156: BotCode/CMakeFiles/BotCode.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:168: BotCode] Error 2
Whanos commented 3 years ago

if I click "reload project" I get this new output:

CMake Error at Botcraft/botcraft/CMakeLists.txt:127 (add_library):
  Target "botcraft" links to target "ZLIB::ZLIB" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
adepierre commented 3 years ago

You need to understand that I have no idea what you are using. Cmake is a command line tool, so the "reload project" button is definitely not a base cmake thing.

You should try to close everything, delete your build folder and start from a clean state. And if you still have an issue, post the full log as in your initial post, otherwise there is absolutely no way I can even try to guess what's going on.

Whanos commented 3 years ago

I'll try to fix MSVC and see if that fixes it. I used MinGW because MSVC was broken beyond belief for some reason. Thanks for your help