I need to build object files from C++ sources, then link them against the Boost Regex library to mimic the compilation of a package using Rcpp. I observe the same problem in the compilation of a small test case and of the complete package, hence the two versions of the problem provided here, for people unfamiliar with Rcpp.
Small test case
I am using Gcc 4.6.3 on Windows, as provided by Rtools. The source file for the test is very basic: I include regex.hpp, then I use boost::regex, boost::regex_match, boost::regex_search and boost::smatch. The problem is that if I compile my code using:
g++ -O0 -pipe -g -Wall -I"xxx\boost_1_56_0" "src/01 - regex.cpp" -o Debug/regex.o
g++ -O0 -pipe -g -Wall Debug/regex.o "xxx\libboost_regex-gcc-1_56.a" -o Debug/reg.exe
I get this kind of error message at the first command:
undefined reference to `boost::re_detail::cpp_regex_traits_char_layer<char>::init()
But if I use a single command to build everything:
g++ -O0 -pipe -g -Wall -I"xxx\boost_1_56_0" "src/01 - regex.cpp" "xxx\libboost_regex-gcc-1_56.a" -o Debug/reg.exe
I get no error messages. How can I compile my object files then link to Boost Regex ?
Problem with the complete Rcpp package
In the bigger context, when I compile my real Rcpp package, I am able to compile several other object files and link them later to (non Boost) libraries. Boost Regex is the first problematic library in that regard.
The complete package is built using:
R CMD INSTALL --no-multiarch --with-keep.source .
With:
STKPPLIB = ../../stkpp/lib/libSTKpp.a
RELIB = ../../boost_1_56_0/libs/regex/build/gcc/libboost_regex-gcc-1_56.a
MCLIB = ../../MixtComp/lib/libMixtComp.a
and:
PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` $(MCLIB) $(STKPPLIB) $(RELIB)
And the build process give similar "undefined references" errors. The question is the same as the previous one: how can I compile my object files then link to Boost Regex ?