fmt icon indicating copy to clipboard operation
fmt copied to clipboard

Unrecognized option `-mbig-obj`

Open ICreateYank opened this issue 6 years ago • 6 comments

The docs says:


Portability

The library is highly portable and relies only on a small set of C++11 features:

  • variadic templates
  • type traits
  • rvalue references
  • decltype
  • trailing return types
  • deleted functions
  • alias templates

These are available since GCC 4.8, Clang 3.0 and MSVC 19.0 (2015). For older compilers use {fmt} version 4.x which continues to be maintained and only requires C++98.


If you mean GCC 4.8.0, I think this is a small mistake because the library is not able to build because GCC 4.8.0 does not support method ref qualifiers (on line 831 format.h):

Compiler rvalue refs ref-qualifiers source
GCC 4.3 4.8.1 here
Clang 2.9 2.9 here
Intel 12.0 14.0 here
Visual C++ VC10 Nov 2013 CTP here

With GCC 4.8.1 installed however, building on Windows 10 with x86_64-4.8.1-release-posix-seh-rt_v3-rev2 gives:

c:/users/marcd/downloads/x86_64-4.8.1-release-posix-seh-rt_v3-rev2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/as.exe: unrecognized option `-mbig-obj'
mingw32-make.exe[3]: *** [fmt/CMakeFiles/fmt.dir/src/os.cc.obj] Error 1
mingw32-make.exe[3]: *** Waiting for unfinished jobs....
fmt\CMakeFiles\fmt.dir\build.make:96: recipe for target 'fmt/CMakeFiles/fmt.dir/src/os.cc.obj' failed
c:/users/marcd/downloads/x86_64-4.8.1-release-posix-seh-rt_v3-rev2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/as.exe: unrecognized option `-mbig-obj'
mingw32-make.exe[3]: *** [fmt/CMakeFiles/fmt.dir/src/format.cc.obj] Error 1
mingw32-make.exe[2]: *** [fmt/CMakeFiles/fmt.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/untitled.dir/rule] Error 2
mingw32-make.exe: *** [untitled] Error 2
fmt\CMakeFiles\fmt.dir\build.make:82: recipe for target 'fmt/CMakeFiles/fmt.dir/src/format.cc.obj' failed
CMakeFiles\Makefile2:141: recipe for target 'fmt/CMakeFiles/fmt.dir/all' failed
CMakeFiles\Makefile2:121: recipe for target 'CMakeFiles/untitled.dir/rule' failed
Makefile:137: recipe for target 'untitled' failed

Main.cpp:

#include <fmt/core.h>

int main() {
    fmt::print("The answer is {}", 42);
    return 0;
}

Cmake:

cmake_minimum_required(VERSION 3.17)
project(untitled)

add_subdirectory(fmt)

add_executable(untitled main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE fmt::fmt)

Am I missing something?

ICreateYank avatar Oct 10 '20 13:10 ICreateYank

the library is not able to build because GCC 4.8.0 does not support method ref qualifiers (on line 831 format.h)

Those qualifiers are non-essential, a PR to remove them is welcome. Alternatively you can use GCC 4.8.1.

-mbig-obj was introduced in https://github.com/fmtlib/fmt/commit/47ae521557a3f1a3a338e8f5b1b75add53754c8d to workaround a bug in mingw. I think the solution is to detect flag support with check_cxx_compiler_flag. Again a PR would be welcome because you are in the best position to check if it works.

vitaut avatar Oct 10 '20 13:10 vitaut

Alright I'll try and make a PR soon. I'm busy this week but you will receive it somewhere soon hopefully.

ICreateYank avatar Oct 10 '20 15:10 ICreateYank

While this issue is open anyway, I had another question regarding the insertion of the flag -fPIC. One of my builds errored because of a missing -fPIC flag in GCC 4.8:

/usr/bin/ld: /home/runner/work/cpp-lazy/cpp-lazy/build/prefix/lib/libfmt.a(format.cc.o): relocation R_X86_64_32S against symbol `_ZTVN3fmt2v712format_errorE' can not be used when making a PIE object; recompile with -fPIC

As one of my contributors (@friendlyanon) mentioned:

Regarding -fPIC, since {fmt} does not define library type, that add_library call is affected by BUILD_SHARED_LIBS's value, which by default is not defined, hence false, ie {fmt} is built as a static library as evident by the fmt.a artifact name. Your library is explicitly defined as INTERFACE (usage requirements only) and for the tests it's consumed directly using an executable target. Indeed, this doesn't make much sense.

Are we missing something here?

ICreateYank avatar Oct 11 '20 13:10 ICreateYank

Not sure what's the question, -fPIC is added when BUILD_SHARED_LIBS is ON.

vitaut avatar Oct 11 '20 13:10 vitaut

If I understood correctly, this variable is simply set to its initial value, so false. But when importing fmt the following way:

option(CPP-LAZY_USE_INSTALLED_FMT "Import {fmt} using find_package" NO)
if(CPP-LAZY_USE_INSTALLED_FMT)
    find_package(fmt 7 REQUIRED CONFIG)
else()
    set(FMT_INSTALL YES CACHE INTERNAL "" FORCE)
    set(FMT_OS YES CACHE INTERNAL "")
    include(FetchContent)
    FetchContent_Declare(fmt
            GIT_REPOSITORY https://github.com/fmtlib/fmt.git
            GIT_TAG a581e9e5d83673fefbecb7cc6ea2514af83f77c8
            UPDATE_DISCONNECTED YES)
    FetchContent_MakeAvailable(fmt)
endif()

target_link_libraries(cpp-lazy INTERFACE fmt::fmt)

But that gives this link error on GCC 4.8, so I was wondering if you had any pointers

ICreateYank avatar Oct 11 '20 13:10 ICreateYank

Closing as the original issue has been fixed (thanks for providing the fix). As for -fPIC, I suggest opening a separate issue if it's more than just a problem of building with inconsistent CMake flags.

vitaut avatar Oct 11 '20 14:10 vitaut