I am trying to develop an R package which uses the Sundials C library for solving differential equations. In order to not have the user install the library, I am putting the source code of the library in my package.
I have put all the header files from the library in /inst/include/sundials-2.6.2 and the .c files in src/sundials-2.6.2 of my package folder.
From my reading of the SO posts on this topic, sourceCpp of code in multiple files (e.g., separate .h and .cpp files should work if they are structured to be a part of the package. I am trying to run a example code file from the Sundials package
My code (only the beginning part) looks something like
#include <Rcpp.h>
#include "../inst/include/sundials-2.6.2/cvode/cvode.h" /* prototypes for CVODE fcts., consts. */
#include "../inst/include/sundials-2.6.2/nvector/nvector_serial.h" /* serial N_Vector types, fcts., macros */
#include "../inst/include/sundials-2.6.2/cvode/cvode_dense.h" /* prototype for CVDense */
#include "../inst/include/sundials-2.6.2/sundials/sundials_dense.h" /* definitions DlsMat DENSE_ELEM */
#include "../inst/include/sundials-2.6.2/sundials/sundials_types.h" /* definition of type realtype */
But, I am getting an error
fatal error: sundials/sundials_nvector.h: No such file or directory
I do example of something similar done in the following github repositories
Rcppsundials - https://github.com/AleMorales/RcppSundials.R/blob/master/src/cvode.cpp
which calls the header files using
#include <cvodes/cvodes.h> // CVODES functions and constants
#include <nvector/nvector_serial.h> // Serial N_Vector
#include <cvodes/cvodes_dense.h> // CVDense
and has incorporated the header files under the /inst/include/ folder.
This is the first package I am trying to develop and I have not used C/C++ also extensively, so there could be something very silly in how I am trying to compile this program.
Just a side note - I was able to install and run an example on my OSX machine, but currently I am working from a Windows machine that does not have Sundials installed. It does have Rtools installed, so I can compile and run the example Rcpp programs.
Thank you
SN
External library linking should be done with the following setup:
R/
inst/
|- include/
|- sundials/
|- header.h
src/
|- sundials/
|- Makevars
|- Makevars.win
|- action.cpp
man/
DESCRIPTION
NAMESPACE
Then add the following:
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
PKG_CPPFLAGS = -I../inst/include/ -I src/sundials
To both Makevars and Makevars.win
Here I've opted to remove the sundial version numbers from the folder names.
Edit
I've made the fixes necessary to compile the package:
https://github.com/sn248/Rcppsbmod/pull/1
Note:
The structure was:
inst/
|- include/
|- sundials/
|- arkode/
.....
|- nvector/
|- sundials/
|- header.h
This would have forced the include statements to be:
#include <sundials/cvodes/cvodes.h> // CVODES functions and constants
#include <sundials/nvector/nvector_serial.h> // Serial N_Vector
#include <sundials/cvodes/cvodes_dense.h> // CVDense
I changed it so that:
inst/
|- include/
|- arkode/
.....
|- nvector/
|- sundials/
|- header.h
So, the statements will always be:
#include <cvodes/cvodes.h> // CVODES functions and constants
#include <nvector/nvector_serial.h> // Serial N_Vector
#include <cvodes/cvodes_dense.h> // CVDense
Related
A complete newbie here. I am learning to read the codes on suckless.org. They are written in C, and are most quite short, so I think it's a good start.
The problem is I know too little to start with. Wandering around on the site, I found that the suckless community has their own coreutils, which are also very short. echo.c on this page is one of the shortests. I include its header here:
/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <string.h>
#include "util.h"
I'd like to compile it and see how this version of echo works, and come back to understand the code. The goal is to repeat this process until I'm comfortable enough to read the source codes of their their larger programs like sent, dmenu, dwm.
In the code, the header #include "util.h" suggests me to put util.h, which is another file in the link above, together with echo.c. I also include arg.h and compat.h because the header of util.h says
#include <sys/types.h>
#include <regex.h>
#include <stddef.h>
#include <stdio.h>
#include "arg.h"
#include "compat.h"
I further checked arg.h and compat.h. Neither of them includes customized header files, so I think I'm good to go. Now the folder tree looks like
$ tree
.
├── arg.h
├── compat.h
├── echo.c
└── util.h
and I run $ gcc echo.c -o echo.o. However, I got an error
/usr/bin/ld: /tmp/cc2VjXNO.o: in function `main':
echo.c:(.text+0x20): undefined reference to `argv0'
/usr/bin/ld: echo.c:(.text+0x27): undefined reference to `argv0'
/usr/bin/ld: echo.c:(.text+0x8d): undefined reference to `putword'
/usr/bin/ld: echo.c:(.text+0xc8): undefined reference to `fshut'
collect2: error: ld returned 1 exit status
Apparently, these undefined arguments are in those header files. Searching around on the net, I further tried
$ gcc -c . echo.c -o echo.o
gcc: warning: .: linker input file unused because linking not done
It spits a warning, but anyway an echo.o is delivered. I chmod it to executable, and run it by $ ./echo.o, but my shell complains
zsh: exec format error: ./echo.o
I spent another hour trying to solve this.. by try and error, but in vain. Would you please point out what's going on? And what should I do?
(Any other suggestions will also be very appreciated.)
You try to compile a program with library that you don't have. The header you're using needs a dynamic or static library (either .a or .o on linux). That's why you get linker input file unused because linking not done.
zsh: exec format error: ./echo.o if you use .o extension with -o argument, you're either making or linking a .o object file (static lib). With gcc -c . echo.c -o echo.o, you're creating a static library (called object) that you won't be able to execute.
By the way, I'd stay away for now from this kind of code, it's very not friendly user for a learner.
I tried to build simple kernel module (using source downloaded from developer.sonymobile.com) but after compiling i can't insmod it: Unknown symbol __gnu_mcount_nc so i founded a solution and I wrote another module using assembler and I exported this function. After this module insmoded correctly but I see in lsmod that all modules are permament. I have a problem with simple filesystem (Permission denied - default action when pointer is null), on PC this code works without any errors.
I guess the config is wrong in source code, (probably offset of some fields in structure is another than in device).
Version of built is: 24.0.A.5.14 (downloaded from developer.sonymobile.com site).
Can I do anything to get this same configuration as in device?
I had not /proc/config.gz so I can't get it easily.
Module source:
#include <linux/module.h>
#include <linux/kernel.h>
int __init example_init(void)
{
printk("Hello world!\n");
return 0;
}
void __exit example_exit(void)
{
printk("example module exit\n");
}
module_init(example_init);
module_exit(example_exit);
And I see Hello World! in dmesg but module is still permament.
Source of __gnu_mcount_nc i found here: http://doc.ironwoodlabs.com/arm-arm-none-eabi/html/getting-started/arm-mcount.html
Do you compile with with profile enable -pg flag when you build the kernel module? It looks that way.
The kernel module Makefile for CFLAGS.
I downloaded sample code that uses a 'header only' library and even though I have included the library path in my VC++ project, I keep getting the error:
fatal error C1083: Cannot open include file: 'websocketpp/config/asio_no_tls.hpp': No such file or directory
Library header files location:
D:\websocketpp
D:\websocketpp\config
Here are the first few lines of the example program echo_server.cpp:
#include "stdafx.h"
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>
The included files do exist in the directories above. I have specified the directories as follows:
Visual C++ Directories / Include Directories /
D:\websocketpp
C/C++ / General / Additional Include Directories
D:\websocketpp\config
Does someone know what the problem is?
It was a stupid mistake. I moved the entire directory structure into a new folder:
D:\websocket\websocket
D:\websocket\websocket\config
I have unit a.cpp that is used in several projects in subdirectory libA. Some of project are using precompiled headers, while others -not. In this case projects that use precompiled header must have line:
#include <stdafx.h>
and projects that are not using PCH must have line:
#include "..\stdafx.h"
Wise verse is not working.
Why project sees stdafx.h file in different way when project uses PCH or not?
UPD.
When I replace line #include <stdafx.h> with #include "..\stdafx.h" in project that uses precompiled header i have error
Error 19 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
Directory structure is the same in both projects.
There is no (or there should not be any) difference between <stdafx.h> and "stdafx.h". The only significant difference is that one project "sees" the file in current folder, and the other project sees it in parent folder. This difference is controlled by compiler option Additional Include Directories. One project has libA in it, and the other does not have it.
I am using Visual Studio 10 to program in C++
The 1st part of my program is
//Includes
//#include <LEDA\numbers> //fatal error C1083: Cannot open include file: 'LEDA\numbers': No such file or directory
#include <LEDA/numbers/real.h>
//Why do I get a linker error here
//All.obj : error LNK2001: unresolved external symbol "class leda::memory_manager leda::std_memory_mgr" (?std_memory_mgr#leda##3Vmemory_manager#1#A)
#include <LEDA\numbers\integer.h> //Here I used the system to write most of it for me
#include <LEDA/numbers/integer.h> //Include LEDA. So 2 things
//1. including the same file twice does not matter
//2. forward slashes and backward slashes are the same
//I tried to use a wild card and said #include <LEDA/numbers/*>
//But that did not work
#include <LEDA/numbers/rational.h>
#include <LEDA/core/string.h>
#include <LEDA/core/array.h>
#include <LEDA/numbers/bigfloat.h>
//The sqrt does not work
#include <iostream> //include ordinary C++
#include <math.h>
and I have a LINKER error
I have tried specifying which libraries to use by specifying the LIB User Environment symbol
I have tried specifying which libraries to use by specifying the
Include Directories and
Library Directories
in the properties of my Project
I have made a mistake somewhere, BUT where is it
There are several mistakes in this program:
LEDA\numbers is apparently a directory, not an include file. So you shouldn't try to include it.
(conceptual) #include statements don't help in resolving linker errors at all. Instead, you need to specify the libraries you want to link with to the linker; libraries are files that end in .lib. Go to the project settings, and add the libraries containing the missing symbols.
#include <abcd.h> // looks for the include abcd.h in the INCLUDES path.
#include "abcd.h" // looks for the include abcd.h in the current path and then INCLUDES path.
From your description it looks like your LEDA lib in under your current directory. Try using "" instead of <> and see if it fixes your errors.