Dune-II---The-Maker icon indicating copy to clipboard operation
Dune-II---The-Maker copied to clipboard

ubuntu - selection of gcc-11 as the default or preferred compiler (and if missing, either fail, or optionally fallback to using another installed compiler)

Open dreamcat4 opened this issue 3 years ago • 14 comments

Followed the instructions, ran the install_dependencies_ubuntu.sh, got the same exact compile error message as before. This is on ubuntu 21.04.

[ 53%] Building CXX object CMakeFiles/d2tm.dir/gameobjects/units/cUnitUtils.cpp.o
[ 54%] Building CXX object CMakeFiles/d2tm.dir/gamestates/cChooseHouseGameState.cpp.o
[ 54%] Building CXX object CMakeFiles/d2tm.dir/gamestates/cCreditsState.cpp.o
[ 55%] Building CXX object CMakeFiles/d2tm.dir/gamestates/cGameState.cpp.o
[ 56%] Building CXX object CMakeFiles/d2tm.dir/gamestates/cMainMenuGameState.cpp.o
[ 56%] Building CXX object CMakeFiles/d2tm.dir/gamestates/cOptionsState.cpp.o
[ 57%] Building CXX object CMakeFiles/d2tm.dir/gamestates/cSelectYourNextConquestState.cpp.o
[ 57%] Building CXX object CMakeFiles/d2tm.dir/gamestates/cSetupSkirmishGameState.cpp.o
[ 58%] Building CXX object CMakeFiles/d2tm.dir/gui.cpp.o
[ 59%] Building CXX object CMakeFiles/d2tm.dir/gui/actions/cGuiActionExitGame.cpp.o
[ 59%] Building CXX object CMakeFiles/d2tm.dir/gui/actions/cGuiActionFadeOutOnly.cpp.o
[ 60%] Building CXX object CMakeFiles/d2tm.dir/gui/actions/cGuiActionSelectHouse.cpp.o
[ 61%] Building CXX object CMakeFiles/d2tm.dir/gui/actions/cGuiActionSetupSkirmishGame.cpp.o
[ 61%] Building CXX object CMakeFiles/d2tm.dir/gui/actions/cGuiActionShowOptions.cpp.o
[ 62%] Building CXX object CMakeFiles/d2tm.dir/gui/actions/cGuiActionStartNewSkirmishGame.cpp.o
[ 63%] Building CXX object CMakeFiles/d2tm.dir/gui/actions/cGuiActionToGameState.cpp.o
[ 63%] Building CXX object CMakeFiles/d2tm.dir/gui/cGuiAction.cpp.o
[ 64%] Building CXX object CMakeFiles/d2tm.dir/gui/cGuiButton.cpp.o
[ 64%] Building CXX object CMakeFiles/d2tm.dir/gui/cGuiWindow.cpp.o
[ 65%] Building CXX object CMakeFiles/d2tm.dir/gui/cMouseToolTip.cpp.o
[ 66%] Building CXX object CMakeFiles/d2tm.dir/gui/cTextWriter.cpp.o
[ 66%] Building CXX object CMakeFiles/d2tm.dir/ini.cpp.o
[ 67%] Building CXX object CMakeFiles/d2tm.dir/main.cpp.o
[ 68%] Building CXX object CMakeFiles/d2tm.dir/managers/cDrawManager.cpp.o
[ 68%] Building CXX object CMakeFiles/d2tm.dir/managers/cInteractionManager.cpp.o
/home/id/.builds/Dune-II---The-Maker/main.cpp:145:14: warning: extra ‘;’ [-Wpedantic]
  145 | END_OF_MAIN();
      |              ^
