Build fails

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
User avatar
em3
Vacuum Dragon
Posts: 630
Joined: Sun Sep 25, 2011 2:51 pm

Build fails

#1 Post by em3 »

I'm attempting to build FO after updating to latest master.

All over the codebase, I get errors like this:
error C2039: "min": Nie jest składową "std"
... this translates to:
error C2039: "min": Is not a member "std"
One of the files with such problem is GG/GG/Clr.h... and fair enough it does use std::min without including <algorithm>, which, according to cppreference, it should.

Oh, it's all over the codebase, because virtually everything includes GG/GG/Clr.h, it seems.

There are also many warnings about narrowing conversions, includingin the Clr.h.

Edit: Why can std::max and std::min still be used even if I didn't #include <algorithm>?

Edit2: This all seems to be inside inlined functions... maybe it works "magically" because of inlining under some compilers?

Edit3: Adding #include <algorithm> to Clr.h fixes compilation. I still have some linking issues:
"C:\Users\ 8) \Documents\Build\freeorion\ALL_BUILD.vcxproj" (domyślny element docelowy) (1)->
"C:\Users\ 8) \Documents\Build\freeorion\test\system\fo_systemtest_game.vcxproj" (domyślny element docelowy) (4
)->
(element docelowy Link) ->
LINK : fatal error LNK1104: nie mo┐na otworzyŠ pliku äboost_filesystem-vc141-mt-x32-1_70.libö [C:\Users\ 8) \
Documents\Build\freeorion\test\system\fo_systemtest_game.vcxproj]
The game build seems to be looking for boost_filesystem-vc141-mt-x32-1_70.lib, while my SDK folder contains simply boost_filesystem.lib. Game CMAKE is configured properly and points to the library in the SDK build directory.
Sorry for the wachy symbols, Powershell + CMAKE + MSBuild seem to be really confused about encoding (telephone effect).

Edit4: It's even weirder, as the call to link.exe explicitly refers to the sort name, b]boost_filesystem.lib[/b]...
https://github.com/mmoderau
[...] for Man has earned his right to hold this planet against all comers, by virtue of occasionally producing someone totally batshit insane. - Randall Munroe, title text to xkcd #556

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13586
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Build fails

#2 Post by Geoff the Medio »

So you're trying to build with CMake on Windows? As far as I know, that's not actively supported. Visual Studio 2017 Community Edition can be downloaded free and is the presently the suggested build environment on Windows.

User avatar
em3
Vacuum Dragon
Posts: 630
Joined: Sun Sep 25, 2011 2:51 pm

Re: Build fails

#3 Post by em3 »

I'm using CMAKE, but it's just calling MSBuild under the hood. I'm using the solution as generated by CMAKE, but my understanding was that it should work.

Should I make a PR with the missing #include?
https://github.com/mmoderau
[...] for Man has earned his right to hold this planet against all comers, by virtue of occasionally producing someone totally batshit insane. - Randall Munroe, title text to xkcd #556

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13586
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Build fails

#4 Post by Geoff the Medio »

The Windows build works with the Visual Studio project files and on other OS's, so more includes aren't needed. If you can fix the Windows CMake build by modifying the Cmake files, then go ahead...

User avatar
em3
Vacuum Dragon
Posts: 630
Joined: Sun Sep 25, 2011 2:51 pm

Re: Build fails

#5 Post by em3 »

Geoff the Medio wrote: Sun Oct 18, 2020 8:40 am The Windows build works with the Visual Studio project files and on other OS's, so more includes aren't needed.
A file is using a function without including a required header. That it works seems more like an accident.

I'll bite, though. I'll see what is the difference between the generated .sln and the tracked one. Maybe some precompiled headers? :|

Edit: Oh, the tracked vcxproj uses props files (which is a good practice). The boost one includes BOOST_AUTO_LINK_NOMANGLE preprocessor definition.
See boost/config/auto_link.hpp:

Code: Select all

BOOST_AUTO_LINK_NOMANGLE: Specifies that we should link to BOOST_LIB_NAME.lib,
                          rather than a mangled-name version.
Edit2:So far, adding this line in the right place of CMakeList.txt seems to do the trick:

Code: Select all

        $<$<PLATFORM_ID:Windows>:BOOST_AUTO_LINK_NOMANGLE>
By the way, the following code issues a warning:

Code: Select all

inline Clr LightenClr(const Clr& clr, float factor = 2.0)
{
    return Clr(
        std::min(static_cast<int>(clr.r * factor), 255),
        std::min(static_cast<int>(clr.g * factor), 255),
        std::min(static_cast<int>(clr.b * factor), 255),
        clr.a);
}
The warning is because Clr constructor takes four unsigned chars, but is given three ints and an unsigned char here. This is a narrowing conversion. Yes, the std::min used here guarantees the conversion is valid, but compiler does not know that. To fix the warning:

Code: Select all

inline Clr LightenClr(const Clr& clr, float factor = 2.0)
{
    return Clr(
        static_cast<iunsigned char>(std::min(static_cast<int>(clr.r * factor), 255)),
        static_cast<iunsigned char>(std::min(static_cast<int>(clr.g * factor), 255)),
        static_cast<iunsigned char>(std::min(static_cast<int>(clr.b * factor), 255)),
        clr.a);
}
Edit3:Nope, still not linking because of boost. Maybe I didn't add it to the right place in CMakeList.....
Edit4:Oh, it worked. I just needed to make a clean build.
https://github.com/mmoderau
[...] for Man has earned his right to hold this planet against all comers, by virtue of occasionally producing someone totally batshit insane. - Randall Munroe, title text to xkcd #556

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13586
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Build fails

#6 Post by Geoff the Medio »

em3 wrote: Sat Oct 17, 2020 5:52 pmOne of the files with such problem is GG/GG/Clr.h... and fair enough it does use std::min without including <algorithm>, which, according to cppreference, it should.
Apparently someone else thinks similarly... https://github.com/freeorion/freeorion/pull/3199

User avatar
em3
Vacuum Dragon
Posts: 630
Joined: Sun Sep 25, 2011 2:51 pm

Re: Build fails

#7 Post by em3 »

That would be me. :oops:
https://github.com/mmoderau
[...] for Man has earned his right to hold this planet against all comers, by virtue of occasionally producing someone totally batshit insane. - Randall Munroe, title text to xkcd #556

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13586
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Build fails

#8 Post by Geoff the Medio »

I've pretty much given up on keeping track of the multiple accounts of people who have two completely unrelated names on the forum and github...

I did check your forum account profile briefly to see if there was an indication if they were connected, but didn't see anything.

User avatar
em3
Vacuum Dragon
Posts: 630
Joined: Sun Sep 25, 2011 2:51 pm

Re: Build fails

#9 Post by em3 »

Geoff the Medio wrote: Fri Oct 23, 2020 12:04 am I've pretty much given up on keeping track of the multiple accounts of people who have two completely unrelated names on the forum and github...
That's entirely reasonable. I just wanted to make it clear, so that I don't count as "two votes" in favor of my pull request. :)

Thank you for quick response.
https://github.com/mmoderau
[...] for Man has earned his right to hold this planet against all comers, by virtue of occasionally producing someone totally batshit insane. - Randall Munroe, title text to xkcd #556

Post Reply