recompile with -fPIC

Hi.
I could not catch the proper way to recompile the lib in Makevars with -fPIC. Can someone help, please?

==> Rcpp::compileAttributes()

* Updated R/RcppExports.R

==> roxygen2::roxygenize('.', roclets = c('rd', 'collate', 'namespace', 'vignette'))

Loading flashlight
Re-compiling flashlight
─  installing *source* package ‘flashlight’ ...
   ** using staged installation
   ** libs
   g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/ -I'/home/turgut/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include'    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c RcppExports.cpp -o RcppExports.o
   g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/ -I'/home/turgut/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include'    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c Variable.cpp -o Variable.o
   g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/ -I'/home/turgut/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include'    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c rcpp_hello_world.cpp -o rcpp_hello_world.o
   g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o flashlight.so RcppExports.o Variable.o rcpp_hello_world.o -L/usr/local/lib -laf -lflashlight -Wl,-rpath,/usr/local/lib -L/usr/lib/R/lib -lR
   /usr/bin/ld: /usr/local/lib/libflashlight.a(Activations.cpp.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
   /usr/local/lib/libflashlight.a: error adding symbols: Bad value
   collect2: error: ld returned 1 exit status
   /usr/share/R/share/make/shlib.mk:6: recipe for target 'flashlight.so' failed
   make: *** [flashlight.so] Error 1
   ERROR: compilation failed for package ‘flashlight’
─  removing ‘/tmp/RtmpIAxlaX/devtools_install_1f7f1e7ab44e/flashlight’

Error: System command 'R' failed, exit status: 1, stdout + stderr:
E> * installing *source* package ‘flashlight’ ...
E> ** using staged installation
E> ** libs
E> g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/ -I'/home/turgut/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include'    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c RcppExports.cpp -o RcppExports.o
E> g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/ -I'/home/turgut/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include'    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c Variable.cpp -o Variable.o
E> g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/ -I'/home/turgut/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include'    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c rcpp_hello_world.cpp -o rcpp_hello_world.o
E> g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o flashlight.so RcppExports.o Variable.o rcpp_hello_world.o -L/usr/local/lib -laf -lflashlight -Wl,-rpath,/usr/local/lib -L/usr/lib/R/lib -lR
E> /usr/bin/ld: /usr/local/lib/libflashlight.a(Activations.cpp.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
E> /usr/local/lib/libflashlight.a: error adding symbols: Bad value
E> collect2: error: ld returned 1 exit status
E> /usr/share/R/share/make/shlib.mk:6: recipe for target 'flashlight.so' failed
E> make: *** [flashlight.so] Error 1
E> ERROR: compilation failed for package ‘flashlight’
E> * removing ‘/tmp/RtmpIAxlaX/devtools_install_1f7f1e7ab44e/flashlight’

 Stack trace:

 1. base:::suppressPackageStartupMessages({ ...
 2. base:::withCallingHandlers(expr, packageStartupMessage = function(c) tryInv ...
 3. roxygen2::roxygenize(".", roclets = c("rd", "collate", "namespace",  ...
 4. roxygen2:::load_code(base_path)
 5. pkgload::load_all(path, helpers = FALSE, attach_testthat = FALSE)
 6. pkgbuild::compile_dll(path, quiet = quiet)
 7. withr::with_makevars(compiler_flags(TRUE), assignment = "+=",  ...
 8. withr:::with_envvar(c(R_MAKEVARS_USER = makevars_file), { ...
 9. base:::force(code)
 10. base:::force(code)
 11. pkgbuild:::install_min(path, dest = install_dir, components = "libs",  ...
 12. pkgbuild:::rcmd_build_tools("INSTALL", c(path, paste("--library=",  ...
 13. pkgbuild:::with_build_tools(callr::rcmd_safe(..., env = env,  ...
 14. callr::rcmd_safe(..., env = env, spinner = FALSE, show = FALSE,  ...
 15. callr:::run_r(options)
 16. base:::with(options, with_envvar(env, do.call(processx::run,  ...
 17. base:::with.default(options, with_envvar(env, do.call(processx::run,  ...
 18. base:::eval(substitute(expr), data, enclos = parent.frame())
 19. base:::eval(substitute(expr), data, enclos = parent.frame())
 20. callr:::with_envvar(env, do.call(processx::run, c(list(bin, args = real_cmd ...
 21. base:::force(code)
 22. base:::do.call(processx::run, c(list(bin, args = real_cmdargs,  ...
 23. (function (command = NULL, args = character(), error_on_status = TRUE,  ...
 24. throw(new_process_error(res, call = sys.call(), echo = echo,  ...

 x System command 'R' failed, exit status: 1, stdout + stderr:
E> * installing *source* package ‘flashlight’ ...
E> ** using staged installation
E> ** libs
E> g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/ -I'/home/turgut/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include'    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c RcppExports.cpp -o RcppExports.o
E> g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/ -I'/home/turgut/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include'    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c Variable.cpp -o Variable.o
E> g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/ -I'/home/turgut/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include'    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c rcpp_hello_world.cpp -o rcpp_hello_world.o
E> g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o flashlight.so RcppExports.o Variable.o rcpp_hello_world.o -L/usr/local/lib -laf -lflashlight -Wl,-rpath,/usr/local/lib -L/usr/lib/R/lib -lR
E> /usr/bin/ld: /usr/local/lib/libflashlight.a(Activations.cpp.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
E> /usr/local/lib/libflashlight.a: error adding symbols: Bad value
E> collect2: error: ld returned 1 exit status
E> /usr/share/R/share/make/shlib.mk:6: recipe for target 'flashlight.so' failed
E> make: *** [flashlight.so] Error 1
E> ERROR: compilation failed for package ‘flashlight’
E> * removing ‘/tmp/RtmpIAxlaX/devtools_install_1f7f1e7ab44e/flashlight’ 

Execution halted

Exited with status 1.

My makevars:

CXX_STD = CXX14
PKG_CPPFLAGS =  -I../inst/include/
PKG_LIBS = -L/usr/local/lib -laf -lflashlight -Wl,-rpath,/usr/local/lib
sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] flashlight_0.1.0

loaded via a namespace (and not attached):
[1] compiler_4.0.2 tools_4.0.2    Rcpp_1.0.4.6  

I forgot to mention that I just include blank file with header "#include <flashlight/flashlight.h> which causes this error.

It seems that this post is related to my issue. https://stackoverflow.com/questions/40729027/linking-dynamic-and-static-libraries-rcpp

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.