[ 69%] Building CXX object CMakeFiles/d2tm.dir/map/cMap.cpp.o
[ 69%] Building CXX object CMakeFiles/d2tm.dir/map/cMapCamera.cpp.o
[ 70%] Building CXX object CMakeFiles/d2tm.dir/map/cMapEditor.cpp.o
[ 71%] Building CXX object CMakeFiles/d2tm.dir/map/cRandomMapGenerator.cpp.o
[ 71%] Building CXX object CMakeFiles/d2tm.dir/mentat/cAbstractMentat.cpp.o
[ 72%] Building CXX object CMakeFiles/d2tm.dir/mentat/cAtreidesMentat.cpp.o
[ 73%] Building CXX object CMakeFiles/d2tm.dir/mentat/cBeneMentat.cpp.o
[ 73%] Building CXX object CMakeFiles/d2tm.dir/mentat/cHarkonnenMentat.cpp.o
[ 74%] Building CXX object CMakeFiles/d2tm.dir/mentat/cNoButtonCommand.cpp.o
[ 74%] Building CXX object CMakeFiles/d2tm.dir/mentat/cOrdosMentat.cpp.o
[ 75%] Building CXX object CMakeFiles/d2tm.dir/mentat/cProceedButtonCommand.cpp.o
[ 76%] Building CXX object CMakeFiles/d2tm.dir/mentat/cRepeatButtonCommand.cpp.o
[ 76%] Building CXX object CMakeFiles/d2tm.dir/mentat/cYesButtonCommand.cpp.o
[ 77%] Building CXX object CMakeFiles/d2tm.dir/player/brains/cPlayerBrain.cpp.o
[ 78%] Building CXX object CMakeFiles/d2tm.dir/player/brains/cPlayerBrainCampaign.cpp.o
[ 78%] Building CXX object CMakeFiles/d2tm.dir/player/brains/cPlayerBrainEmpty.cpp.o
[ 79%] Building CXX object CMakeFiles/d2tm.dir/player/brains/cPlayerBrainSandworm.cpp.o
[ 79%] Building CXX object CMakeFiles/d2tm.dir/player/brains/cPlayerBrainSkirmish.cpp.o
[ 80%] Building CXX object CMakeFiles/d2tm.dir/player/brains/missions/cPlayerBrainMission.cpp.o
[ 81%] Building CXX object CMakeFiles/d2tm.dir/player/brains/missions/cPlayerBrainMissionKind.cpp.o
[ 81%] Building CXX object CMakeFiles/d2tm.dir/player/brains/missions/cPlayerBrainMissionKindAttack.cpp.o
[ 82%] Building CXX object CMakeFiles/d2tm.dir/player/brains/missions/cPlayerBrainMissionKindDeathHand.cpp.o
[ 83%] Building CXX object CMakeFiles/d2tm.dir/player/brains/missions/cPlayerBrainMissionKindExplore.cpp.o
[ 83%] Building CXX object CMakeFiles/d2tm.dir/player/brains/missions/cPlayerBrainMissionKindFremen.cpp.o
[ 84%] Building CXX object CMakeFiles/d2tm.dir/player/brains/missions/cPlayerBrainMissionKindSaboteur.cpp.o
[ 85%] Building CXX object CMakeFiles/d2tm.dir/player/brains/superweapon/cPlayerBrainFremenSuperWeapon.cpp.o
[ 85%] Building CXX object CMakeFiles/d2tm.dir/player/cPlayer.cpp.o
[ 86%] Building CXX object CMakeFiles/d2tm.dir/player/cPlayerDifficultySettings.cpp.o
[ 86%] Building CXX object CMakeFiles/d2tm.dir/player/cPlayerNotification.cpp.o
In file included from /home/id/.builds/Dune-II---The-Maker/player/cPlayer.cpp:9:
/home/id/.builds/Dune-II---The-Maker/dependencies/fmt/include/fmt/format.h:2382:8: error: partial specialization of ‘struct fmt::v8::formatter<Char [N], Char>’ after instantiation of ‘struct fmt::v8::formatter<char [8], char, void>’ [-fpermissive]
 2382 | struct formatter<Char[N], Char> : formatter<basic_string_view<Char>, Char> {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~
[ 87%] Building CXX object CMakeFiles/d2tm.dir/player/cPlayerStatistics.cpp.o
[ 88%] Building CXX object CMakeFiles/d2tm.dir/sidebar/cBuildingList.cpp.o
[ 88%] Building CXX object CMakeFiles/d2tm.dir/sidebar/cBuildingListFactory.cpp.o
/home/id/.builds/Dune-II---The-Maker/player/cPlayer.cpp:440:2: warning: extra ‘;’ [-Wpedantic]
  440 | };
      |  ^
make[2]: *** [CMakeFiles/d2tm.dir/build.make:1518: CMakeFiles/d2tm.dir/player/cPlayer.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:134: CMakeFiles/d2tm.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
⏚ θ127° [id:~/.builds/Dune-II---The-Maker/build] 4bfab6c(+0/-1) 2 ± 

dreamcat4 avatar Feb 17 '22 22:02 dreamcat4

which gcc version? (just to be sure).

stefanhendriks avatar Feb 17 '22 22:02 stefanhendriks

Also do you compile under x86 or x64 ?

stefanhendriks avatar Feb 17 '22 22:02 stefanhendriks

A quick google got me here https://github.com/fmtlib/fmt/issues/2419 - @dreamcat4 perhaps this helps you a bit? I wonder if you can fix it with the suggestion at the bottom?

stefanhendriks avatar Feb 17 '22 22:02 stefanhendriks

When looking a bit deeper, I don't think thats it. Needs more investigation.

stefanhendriks avatar Feb 17 '22 22:02 stefanhendriks

well it's probably something similar along those lines... like a different compiler is being picked up by cmake to do the build here on my system (which then throws the error, which isn't for other people, who are using a different compiler)

