Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Building flags that are needed #356

Closed
1 task done
kellijohnson-NOAA opened this issue May 15, 2023 · 5 comments
Closed
1 task done

[Bug]: Building flags that are needed #356

kellijohnson-NOAA opened this issue May 15, 2023 · 5 comments
Labels
kind: bug Something isn't working kind: documentation Improvements or additions to documentation status: triage_needed This is not approved for this milestone, do not work on it yet

Comments

@kellijohnson-NOAA
Copy link
Contributor

Describe the bug

Users can get this, or some derivative of, error as noted by @Cole-Monnahan-NOAA.

Fatal error: can't write 326 bytes to section .text of FIMS.o: 'file too big

@Andrea-Havron-NOAA knows of the following solution that worked for @kellijohnson-NOAA

withr::local_options(pkg.build_extra_flags = FALSE)

but this is not documented anywhere in FIMS that I know of. Perhaps having this searchable issue will be helpful. But, is this important enough that we should put it on the README?

I am happy to add this to the README if everything thinks that this is the best location for it.

To Reproduce

load_all()

Expected behavior

That FIMS would just compile.

Screenshots

No response

Which OS are you seeing the problem on?

Windows

Which browser are you seeing the problem on?

No response

Which version of FIMS are you seeing the problem on?

No response

Additional Context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@kellijohnson-NOAA kellijohnson-NOAA added kind: bug Something isn't working kind: documentation Improvements or additions to documentation status: triage_needed This is not approved for this milestone, do not work on it yet labels May 15, 2023
@Andrea-Havron-NOAA
Copy link
Collaborator

@kellijohnson-NOAA, I think the README is the best place for it. If you can add it there, I can follow up with a bit more detail. Thanks!

kellijohnson-NOAA added a commit that referenced this issue May 16, 2023
to the README under a header labeled "Fixing Fatal Error".

Close #356
@Andrea-Havron-NOAA
Copy link
Collaborator

A bit more background on this issue...

This error message is specific to Windows OS and happens when FIMS is compiled through a devtools function that automatically turns on the degugger (eg. devtools::load_all()). The devtools package uses pkgbuild to set up the compiler flags, which automatically defines the debugger flag as, -O0 -g, an optimization level that is too low for a templated C++ program on a Windows OS. The degugger flag on a Windows OS should be set at -O1 -g or higher as recommended by TMB developers.

I have reached out to pkgbuild developers asking for an option to set the debugger flag as an argument through devtools. The recommended option was to use withr::local_options(pkg.build_extra_flags = FALSE) to turn off the automatic addition of the -O0 -g debugger flag. Then, we can add the -O1 -g debugger flag manually to the FIMS Makevars.win file when needing to compile with the debugger turn on:

PKG_CXXFLAGS = -DTMB_MODEL -DTMB_EIGEN_DISABLE_WARNINGS -O1 -g

In the future, we could possibly set-up a Makefile that automatically compiles FIMS with the correct debugger flag when calling devtools::load_all().

@Cole-Monnahan-NOAA
Copy link
Contributor

@Andrea-Havron-NOAA I tried executing that withr call on the console and then testing the package through RStudio. This is Windows R 4.2.2 and devtools 2.4.5.

I actually get an earlier error:

Error in `private$handle_error()`:
! testthat subprocess failed to start, stderr:
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'Rcmd.exe' failed

Here's the compiler call

g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-42~1.2/include" -DNDEBUG  -I'C:/Users/cole.monnahan/Rlibs/Rcpp/include' -I'C:/Users/cole.monnahan/Rlibs/TMB/include' -I'C:/Users/cole.monnahan/Rlibs/RcppEigen/include'   -I"C:/rtools42/x86_64-w64-mingw32.static.posix/include"  -DTMB_MODEL  -DTMB_EIGEN_DISABLE_WARNINGS   -O2 -Wall -gdwarf-2 -mfpmath=sse -msse2 -mstackrealign  -UNDEBUG -Wall -pedantic -g -O0 -c FIMS.cpp -o FIMS.o

but results in the same error

c:\users\cole.monnahan\fims\inst\include\common\data_object.hpp:58:3: warning:   when initialized here [-Wreorder]
   58 |   DataObject(size_t imax) : imax(imax), dimensions(1) {
      |   ^~~~~~~~~~
as: FIMS.o: too many sections (66540)
C:\Users\COLE~1.MON\AppData\Local\Temp\ccMATBww.s: Assembler messages:
C:\Users\COLE~1.MON\AppData\Local\Temp\ccMATBww.s: Fatal error: can't write 326 bytes to section .text of FIMS.o: 'file too big'
as: FIMS.o: too many sections (66540)
C:\Users\COLE~1.MON\AppData\Local\Temp\ccMATBww.s: Fatal error: FIMS.o: file too big
make: *** [C:/PROGRA~1/R/R-42~1.2/etc/x64/Makeconf:260: FIMS.o] Error 1
ERROR: compilation failed for package 'FIMS'

I confirmed that I can run devtools::test on a different package without issue so I suspect this is a FIMS issue. I wonder if this could be an issue with my compiler setup from TMB or rstan installation?

@Andrea-Havron-NOAA
Copy link
Collaborator

@Cole-Monnahan-NOAA, It looks like you're still compiling with the -O0 -g flag, so the withr script hasn't succesfully turned off the automatic addition of this debugger flag.

You need to run
withr::local_options(pkg.build_extra_flags = FALSE)
within the same R session that you run the tests. If it works, you will see -O1 -g near the end of the compiler call.

Note the issue is with compiling templated C++ on windows when the debugger is automatically turned on by devtools. The debugger bloats the .o file, so you won't see this error with a small program. We started seeing this error in FIMS once we linked in the Rcpp interface, which includes a large codebase. Other TMB developers (eg. VAST) have also seen this error.

@Andrea-Havron-NOAA
Copy link
Collaborator

I've added more details to the README, including instructions on how to modify Makevars.win to compile FIMS with the debugger turned on (needed for gdb). Given that developers may need to modify Makevars.win, I've added this file to the .gitignore in src to make sure changes are not pushed up to github. We will just want to remove from .gitignore if/when we need to make changes to Makevars.win.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Something isn't working kind: documentation Improvements or additions to documentation status: triage_needed This is not approved for this milestone, do not work on it yet
Projects
None yet
Development

No branches or pull requests

4 participants