0

When I was building an application of mine which used Assimp, I got an error

C:\Users\nitin\AppData\Local\Temp\ccA4Vs3q.s: Assembler messages:
C:\Users\nitin\AppData\Local\Temp\ccA4Vs3q.s: Fatal error: can't write 117 bytes to section .text of CMakeFiles\assimp.dir\AssetLib\IFC\IFCReaderGen1_2x3.cpp.obj because: 'File too big'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/as.exe: CMakeFiles\assimp.dir\AssetLib\IFC\IFCReaderGen1_2x3.cpp.obj: too many sections (46774)
C:\Users\nitin\AppData\Local\Temp\ccA4Vs3q.s: Fatal error: can't close CMakeFiles\assimp.dir\AssetLib\IFC\IFCReaderGen1_2x3.cpp.obj: File too big
Nade\vendor\assimp\code\CMakeFiles\assimp.dir\build.make:1965: recipe for target 'Nade/vendor/assimp/code/CMakeFiles/assimp.dir/AssetLib/IFC/IFCReaderGen1_2x3.cpp.obj' failed

So I searched online for solutions and I found a solution that said that I need to set the /bigobj flag.

I am using Cmake and Mingw32-make.

But when I add the definition like this

set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} /bigobj)

or like that

add_definitions(/bigobj)

I Get the error

/bigobj: No such file or directory

How do I solve this error while solving the Too Big OBJ file error at the same time?

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • Options started with forward slash (`/`) are usually used on Windows. In Unux environment (MinGW uses Unix-like environment too) options are usually passed as dash-prefixed (`-`). So `/bigobj` is definitely not suitable as an option for the compiler under MinGW. Please, show (add to the question post) the **exact** error message about "Too Big OBJ file". – Tsyvarev Nov 09 '21 at 19:18

1 Answers1

6

The /bigobj option is for Microsoft Visual Studio compiler.

For GCC, try -Wa,-mbig-obj instead.

If you want to support both, try:

if (MSVC)
  add_compile_options(/bigobj)
else ()
  add_compile_options(-Wa,-mbig-obj)
endif ()

If you want to specify directly only a single target:

target_compile_options(my_target_name PRIVATE /bigobj)
malat
  • 12,152
  • 13
  • 89
  • 158
Lindydancer
  • 25,428
  • 4
  • 49
  • 68
  • there's a typo, add_definition should be add_definitions – e9x Feb 27 '22 at 02:31
  • for curiosity: is there a reason to use `add_definitions()` here instead of `add_compile_options()`? According to the [CMake Docs](https://cmake.org/cmake/help/latest/command/add_definitions.html) the latter seems to be the better choice (and it also supports generator Expressions) – user2169513 Jun 02 '22 at 09:16
  • 1
    No reason that I remember... I'll update the answer. – Lindydancer Jun 02 '22 at 09:59