Crt Crt - 1 year ago 131
C++ Question

Current Working Directory for Header Files C++

I am compiling some code but, I am having problems with the path to custom header files.

Here is the structure of the repository.


In the hello_world.cpp file is the following:

#include <iostream>
#include <Rcpp.h>
#include "../headerFiles/SeqLibCommon.h"

This compiles and works but, in C++ packages, the path to SeqLibCommon.h would be referenced as such:

#include "headerFiles/SeqLibCommon.h"

Why are the two different?

Answer Source

An R package compilation is always relative to src/ which becomes the working directory for the build.

If you want to add that directory explicitly you can add


And if you want to add the directory inst/include/ you would have to add

PKG_CXXFLAGS = -I../inst/include

as you need to be relative to src/. You can combine both.

As for your SeqLib sources: you can move things around, or adjust your src/Makevars as needed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download