R-package installation from GitHub: changes when R package is in a subdir and C++ code in root - c++

Installation of my R package from GitHub fails when using the devtools::install_github function, while the package is in a subdirectory and the C++ code is located at root.
The repository can be found here: https://github.com/Blunde1/gbtorch
The master branch has the C++ code located in the R package folder. However, as I want to build a Python package later, it makes sense to move the C++ header files to the root. I modified this in a new branch: https://github.com/Blunde1/gbtorch/tree/Restructuring-Header-Files
Locally, this works after modifying the Makevars files with
PKG_CPPFLAGS = -I../inst/include
being changed to
PKG_CPPFLAGS = -I../../inst/include
I therefore assume a clone and manual installation should work, but I want this to be easy and hope that installation using devtools::install_github will be possible.
I am most likely ignorant of something, as this is not a new problem. I researched (read "googled") and found that the devtools team indeed has thought of this: https://github.com/r-lib/devtools/issues/64 which led to the subdir argument in devtools::install_github.
Here it seems the issue is solved, but still, the solution with subdir does not work for me:
This works: master branch, C++ located in R-package folder
devtools::install_github("Blunde1/gbtorch", ref="master", subdir = "R-package")
This fails: new development branch, C++ code not located at R-package folder
devtools::install_github("Blunde1/gbtorch", ref="Restructuring-Header-Files", subdir = "R-package")
The above command gives the following error:
gbtorch.cpp:8:23: fatal error: gbtorch.hpp: No such file or directory
#include "gbtorch.hpp"
If the header files' location path is not set in the Makevars file, then where? Is it possible that some configure file might do the trick?
Any ideas on how to fix this? Any help on the subject is greatly appreciated!

Related

Applying patch to a package outside of buildroot directory

