Bug 15899 - Omitted 'extern' on 'R_running_as_main_program' after refactor can cause linker errors for applications embedding R
Summary: Omitted 'extern' on 'R_running_as_main_program' after refactor can cause link...
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R-devel (trunk)
Hardware: All All
: P5 minor
Assignee: R-core
Depends on:
Reported: 2014-07-25 21:49 UTC by Kevin Ushey
Modified: 2015-07-03 10:49 UTC (History)
5 users (show)

See Also:

Patch to add extern back to R_running_as_main_program (383 bytes, patch)
2014-07-25 21:49 UTC, Kevin Ushey
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Ushey 2014-07-25 21:49:51 UTC
Created attachment 1629 [details]
Patch to add extern back to R_running_as_main_program

R_running_as_main_program lost its extern when it was migrated from 'src/main/Rmain.c' to 'src/include/Rinterface.h'.

If this was intentional, close this; otherwise I've attached a patch to change.

Reason: applications embedding R which include Rinterface.h in multiple components will have linker errors due to duplicate symbols.

Index: Rinterface.h
--- Rinterface.h	(revision 66251)
+++ Rinterface.h	(working copy)
@@ -84,7 +84,7 @@
 void fpu_setup(Rboolean);
 /* in unix/system.c */
-int R_running_as_main_program; 
+extern int R_running_as_main_program; 
 /* duplicating Defn.h */
Comment 1 GG 2015-04-18 09:00:28 UTC
Is there a resolution for this (R 3.2, on Ubuntu Precise)
Comment 2 Enzo 2015-04-22 07:12:04 UTC
Is there a resolution for this (R 3.2, on OS X Yosemite)?
Comment 3 Martin Maechler 2015-04-22 12:16:19 UTC
Your patch seems to make sense.  It's unfortunate that we do not have
a (hopefully small) reproducible example which shows the problem and shows that the change solves that problem.

I've committed the change to R-devel (-> R 3.3 in 2016) 
and will port it to  "R 3.2 patched" later -- notably if you can confirm it solves your problem.
Comment 4 diane 2015-04-22 21:19:35 UTC
+1 for fix. 

I just helped one of my coworkers use this patch to fix a build problem using R and Rcpp and a large pile of code.

He's using Ubuntu 12.04 with r-base-core 3.2.0-1precise from http://cran.r-project.org/bin/linux/ubuntu/ precise/ 

We were having duplicate R_running_as_main_program symbols which I fixed by editing Rinterface.h and adding the extern, and recompiling the project.

His code has a bunch of object files loaded into a static library and then that was linked against a main.o, and with the broken implementation there was a conflict with every .o in static library.
Comment 5 Philipp Angerer 2015-07-03 10:49:31 UTC
from what i can see it’s in 3.2.1 (so it was backported)