but heavens knows. personally i stay well away from C++ templates feature myself. Life is a lot simpler that way :)

dreamcat4 avatar Feb 17 '22 22:02 dreamcat4

Ah, I ran into those semicolon errors too once. Clang warns on those extra semicolons, if I recall correctly. GCC doesn't. Feel free to open a PR that removes them.

The start of the CMake logging should show you which compiler is picked up.

That leaves the error in libfmt. I don't get it. I would also expect a longer error message, TBH.

pbomta avatar Feb 20 '22 08:02 pbomta

thanks! ...will try to check for clang. and then (if yes?) then try to find out how to witch it back to gcc in cmake world

hopefully the template error is also for same reason (clang vs gcc). that is my current guessings

dreamcat4 avatar Feb 20 '22 10:02 dreamcat4

I have the same problem with g++ 9 When i switch on g++ 11, the error disappears.

Mira-Chronos avatar Feb 20 '22 10:02 Mira-Chronos

ah... so when i run gcc --version i got 10.x here. Not 11. So maybe that's the cause of such problem.

  • now i notice the gcc 11+ dependancies requirement in the readme file. OK
  • so i look into the new dependancies install script for ubuntu here:

https://github.com/stefanhendriks/Dune-II---The-Maker/blob/master/install_dependencies_ubuntu.sh#L15

It does not automatically install any pkg(s) for gcc-11. So maybe it can or should?

Ah, but I already had gcc-11 package installed on my system!

... so therefore cmake is defaulting to gcc command --> redirecting to gcc-10. Instead of directly invoking gcc-11.

So maybe it should / should not ? Perhaps there can be a warning or error message when doing the project configure stage? Or alternatively, it it worth to broaden the compiler support for this whole project? And then elsewhere hit other new to fix etc.

Personally I'm just happy forcing to invoking the gcc-11. I just don't understand why it isn't forced by default (if exists, and was detected on the PATH environment). This makes sense to me. Only if gcc-11 isn't presently installed you fallback to gcc (any) and would not specifically use it? Does that make more sense? (or if we manually override to a different compiled in the build settings, for example to be debugging and working on issues with clang etc., to broaden the compiler support).

dreamcat4 avatar Feb 20 '22 13:02 dreamcat4

@pbomta can we somehow make CMake enforce to look for gcc11 or higher? (and if it can't find it, fail?)

stefanhendriks avatar Feb 20 '22 13:02 stefanhendriks

here is a simpler example:

https://github.com/NREL/SolarPILOT/blob/develop/CMakeLists.txt#L14-L17

So to actually detect what's available / currently installed on the system would require some extra cmake macros / functions to determine that. Before actually choosing 1 specific pair of compiler cmds (c & cxx) to set the compiler to.

And probably some other cmake based projects already made such logic. Which we could potentially copy/paste from... I just haven't found yet on google a good example. For such auto detection macros function

dreamcat4 avatar Feb 20 '22 13:02 dreamcat4

maybe this one? haven't had the time to read thu it yet. but seems a lot like what we would need

https://dane-bulat.medium.com/cmake-how-to-inspect-and-configure-the-compiler-877e6cb0317f

dreamcat4 avatar Feb 20 '22 13:02 dreamcat4

anyhow heres a simple patch you can just apply in git, and commit / merge. Just tried it and works. But still need to add gcc-11 to the ubuntu install deps script too though. To ensure it gets installed

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7d4b1425..2cc27dc3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.21)
 
 set(CMAKE_CXX_STANDARD 20)
 
+set(CMAKE_C_COMPILER gcc-11)
+set(CMAKE_CXX_COMPILER g++-11)
+
 project(d2tm)
 
 SET(OpenGL_GL_PREFERENCE "GLVND")
@@ -107,7 +110,6 @@ endif()
 target_compile_options(${PROJECT_NAME}
   PRIVATE
     ${D2TM_OPTMIZATION}
-    "-Werror"
     "-Wall"
     "-Wextra"
     "-Wpedantic"
diff --git a/install_dependencies_ubuntu.sh b/install_dependencies_ubuntu.sh
old mode 100644
new mode 100755

dreamcat4 avatar Feb 20 '22 13:02 dreamcat4

Thanks for the effort! And narrowing down the problem. But we need to keep -Werror. Bugs will creep in otherwise. And I don't think we should hardcode gcc 11. Things should be able to compile with clang. Also for the sanitizers we wish to use at some point.

On linux, there is a way to set the default compiler. See this answer on AskUbuntu: https://askubuntu.com/questions/26498/how-to-choose-the-default-gcc-and-g-version I use this method on my work machine. Another method is to set the CC and CXX environment variables before running cmake. See this: https://stackoverflow.com/questions/17275348/how-to-specify-new-gcc-path-for-cmake

pbomta avatar Feb 20 '22 15:02 pbomta