I am trying to apply a patch to a package that is not located within buildroot/package but elsewhere.
I have added to my buildroot .config the following
BR2_GLOBAL_PATCH_DIR="absolute/path/to/folder"
The folder is correct because if the path wasn't correct, buildroot would error out. So the path to the directory is good.
Using the instructions here and here. I've added a subdirectory with the name that matches the package and adding the patch to that subdirectory but nothing happens.
Buildroot never outputs it's trying to apply patches which leads me to believe buildroot isn't even looking in the BR2_GLOBAL_PATCH_DIR or calling the apply-patches.sh in buildroot/support/scripts/.
Why isn't buildroot trying to apply the patch to my package?
Buildroot applies patches only to packages with downloaded source code. In other words, it doesn't apply patches to packages that are taken locally with FOO_SITE_METHOD = local or with FOO_OVERRIDE_SRCDIR = /path/to/foo.
If you see output like this:
>>> foo custom Syncing from source dir /path/to/foo
you are in this situation.
-EDIT-
Applying patches in this case is not supported by Buildroot. However, you can work around it with something like this:
define FOO_APPLY_PATCHES
$(APPLY_PATCHES) $(#D) $(addsuffix /$(RAWNAME),$(call qstrip,$(BR2_GLOBAL_PATCH_DIR))) \*.patch
endef
FOO_POST_RSYNC_HOOKS += FOO_APPLY_PATCHES

"unsupported/Eigen/CXX11/Tensor: No such file or directory" while working with TensorFlow

I'm trying to use tensorflow as a external library in my C++ application (mainly following this tutorial). What I done so far:
I have cloned the tensorflow reporitory (let's say, that the repo root dir is $TENSORFLOW)
Run /.configure (which all settings default, so no CUDA, no OpenCL etc.).
Build shared library with bazel build -c /opt //tensorflow:libtensorflow_cc.so (build completed successfully)
Now I'm trying to #include "tensorflow/core/public/session.h". But after including it (and adding $TENSORFLOW and $TENSORFLOW/bazel-genfiles to include path), I'm receiving error:
$TENSORFLOW/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1:42:
fatal error: unsupported/Eigen/CXX11/Tensor: No such file or directory
There is a github issue created for similar problem, but it's marked as closed without any solution provided. Also I tried with master branch as well as v.1.4.0 release.
Do you happen to know, what could cause this kind of problem and how to deal with it?
I (and many others) agonized over the same problem. It probably can be solved using bazel but I don't know that tool well enough and now I solve this using make. The source of confusion is that a file named Tensor is included and it itself includes a file named Tensor, which has caused some people to wrongly conclude Tensor is including itself.
If you built and installed the python .whl file there will be a tensorflow directory in dist-packages and an include directory below that, e.g. on my system:
/usr/local/lib/python2.7/dist-packages/tensorflow/include
From the include directory
find . -type f -name 'Tensor' -print
./third_party/eigen3/unsupported/Eigen/CXX11/Tensor
./external/eigen_archive/unsupported/Eigen/CXX11/Tensor
The first one has
#include "unsupported/Eigen/CXX11/Tensor"
and the file that should satisfy this is the second one.
So to compile session.cc that includes session.h, the following will work
INC_TENS1=/usr/local/lib/python2.7/dist-packages/tensorflow/include/
INC_TENS2=${INC_TENS1}external/eigen_archive/
gcc -c -std=c++11 -I $INC_TENS1 -I $INC_TENS2 session.cc
I've seen claims that you must build apps from the tensorflow tree and you must use bazel. However, I believe all the header files you need are in dist-packages/tensorflow/include and at least for starters you can construct makefile or cmake projects.
Slightly off-topic, but I had the same error with a C++ project using opencv-4.5.5 and compiled with Visual Studio (no problem with opencv-4.3.0, and no problem with MinGW).
To make it work, I had to add to my root CMakeLists.txt:
add_definitions(-DOPENCV_DISABLE_EIGEN_TENSOR_SUPPORT)
If that can help someone...
the problem was actually in the relative path of the header file taken in the Tensor file.
installed path for Tensor is /usr/include/eigen3/unsupported/Eigen/CXX11/Tensor
but mentioned in the Tensor file is "unsupported/Eigen/CXX11/Tensor"
So there should be an entry upto /usr/include/eigen3/ in the project path to run this correctly so that it can be used.

MiXiM include error

I created a project, which includes MiXiM.
The problem is that when I build the project I get this error:
/MiXiM/src/base/connectionManager/ConnectionManagerAccess.h:40:26: fatal error: BaseMobility.h: No such file or directory
I don't understand. The problem seems related to the MiXiM library but if I close my project, I can successfully compile every MiXiM example.
Is it a bug or am I doing smomething wrong?
You are probably trying to build MiXiM with a recent version of OMNeT++ (5.0 or later?). Since 5.0 OMNeT++ does NOT add all directories in the source tree as an include dir one by one. Only the root of the source folder is added. It means that ALL files that include other headers from a directory other than the current one MUST be prefixed with the path relative to the source folder root. Adding all directories to the include path was a very bad idea and was removed from OMNeT 5.
This leads to the next question: Why are you using MiXiM which is abandoned long ago and most of its functionality was merged into INET 3.x? Why not INET?
I don't know,if I can help you or not;but I had the same experience.
If you try to execute an old project in MIXIM with different version,you get this error.
For example,in MIXIM-2.2.1 there is BaseMobility;but in MIXIM-2.3 there is MobilityBase.Therefore,If your project was written in MIXIM-2.2.1,you should change it according to MIXIM-2.3.

SCons not finding "stdafx.hpp" when using nested directories

I have a C++ project, and I am transitioning from Visual Studio Solutions to SCons for builds, so Linux users can also build my code. This is my first foray into SCons, and it's working very well with simple projects. But, for this project, I have a nested directory structure:
main/
sub1/*.cpp
sub2/*.cpp
sub3/*.cpp
file1.cpp
file2.cpp
And I have the following SConstruct file:
env = Environment()
env['PCHSTOP'] = 'stdafx.hpp'
env['PCH'] = env.PCH('stdafx.cpp')[0]
env.Program('program', [
'file1.cpp',
'file2.cpp',
'sub1/file1.cpp',
'sub2/file1.cpp',
'sub3/file1.cpp'
])
Running scons from the command line causes the following error:
fatal error C1083: Cannot open include file: 'stdafx.hpp': No such file or directory
Obviously, this is an MSVC error. But this should be solvable with Scons, I'm just not sure how..
I Noticed that Visual Studio will copy all the *.obj files to a build directory before linking by default. I think this may be part of the solution, but again, I'm unsure.
What I AM sure of, is this is not the first time someone has come across this problem, but Google didn't turn up anything for me.
PS: Unlike in the example, none of the files have naming conflicts, and could theoretically be moved to a flattened folder structure by SCons without issue.
This looks like you'll have to specify the proper include paths in your Environment via the "CPPPATH" variable...but it's difficult to tell without seeing the full command line. Remember, that all SCons envs are clean initially. So, if you're in the wrong working directory, a simple "#include " doesn't find the header if it's in a different folder.
Have a look at SCons' UserGuide, chap. 14 "Hierarchical Builds", which might give you a few more ideas and insights, or come over to the User mailing list at scons-users#scons.org.

Ns3 adding a new module-- gcc not finding included headers

I am trying to add a new custom module to NS3Network Simulator 3 and I am having trouble making the header files of the module visible to the compiler.
Here is what I did:
1.I followed thisguide to add a new noc module using the createModule script.
2.I went on and copied my module files into the new created noc directory and made waf(the build system ns3 uses) aware of my new files through editing the wscript file.
3.It is my understanding that with all this set up(I probably wrong) that with this set up,running the waf commands to rebuild ns3 should rebuild ns3 with my new module.
To build I give the following commands:
./waf clean
./waf configure --enable examples
./waf build
The system goes on and builds ns3 and when it gets to my noc module it throws errors about objects of a Scalar Class not being defined in the scope.This usually means that I haven't included the header files but I have tried to copy them with other module files and included them with statements like #include "nstime.h" .With this the problem persisted. I tried copying the header with the definition of my class in the /usr/include directory and inlcuded it with #include and the problem is still there.
I realize this is a long post ,I am sorry but I would really appreciate it if somebody helped point out what I am missing.Thank you for your time.
You should also make sure in your wscript file that you add the dependencies of your module to other ns-3 modules as explained here.