I am trying to modify an R package that works with C and Fortran code, so in order to test my modifications im trying to compile this C code in R. I have never worked before with C so I am following the steps described at this website: http://mcglinn.web.unc.edu/blog/linking-c-with-r-in-windows/
I have completed all the steps: Downloaded Rtools, modified the PATH, created the C file with some functions and compiled it. The .dll file has been correctly generated (seems so). But when I try to load this code into R using dyn.load I get the following error:
dyn.load("sequence_examples.dll")
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object 'C:/Users/alvaromc317/ZZ_ALVARO/sequence_examples.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
I am not sure what is going wrong. My system works with an x64 architecture, so I installed R and Rtools x64 versions.
Related
After installing gcc on my Windows PC, I tried running a simple C program but, I keep getting an error message saying
Unable to find executable for 'C\Users\Asi Polcarp\Desktop\Cprograms<executable.exe>'
This message is from VS Code.
# include <stdio.h>
void main()
{
printf("welcome");
}
first of all you need to put path of the GCC file to the folder environmental variables and try to compile it in the folder where you have actually put the path address.
In order to run C/C++ codes or most of other programming languages on VS Code I suggest the 'Code Runner' extension.
I am attempting to run an old program that uses tcl as well as legacy opengl. I managed to link the opengl libraries successfully; however, I cannot seem to get the tcl linker to work. For context, the program I am using came with include and lib folder. The lib folder contains tclstub86_32.lib, tclstub86_64.lib, and tkstub86.lib as well as opengl .libs. The include folder contains two folders: tcl_include and tk_include, which obviously contain all the .c and .h files for tcl and tk. The following pictures show my settings from using project -> build options:
The error I receive when compiling is:
C:\Users\amlut\Downloads\C\tkogl\curve.c|18|undefined reference to `_imp__Tcl_Free'|
And here is the bit of code that is throwing the error:
if (*line != NULL) Tcl_Free((char*)*line);
I am not sure what I am doing wrong here, any help is appreciated. Thank you.
The problem is that the code is apparently linking against the Tcl stub library (an ABI/API adaptor library) but isn't compiling to use that library but rather to use a full Tcl library instead. When building an extension package, using the stub library is a good thing as it means that the resulting code is not bound to an exact version of the Tcl (and Tk) library but rather to a version of the Tcl ABI which has a much longer support cycle.
The fix is to define the USE_TCL_STUBS and USE_TK_STUBS (that has the identical issue; you have just hit the Tcl version of it first) C preprocessor symbols when building; set them both to 1 and recompile. This is done under the Compiler Settings tab in Code::Blocks apparently.
I'm trying to build an R package which is calling some C subroutines via .Call.
All of the functions are working fine if I manually do R CMD SHLIB and then dyn.load the .dll files.
Now, I'm building the package with R CMD build.
I put all the C code in the src folder, together with the .h files for some libraries I'm adding. When I run R CMD build NAMEPACKAGE everything seems to be fine, but then when I run R CMD check NAMEPACKAGE I get the following errors:
*** arch - i386
Error in library.dynam(lib, package, package.lib) :
DLL 'NAMEFUNC' not found: maybe not installed for this architecture?
Error: loading failed
Execution halted
*** arch - x64
Error in library.dynam(lib, package, package.lib) :
DLL 'NAMEFUNC' not found: maybe not installed for this architecture?
Error: loading failed
Execution halted
ERROR: loading failed for 'i386', 'x64'
I was trying to get some information on the internet, I have the feeling that I should write a Makevars file, but honestly I spent a lot of time on the Writing R extensions tutorial (1.2.1) and I'm really struggling to understand what is it exactly that I need to do.
Could someone please beifly explain to me how to solve the problem? Consider I would like to submit my package to CRAN. Thanks.
I just found out what the problem was! It was (as usual) a fairly silly thing, I didn't know that even if you call a certain function with a certain name, the associated dll is automatically called with the name of the package and not of the function itself, like it happens instead when you just create your dll through R CMD SHLIB.
Therefore, in the NAMESPACE I had to add useDynLib(NAMEOFPACKAGE) instead of useDynLib(NAMEOFFUNCTION).
I compiled a C code in the Terminal on a Mac (Mountain Lion). Trying to load it using dyn.load on a Windows 7 PC, I got this message:
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object 'C:/Users/Iris/Desktop/mcmc.so':
LoadLibrary failure: %1 is not a valid Win32 application.
The Windows 7 is 64 bit, and the R on it is also 64 bit. I had no problem loading the C code on another MAC. I wonder what went wrong with my code. Thanks.
EDIT:
I tried a solution found here, but it did not work.
The Mac will compile C code to Mach-O (Mach Object) format
Mach-O - Wikipedia
This should work fine across the Mac platform. This is why it worked on another Mac.
Windows uses PE (Portable Executable) format
WinPE - Wikipedia
The formats are not compatible, that's why LoadLibrary is complaining about not being a valid Win32 application - because it is not.
Recompile the C code on Windows and it should work.
So far the only way I found is by making the shared object for a function that is written in e.g. myfile.c:
R CMD SHLIB myfile.c
and then testing in RGui using a script.
I want to code on Windows and i would like an easier way for compiling c code that uses R api calls, preferably using an IDE like Netbeans or Visual Studio. Is this possible ?
EDIT
Install Netbeans C\C++
Install R
Install RTools - contains C\C++ compiler for Netbeans
copy include files from R\R-2.12.2\include folder to RTools\MinGW\include folder
copy dll files from R\R-2.12.2\bin\i386 to Rtools\MinGW\lib
Make Netbeans project C\C++ - will require to select compiler tools from RTools\MinGW folder
copy required dll files from R\R-2.12.2\bin\i386 to execution folder of Netbeans Project
Of course it is. Just look at the output generated by R CMD SHLIB foo.c which is clearly echoed and copy these settings into your preferred IDE. It will work, and it will be less portable.
Nobody handcuffs you; but R using the same command on all platforms is actually a real feature and not a bug as you seem to suggest.