Hi Kevin,

This is the package that I'm trying to build:
https://github.com/RAPLER/dst-1. The Makefile is in the src folder. I don't
think I have something like you said in Makevars and DESCRIPTION.

I tried CFLAGS and CXXFLAGS but still the Makeconf flags are used. I have
no control over this Makeconf file as this is read only on Compute Canada.
Same for ~/.R/Makevars.

Best regards,
Gary


On Wed, May 21, 2025 at 7:50 PM Kevin Ushey <kevinus...@gmail.com> wrote:

> > The manual seems unreadable at this point. Every sentence has at least
> two words which I don't understand.
>
> There's definitely a lot to learn if you haven't spent much time in
> this space before. The somewhat short description here is:
>
> - make is a (now somewhat older) program commonly used to build
> software projects; e.g. compile C / C++ sources to object files
> - It commonly accepts flags like CFLAGS, CXXFLAGS, and so on to
> control the flags used during compilation
> - R builds / extends on this by using things like etc/Makeconf +
> Makevars files to define / augment these compiler flags
>
> It will become more familiar with practice.
>
> All that said, I believe you should be able to override these flags by
> setting CFLAGS or CXXFLAGS, either in
>
> - your own ~/.R/Makevars, or
> - your package's src/Makevars
>
> The specific flag you need to set will depend on where the default
> optimization flags are being set, though. For example, in my R
> installation, I have:
>
> $ cat /Library/Frameworks/R.framework/Resources/etc/Makeconf | grep -- -O
> # configure  'FW_VERSION=4.5-arm64' 'CC=clang -arch arm64'
> 'CXX=clang++ -arch arm64' 'OBJC=clang -arch arm64'
> 'FC=/opt/gfortran/bin/gfortran -arch arm64'
> 'CFLAGS=-falign-functions=64 -Wall -g -O2'
> 'CXXFLAGS=-falign-functions=64 -Wall -g -O2'
> 'OBJCFLAGS=-falign-functions=64 -Wall -g -O2' 'FCFLAGS=-Wall -g -O2'
> 'F77FLAGS=-Wall -g -O2' 'LDFLAGS=-L/opt/R/arm64/lib'
> 'CPPFLAGS=-I/opt/R/arm64/include' '--enable-memory-profiling'
> '--enable-R-framework'
> '--with-tcl-config=/opt/R/arm64/lib/tclConfig.sh'
> '--with-tk-config=/opt/R/arm64/lib/tkConfig.sh'
> '--build=aarch64-apple-darwin20' 'build_alias=aarch64-apple-darwin20'
>
> 'PKG_CONFIG_PATH=/usr/lib/pkgconfig:/opt/R/arm64/lib/pkgconfig:/opt/R/arm64/share/pkgconfig:/opt/X11/lib/pkgconfig:/opt/X11/share/pkgconfig'
> CFLAGS = -falign-functions=64 -Wall -g -O2 $(LTO)
> C17FLAGS = -falign-functions=64 -Wall -g -O2 $(LTO)
> C90FLAGS = -falign-functions=64 -Wall -g -O2 $(LTO)
> C99FLAGS = -falign-functions=64 -Wall -g -O2 $(LTO)
> CXXFLAGS = -falign-functions=64 -Wall -g -O2 $(LTO)
> CXX11FLAGS = -falign-functions=64 -Wall -g -O2 $(LTO)
> CXX14FLAGS = -falign-functions=64 -Wall -g -O2 $(LTO)
> CXX17FLAGS = -falign-functions=64 -Wall -g -O2 $(LTO)
> CXX20FLAGS = -falign-functions=64 -Wall -g -O2 $(LTO)
> CXX23FLAGS = -falign-functions=64 -Wall -g -O2 $(LTO)
> FCFLAGS = -Wall -g -O2 $(LTO_FC)
> FFLAGS = -Wall -g -O2 $(LTO_FC)
> OBJCFLAGS = -falign-functions=64 -Wall -g -O2 -fobjc-exceptions $(LTO)
> SAFE_FFLAGS = -Wall -g -O2
>
> Unfortunately, there are a lot of different default flags set
> depending on the C (or C++) standard being used, and that could also
> affect the flags depending on the C / C++ standard required by the
> project you're compiling.
>
> In short, you should try doing something like:
>
>     CFLAGS = -g -O3
>     CXXFLAGS = -g -O3
>
> in either your own ~/.R/Makevars, or your package's src/Makevars.
>
> If that doesn't work, you may need to override one of the variants
> like CXX17FLAGS -- this would depend on if that package has something
> like CXX_STD = <...> in its src/Makevars file, or SystemRequirements:
> C++17 (or similar) in its DESCRIPTION file. (All of this is much
> easier to be concrete about if you can share the package you're trying
> to build.)
>
> Best,
> Kevin
>
> On Wed, May 21, 2025 at 7:00 PM Peiyuan Zhu <garyzh...@gmail.com> wrote:
> >
> > Unfortunately this still doesn't work.
> >
> > > devtools::install("/home/zhupy/projects/def-kwalley/zhupy/dst-1")
> >
> > ── R CMD build
> ─────────────────────────────────────────────────────────────────
> >
> > ✔  checking for file ‘/project/6046455/zhupy/dst-1/DESCRIPTION’ (847ms)
> >
> > ─  preparing ‘dst’: (17.8s)
> >
> > ✔  checking DESCRIPTION meta-information ...
> >
> > ─  cleaning src
> >
> > ─  checking for LF line-endings in source and make files and shell
> scripts (638ms)
> >
> > ─  checking for empty or unneeded directories
> >
> >    Removed empty directory ‘dst/.idea’
> >
> > ─  building ‘dst_1.9.0.tar.gz’
> >
> >    Warning: invalid uid value replaced by that for user 'nobody'
> >
> >    Warning: invalid gid value replaced by that for user 'nobody'
> >
> >
> >
> > Running \
> >
> >   /cvmfs/
> soft.computecanada.ca/easybuild/software/2023/x86-64-v3/Compiler/gcccore/r/4.4.0/lib64/R/bin/R
> \
> >
> >   CMD INSTALL /tmp/RtmpwaSy51/dst_1.9.0.tar.gz --install-tests
> >
> > * installing to library ‘/home/zhupy/R/x86_64-pc-linux-gnu-library/4.4’
> >
> > * installing *source* package ‘dst’ ...
> >
> > ** using staged installation
> >
> > ** libs
> >
> > using C++ compiler: ‘g++ (Gentoo 12.3.1_p20230526 p2) 12.3.1 20230526’
> >
> > g++ -std=gnu++17 -I"/cvmfs/
> soft.computecanada.ca/easybuild/software/2023/x86-64-v3/Compiler/gcccore/r/4.4.0/lib64/R/include"
> -DNDEBUG  -I'/home/zhupy/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include'
> -I'/home/zhupy/R/x86_64-pc-linux-gnu-library/4.4/BH/include'
> -I'/home/zhupy/R/x86_64-pc-linux-gnu-library/4.4/RcppProgress/include'
> -I'/home/zhupy/R/x86_64-pc-linux-gnu-library/4.4/RcppArmadillo/include'
> -I/cvmfs/
> soft.computecanada.ca/easybuild/software/2023/x86-64-v3/Core/java/17.0.6/include
> -I/cvmfs/
> soft.computecanada.ca/easybuild/software/2023/x86-64-v3/Core/flexiblascore/3.3.1/include
> -I/cvmfs/
> soft.computecanada.ca/easybuild/software/2023/x86-64-v3/Core/flexiblascore/3.3.1/include/flexiblas
>  -O3 -fpic  -O2 -ftree-vectorize -march=x86-64-v3 -fno-math-errno   -c
> RcppExports.cpp -o RcppExports.o
> >
> > g++ -std=gnu++17 -I"/cvmfs/
> soft.computecanada.ca/easybuild/software/2023/x86-64-v3/Compiler/gcccore/r/4.4.0/lib64/R/include"
> -DNDEBUG  -I'/home/zhupy/R/x86_64-pc-linux-gnu-library/4.4/Rcpp/include'
> -I'/home/zhupy/R/x86_64-pc-linux-gnu-library/4.4/BH/include'
> -I'/home/zhupy/R/x86_64-pc-linux-gnu-library/4.4/RcppProgress/include'
> -I'/home/zhupy/R/x86_64-pc-linux-gnu-library/4.4/RcppArmadillo/include'
> -I/cvmfs/
> soft.computecanada.ca/easybuild/software/2023/x86-64-v3/Core/java/17.0.6/include
> -I/cvmfs/
> soft.computecanada.ca/easybuild/software/2023/x86-64-v3/Core/flexiblascore/3.3.1/include
> -I/cvmfs/
> soft.computecanada.ca/easybuild/software/2023/x86-64-v3/Core/flexiblascore/3.3.1/include/flexiblas
>  -O3 -fpic  -O2 -ftree-vectorize -march=x86-64-v3 -fno-math-errno   -c
> belplauHFast.cpp -o belplauHFast.o
> >
> >
> >
> > On Wed, May 21, 2025 at 6:50 PM Peiyuan Zhu <garyzh...@gmail.com> wrote:
> >>
> >> I saw this line from the manual:
> >>
> >> Flags that are already set (for example in file etcR_ARCH/Makeconf) can
> be overridden by the environment variable MAKEFLAGS (at least for systems
> using a POSIX-compliant make), as in (Bourne shell syntax)
> >>
> >> MAKEFLAGS="CFLAGS=-O3" R CMD SHLIB *.c
> >>
> >> I can give it a try.
> >>
> >>
> >>
> >> On Wed, May 21, 2025 at 6:44 PM Peiyuan Zhu <garyzh...@gmail.com>
> wrote:
> >>>
> >>> The manual seems unreadable at this point. Every sentence has at least
> two words which I don't understand.
> >>>
> >>> That said, I was able to find the compiler flags. They're still in
> Makeconf in the system. I don't know how I can control this in a package.
> >>>
> >>> dhcp-128-189-214-31:src garyzhubc$ R CMD SHLIB --dry-run closure.cpp
> >>>
> >>> make cmd is
> >>>
> >>>   make -f 'Makevars' -f
> '/Library/Frameworks/R.framework/Resources/etc/Makeconf' -f
> '/Library/Frameworks/R.framework/Resources/share/make/shlib.mk'
> SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)'
> SHLIB='closure.so' OBJECTS='closure.o'
> >>>
> >>>
> >>> make would use
> >>>
> >>> if test  "zclosure.o" != "z"; then \
> >>>
> >>>   echo clang++ -arch x86_64 -std=gnu++17 -dynamiclib
> -Wl,-headerpad_max_install_names -undefined dynamic_lookup
> -L"/Library/Frameworks/R.framework/Resources/lib" -L/opt/R/x86_64/lib -o
> closure.so closure.o    -F/Library/Frameworks/R.framework/.. -framework R
> -Wl,-framework -Wl,CoreFoundation; \
> >>>
> >>>   clang++ -arch x86_64 -std=gnu++17 -dynamiclib
> -Wl,-headerpad_max_install_names -undefined dynamic_lookup
> -L"/Library/Frameworks/R.framework/Resources/lib" -L/opt/R/x86_64/lib -o
> closure.so closure.o    -F/Library/Frameworks/R.framework/.. -framework R
> -Wl,-framework -Wl,CoreFoundation; \
> >>>
> >>> fi
> >>>
> >>>
> >>>
> >>>
> >>> On Wed, May 21, 2025 at 2:22 PM Kevin Ushey <kevinus...@gmail.com>
> wrote:
> >>>>
> >>>> Peiyuan,
> >>>>
> >>>> Respectfully -- RTFM.
> >>>>
> >>>> https://cran.r-project.org/doc/manuals/R-exts.html#Using-Makevars
> >>>>
> https://cran.r-project.org/doc/manuals/R-admin.html#Customizing-package-compilation
> >>>>
> >>>> The compilation flags are coming either from your R installation's
> >>>> etc/Makeconf, etc/Makevars.site, a user Makevars, or the package's
> >>>> Makevars.
> >>>>
> >>>> You can also use R CMD SHLIB --dry-run to figure out what `make`
> >>>> invocation R is using, so you can know where these compiler flags are
> >>>> coming from. For example:
> >>>>
> >>>> $ R CMD SHLIB --dry-run example.cpp
> >>>> make cmd is
> >>>>   make -f 'Makevars' -f
> >>>> '/Library/Frameworks/R.framework/Resources/etc/Makeconf' -f
> >>>> '/Library/Frameworks/R.framework/Resources/share/make/shlib.mk' -f
> >>>> '/Users/kevin/.R/Makevars' SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)'
> >>>> SHLIB_LD='$(SHLIB_CXXLD)' SHLIB='example.so' OBJECTS='example.o'
> >>>>
> >>>> Kevin
> >>>>
> >>>> On Wed, May 21, 2025 at 2:12 PM Dirk Eddelbuettel <e...@debian.org>
> wrote:
> >>>> >
> >>>> >
> >>>> > On 21 May 2025 at 13:55, Peiyuan Zhu wrote:
> >>>> > | Thanks Kasper, but I don’t know how exactly to accomplish this.
> As Dirk says
> >>>> > | the system overwrites it every time.
> >>>> >
> >>>> > That is *not* what Dirk said.
> >>>> >
> >>>> > Dirk
> >>>> >
> >>>> > --
> >>>> > dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
> >>>> >
> >>>> > ______________________________________________
> >>>> > R-package-devel@r-project.org mailing list
> >>>> > https://stat.ethz.ch/mailman/listinfo/r-package-devel
>

        [[alternative HTML version deleted]]

______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to