JuliaInterop / libcxxwrap-julia

C++ library for backing CxxWrap.jl
Other
79 stars 43 forks source link

Add "-Wa,-mbig-obj -O2" flags to cmake flag list to fix 'file too big' error #84

Closed QuantumBits closed 3 years ago

QuantumBits commented 3 years ago

Hi - tried running through the tutorial for building a local version of this repo, and found that I was getting the following error:

shell> cmake -G "MinGW Makefiles" ../libcxxwrap-julia
-- Found Julia executable: C:/Julia/1.6.1/bin/julia.exe
-- Julia_VERSION_STRING: 1.6.1
-- Julia_INCLUDE_DIRS:   C:\\Julia\\1.6.1\\include\\julia
-- Julia_LIBRARY_DIR:    C:/Julia/1.6.1/lib
-- Julia_LIBRARY:        C:/Julia/1.6.1/lib/libjulia.dll.a
-- JULIA_HOME:           C:\\Julia\\1.6.1\\bin
-- Julia_LLVM_VERSION:   v11.0.1
-- Julia_WORD_SIZE:      64
-- JlCxx version: v0.8.3
-- Configuring done
-- Generating done
-- Build files have been written to: ~/libcxxwrap-julia-build

shell> cmake --build . --config Release
[ 12%] Built target cxxwrap_julia
[ 15%] Building CXX object CMakeFiles/cxxwrap_julia_stl.dir/src/stl.cpp.obj
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/as.exe: CMakeFiles\cxxwrap_julia_stl.dir\src\stl.cpp.obj: too many sections (141576)
~\AppData\Local\Temp\cceYEXXa.s: Assembler messages:
~\AppData\Local\Temp\cceYEXXa.s: Fatal error: can't write 53 bytes to section .text of CMakeFiles\cxxwrap_julia_stl.dir\src\stl.cpp.obj: 'file too big'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/as.exe: CMakeFiles\cxxwrap_julia_stl.dir\src\stl.cpp.obj: too many sections (141576)
~\AppData\Local\Temp\cceYEXXa.s: Fatal error: CMakeFiles\cxxwrap_julia_stl.dir\src\stl.cpp.obj: file too big
mingw32-make[2]: *** [CMakeFiles\cxxwrap_julia_stl.dir\build.make:83: CMakeFiles/cxxwrap_julia_stl.dir/src/stl.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:188: CMakeFiles/cxxwrap_julia_stl.dir/all] Error 2
mingw32-make: *** [Makefile:160: all] Error 2

The part that jumped out at me was 'file too big', so I did some Googling and found this issue which recommended adding the -Wa,-mbig-obj flag to cmake. I did that by adding it to this line, reran things and got this:

shell> cmake --build . --config Release
[  3%] Building CXX object CMakeFiles/cxxwrap_julia.dir/src/c_interface.cpp.obj
[  6%] Building CXX object CMakeFiles/cxxwrap_julia.dir/src/jlcxx.cpp.obj
[  9%] Building CXX object CMakeFiles/cxxwrap_julia.dir/src/functions.cpp.obj
[ 12%] Linking CXX shared library libcxxwrap_julia.dll
[ 12%] Built target cxxwrap_julia
[ 15%] Building CXX object CMakeFiles/cxxwrap_julia_stl.dir/src/stl.cpp.obj
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/as.exe: CMakeFiles\cxxwrap_julia_stl.dir\src\stl.cpp.obj: section .xdata$_ZNSt14_Function_base13_Base_managerIZN5jlcxx6Module11constructorISt8valarrayIaEJyEEEvP14_jl_datatype_tbEUlyE_E8_M_cloneERSt9_Any_dataRKSA_St17integral_constantIbLb1EE: string table overflow at offset 10000120
~\AppData\Local\Temp\cc4Bp5w1.s: Assembler messages:
~\AppData\Local\Temp\cc4Bp5w1.s: Fatal error: CMakeFiles\cxxwrap_julia_stl.dir\src\stl.cpp.obj: file too big
mingw32-make[2]: *** [CMakeFiles\cxxwrap_julia_stl.dir\build.make:83: CMakeFiles/cxxwrap_julia_stl.dir/src/stl.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:188: CMakeFiles/cxxwrap_julia_stl.dir/all] Error 2
mingw32-make: *** [Makefile:160: all] Error 2

Here, I focused on the string table overflow at offset part, and found this issue and decided to add the -O2 flag to the this line, which worked!

Going to create a PR, but the fix is to update this line to read as follows:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-parameter -Wextra -Wreorder -Wa,-mbig-obj -O2")
QuantumBits commented 3 years ago

https://github.com/JuliaInterop/libcxxwrap-julia/pull/85 PR here