Errors using stringstream with ESP8266 (Arduino IDE) [duplicate] - c++

This question already has an answer here:
Linking error using Arduino library with c++'s stringstream
(1 answer)
Closed 4 years ago.
I'm using an ESP8266 with the Arduino IDE to work on a microcontroller project. However I also want to use it as an opportunity to learn more about C++. I'm trying to deserialize a string like "key1:value1;key2:value2;..." into a map of strings, and I came across this question which seemed relevant: Parsing a comma-delimited std::string
So I put it into a function like
void SimpleKeyPairs::deserializeKeyPairs(std::string input, std::map<std::string, std::string>* output)
{
std::stringstream ss(input);
std::string key;
std::string value;
while(ss.good()) {
std::getline(ss, key, ':');
std::getline(ss, value, ';');
output->insert(std::make_pair(key, value));
}
}
However I'm getting compiler errors (copied from IDE) and unfortunately I can't figure out what I need to fix. I did isolate the problem to the line std::stringstream ss(input); but I'm not sure what the issue is.
Arduino: 1.6.13 (Mac OS X), Board: "Adafruit HUZZAH ESP8266, 80 MHz, 4M (3M SPIFFS), v2 Prebuilt (MSS=536), Disabled, None, 921600"
/Users/jake/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/tools/sdk/lib/libstdc++.a(locale-inst.o):(.literal._ZSt9use_facetISt5ctypeIcEERKT_RKSt6locale[std::ctype<char> const& std::use_facet<std::ctype<char> >(std::locale const&)]+0x4): undefined reference to `std::__throw_bad_cast()'
/Users/jake/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/tools/sdk/lib/libstdc++.a(locale-inst.o): In function `std::ctype<char> const& std::use_facet<std::ctype<char> >(std::locale const&)':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:114: undefined reference to `std::__throw_bad_cast()'
/Users/jake/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/tools/sdk/lib/libstdc++.a(locale-inst.o): In function `std::numpunct<char> const& std::use_facet<std::numpunct<char> >(std::locale const&)':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:114: undefined reference to `std::__throw_bad_cast()'
/Users/jake/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/tools/sdk/lib/libstdc++.a(locale-inst.o): In function `std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > > const& std::use_facet<std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > > >(std::locale const&)':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:114: undefined reference to `std::__throw_bad_cast()'
/Users/jake/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/tools/sdk/lib/libstdc++.a(locale-inst.o): In function `std::num_get<char, std::istreambuf_iterator<char, std::char_traits<char> > > const& std::use_facet<std::num_get<char, std::istreambuf_iterator<char, std::char_traits<char> > > >(std::locale const&)':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:114: undefined reference to `std::__throw_bad_cast()'
/Users/jake/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/tools/sdk/lib/libstdc++.a(locale-inst.o):/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/locale_classes.tcc:114: more undefined references to `std::__throw_bad_cast()' follow
/Users/jake/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/tools/sdk/lib/libstdc++.a(c++locale.o):(.literal._ZNSt6locale5facet18_S_create_c_localeERPiPKcS1_+0x4): undefined reference to `std::__throw_runtime_error(char const*)'
/Users/jake/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/tools/sdk/lib/libstdc++.a(c++locale.o): In function `std::locale::facet::_S_create_c_locale(int*&, char const*, int*)':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/src/c++98/c++locale.cc:207: undefined reference to `std::__throw_runtime_error(char const*)'
/Users/jake/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/tools/sdk/lib/libstdc++.a(ios-inst.o):(.literal._ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate[std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)]+0x4): undefined reference to `std::__throw_ios_failure(char const*)'
/Users/jake/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/tools/sdk/lib/libstdc++.a(ios-inst.o): In function `std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/bits/basic_ios.tcc:122: undefined reference to `std::__throw_ios_failure(char const*)'
/Users/jake/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.0/tools/sdk/lib/libstdc++.a(istream-inst.o): In function `__check_facet<std::ctype<char> >':
/Users/igrokhotkov/e/ESPTools/crosstool-NG/.build/xtensa-lx106-elf/build/build-cc-gcc-final/xtensa-lx106-elf/libstdc++-v3/include/istream:95: undefined reference to `std::__throw_bad_cast()'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Adafruit HUZZAH ESP8266.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Thanks in advance!

Thanks to Zebrafish for pointing me to this question about sstream with Arduino. Apparently it is difficult to include a lot of std c++ in Arduino projects, including stringstream.
This led me to find this answer, which recommends staying away from Arduino String. I used it to revise my function to this:
#include <string>
#include <cstring>
#include <map>
void SimpleKeyPairs::deserializeKeyPairs(std::string input, std::map<std::string, std::string>* output)
{
char* inputChars = const_cast<char*>(input.c_str());
char* key;
char* value;
key = strtok(inputChars, ":");
value = strtok(NULL, ";");
while(key != NULL && value != NULL) {
output->insert(std::make_pair(key, value));
key = strtok(NULL, ":");
value = strtok(NULL, ";");
}
}

Related

jpeg_read_image’ is not a member of ‘boost::gil’

I am trying to read a jpg file with boost::gil. I started with the following code snippets but I got stuck already.
#include <iostream>
#include <vector>
#include <string>
#include <boost/gil/gil_all.hpp>
#include <boost/gil/extension/io/jpeg_dynamic_io.hpp>
void ReadAnImage( std::string fname ){
std::vector<std::vector<float> > points;
boost::gil::rgb8_image_t img;
boost::gil::jpeg_read_image( fname , img );
}
int main( void ){
ReadAnImage( "pic.jpg" );
}
When I try to compile this code with
g++ -I ~/programs/cpp/boost/include/ -std=c++11 main.cpp -o main
I get the following error
MainNew.cpp:(.text._ZN5boost3gil6detail11jpeg_reader4initEv[_ZN5boost3gil6detail11jpeg_reader4initEv]+0x1a): undefined reference to jpeg_std_error' MainNew.cpp:(.text._ZN5boost3gil6detail11jpeg_reader4initEv[_ZN5boost3gil6detail11jpeg_reader4initEv]+0x3f): undefined reference to jpeg_CreateDecompress'
MainNew.cpp:(.text._ZN5boost3gil6detail11jpeg_reader4initEv[_ZN5boost3gil6detail11jpeg_reader4initEv]+0x61): undefined reference to jpeg_stdio_src' MainNew.cpp:(.text._ZN5boost3gil6detail11jpeg_reader4initEv[_ZN5boost3gil6detail11jpeg_reader4initEv]+0x76): undefined reference to jpeg_read_header'
/tmp/ccrGnMRc.o: In function boost::gil::detail::jpeg_reader::~jpeg_reader()': MainNew.cpp:(.text._ZN5boost3gil6detail11jpeg_readerD2Ev[_ZN5boost3gil6detail11jpeg_readerD5Ev]+0x18): undefined reference to jpeg_destroy_decompress'
/tmp/ccrGnMRc.o: In function void boost::gil::detail::jpeg_reader::apply<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::ve ctor3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t>, boost::mpl::range_c<int, 0, 3> > >*> > > >(boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned cha r, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t>, boost::mpl::range_c<int, 0, 3> > >*> > > const&)': MainNew.cpp:(.text._ZN5boost3gil6detail11jpeg_reader5applyINS0_10image_viewINS0_23memory_based_2d_locatorINS0_26memory_based_step_iteratorIPNS0_5pixelIhNS0_6layoutINS_3mpl7vector3INS0_5red_tENS0_7green_tENS0_6blue_tEEENS9_7range_cIiLi0ELi 3EEEEEEEEEEEEEEEvRKT_[_ZN5boost3gil6detail11jpeg_reader5applyINS0_10image_viewINS0_23memory_based_2d_locatorINS0_26memory_based_step_iteratorIPNS0_5pixelIhNS0_6layoutINS_3mpl7vector3INS0_5red_tENS0_7green_tENS0_6blue_tEEENS9_7range_cIiLi0 ELi3EEEEEEEEEEEEEEEvRKT_]+0x2e): undefined reference to jpeg_start_decompress'
MainNew.cpp:(.text.ZN5boost3gil6detail11jpeg_reader5applyINS0_10image_viewINS0_23memory_based_2d_locatorINS0_26memory_based_step_iteratorIPNS0_5pixelIhNS0_6layoutINS_3mpl7vector3INS0_5red_tENS0_7green_tENS0_6blue_tEEENS9_7range_cIiLi0ELi
3EEEEEEEEEEEEEEEvRKT[ZN5boost3gil6detail11jpeg_reader5applyINS0_10image_viewINS0_23memory_based_2d_locatorINS0_26memory_based_step_iteratorIPNS0_5pixelIhNS0_6layoutINS_3mpl7vector3INS0_5red_tENS0_7green_tENS0_6blue_tEEENS9_7range_cIiLi0
ELi3EEEEEEEEEEEEEEEvRKT]+0x13e): undefined reference to jpeg_read_scanlines' MainNew.cpp:(.text._ZN5boost3gil6detail11jpeg_reader5applyINS0_10image_viewINS0_23memory_based_2d_locatorINS0_26memory_based_step_iteratorIPNS0_5pixelIhNS0_6layoutINS_3mpl7vector3INS0_5red_tENS0_7green_tENS0_6blue_tEEENS9_7range_cIiLi0ELi 3EEEEEEEEEEEEEEEvRKT_[_ZN5boost3gil6detail11jpeg_reader5applyINS0_10image_viewINS0_23memory_based_2d_locatorINS0_26memory_based_step_iteratorIPNS0_5pixelIhNS0_6layoutINS_3mpl7vector3INS0_5red_tENS0_7green_tENS0_6blue_tEEENS9_7range_cIiLi0 ELi3EEEEEEEEEEEEEEEvRKT_]+0x1ad): undefined reference to jpeg_finish_decompress'
collect2: error: ld returned 1 exit status
I am not quite sure what I am doing wrong. Because according to the documentation
https://www.boost.org/doc/libs/1_74_0/libs/gil/doc/html/index.html
the jpeg_read_image should be included in boost::gil. Am I maybe missing another header file??
Any hints are much appreciated.

compile c++ with clang - newbie

I found this code in a tutorial
http://www.penguinprogrammer.co.uk/c-beginners-tutorial/introduction/
// This line is necessary to be able to output information to the screen
#include <iostream>
// The program starts here and carries on line by line
int main(){
// Create two integers a and b containing 10 and 5
int a = 10;
int b = 5;
/* Add them together and store the result in another
integer called sum */
int sum = a + b;
// Output the sum to the screen
std::cout << sum << std::endl;
// End the program and send a value of 0 (success) back
// to the operating system
return 0;
}
I want to compile it
Have installed clang by doing
apt-get install clang
Compiling by doing
clang -x c++ tutorial.cpp
error
/tmp/tutorial-aa5f7a.o: In function `main':
tutorial.cpp:(.text+0xa): undefined reference to `std::cout'
tutorial.cpp:(.text+0x34): undefined reference to `std::ostream::operator<<(int)'
tutorial.cpp:(.text+0x3a): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
tutorial.cpp:(.text+0x46): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/tmp/tutorial-aa5f7a.o: In function `__cxx_global_var_init':
tutorial.cpp:(.text.startup+0x13): undefined reference to `std::ios_base::Init::Init()'
tutorial.cpp:(.text.startup+0x19): undefined reference to `std::ios_base::Init::~Init()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Use clang++ tutorial.cpp - the -x c++ is useful if you only want to compile the source file, using -c, but if you are also linking the application into an executable, you want clang to know that you are linking a C++ application, and add the c++ libraries to the link command (if you want to see what clang actually does, add the -v option.

Linking issue in g++

I am writing code using C++ boost library, I am getting a linking error -
Code
#include "test/support/checkers/log-entry-presence-checkers.h"
#include <sstream>
#include <iostream>
#include <fstream>
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
using namespace std;
namespace YumaTest
{
LogEntryPresenceChecker::LogEntryPresenceChecker(
const vector<string>& expPresentText )
: checkStrings_( expPresentText )
{
}
LogEntryPresenceChecker::~LogEntryPresenceChecker()
{
}
void LogEntryPresenceChecker::operator()( const string& logFilePath ) const
{
ifstream logFile;
string line;
bool entryFound;
BOOST_FOREACH ( const string& val, checkStrings_ )
{
entryFound = false;
BOOST_TEST_MESSAGE( "\tChecking " << val << " is present" );
logFile.open( logFilePath );
if (logFile.is_open()) {
while ( logFile.good() && entryFound == false ) {
getline(logFile, line);
if ( line.find( val ) != string::npos ) {
entryFound = true;
}
}
logFile.close();
}
BOOST_CHECK_EQUAL( true, entryFound );
}
}
Linking Error -
g++ output/b64.o output/bobhash.o output/cap.o output/cfg.o output/cli.o output/conf.o output/def_reg.o output/dlq.o output/ext.o output/grp.o output/help.o output/json_wr.o output/log.o output/ncx_appinfo.o output/ncx.o output/ncx_feature.o output/ncx_list.o output/ncxmod.o output/ncx_num.o output/ncx_str.o output/obj.o output/obj_help.o output/op.o output/plock.o output/plock_cb.o output/rpc.o output/rpc_err.o output/runstack.o output/ses.o output/ses_msg.o output/status.o output/tk.o output/top.o output/tstamp.o output/typ.o output/val.o output/val_util.o output/var.o output/xml_msg.o output/xmlns.o output/xml_util.o output/xml_val.o output/xml_wr.o output/xpath1.o output/xpath.o output/xpath_wr.o output/xpath_yang.o output/yang.o output/yang_ext.o output/yang_grp.o output/yang_obj.o output/yang_parse.o output/yang_typ.o output/yin.o output/yinyang.o output/send_buff.o output/agt_acm.o output/agt.o output/agt_cap.o output/agt_cb.o output/agt_cfg.o output/agt_cli.o output/agt_commit_complete.o output/agt_connect.o output/agt_hello.o output/agt_if.o output/agt_ncx.o output/agt_not.o output/agt_plock.o output/agt_proc.o output/agt_rpc.o output/agt_rpcerr.o output/agt_ses.o output/agt_signal.o output/agt_state.o output/agt_sys.o output/agt_time_filter.o output/agt_timer.o output/agt_top.o output/agt_tree.o output/agt_util.o output/agt_val.o output/agt_val_parse.o output/agt_xml.o output/agt_xpath.o output/agt_yuma_arp.o output/agt_ncxserver.o output/checker-group.o output/string-presence-checkers.o output/log-entry-presence-checkers.o output/sil-callback-log.o output/callback-checker.o output/sil-callback-controller.o output/device-test-db.o output/device-test-db-debug.o output/state-data-test-db.o output/abstract-nc-session.o output/nc-base-query-test-engine.o output/nc-default-operation-config.o output/nc-query-test-engine.o output/nc-query-utils.o output/nc-strings.o output/yuma-op-policies.o output/abstract-global-fixture.o output/test-context.o output/base-suite-fixture.o output/query-suite-fixture.o output/simple-container-module-fixture.o output/simple-yang-fixture.o output/device-module-fixture.o output/device-get-module-fixture.o output/device-module-common-fixture.o output/state-get-module-fixture.o output/state-data-module-common-fixture.o output/cpp-unit-op-formatter.o output/log-utils.o output/ptree-utils.o output/base64.o output/NCMessageBuilder.o output/xpo-query-builder.o output/state-data-query-builder.o output/spoof-nc-session.o output/spoof-nc-session-factory.o output/running-cb-checker.o output/candidate-cb-checker.o output/integ-cb-checker-factory.o output/integ-fixture-helper.o output/integ-fixture-helper-factory.o output/simple-edit-tests.o output/default-none-tests.o output/simple-edit-running.o -Wall -g -lxml2 -lboost_unit_test_framework -Wl,--export-dynamic -o test-simple-edit-running
output/log-entry-presence-checkers.o: In function `YumaTest::LogEntryPresenceChecker::operator()(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const':
/home/abhishek/NETCONF_8_3_0/code/opensource/openyuma/netconf/test/integ-tests/../../test/support/checkers/log-entry-presence-checkers.cpp:52: undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::open(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
output/log-entry-presence-checkers.o: In function `YumaTest::LogEntryNonPresenceChecker::operator()(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const':
/home/abhishek/NETCONF_8_3_0/code/opensource/openyuma/netconf/test/integ-tests/../../test/support/checkers/log-entry-presence-checkers.cpp:89: undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::open(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
output/abstract-nc-session.o: In function `YumaTest::AbstractNCSession::concatenateLogFiles()':
/home/abhishek/NETCONF_8_3_0/code/opensource/openyuma/netconf/test/integ-tests/../../test/support/nc-session/abstract-nc-session.cpp:66: undefined reference to `std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
output/abstract-nc-session.o: In function `YumaTest::AbstractNCSession::appendLog(std::basic_ofstream<char, std::char_traits<char> >&, unsigned short)':
/home/abhishek/NETCONF_8_3_0/code/opensource/openyuma/netconf/test/integ-tests/../../test/support/nc-session/abstract-nc-session.cpp:84: undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)'
collect2: ld returned 1 exit status
I am not getting why there is a error of undefined reference.
Please help me out How can I get rid of this issue.
Thanks in Advance.
Did you copy/paste the object files or library files from somewhere? They must be built against the same binary interface.
This looks very much like you're using C++11 headers but a C++03 runtime, because your compiled code expects to find ifstream constructor overloads taking std::string (introduced in C++11), but the linker can find no evidence of implementation for such overloads.
Rebuild everything, including your Boost library, with the same toolchain and see what happens.

Issue linking libxml++ and glib libraries with CodeBlocks IDE for C++ Windows

I am writing a C++ app for Windows using Code Blocks IDE. I am interested in using the following XML++ library: http://libxmlplusplus.sourceforge.net/
It requires libxml2 and glibmm-2.4 libraries. I downloaded the source for each of these libraries and included all of the headers into my project by right clicking on "Build Options" ==> "Search Directories" tab ==> "Compiler" tab. I specified the header include files there. I modified the main.cpp file using the source code from "examples/dom_parser" from the xml++/examples directory.
Now, I am having trouble with the following error message. I have never "linked" or used *.lib, *.dll files before... but I am now getting the following "undefined reference" error messages. Please let me know what I'd need to do in order to build this. Is there a particular file that I need to "link" and if so, where are these files located? I can't seem to find them in the source files that I extracted. Could you help with specific instructions on which files to include and which folders they might be located in? I am using the CodeBlocks IDE.
Could someone replicate the project on your Windows 64 bit PC and see if it is able to run correctly?
Thank you.
UPDATE
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:44: undefined reference to `xmlpp::ContentNode::is_white_space() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:47: undefined reference to `xmlpp::Node::get_name() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:49: undefined reference to `Glib::ustring::empty() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:53: undefined reference to `xmlpp::Node::get_namespace_prefix() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:54: undefined reference to `Glib::ustring::empty() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:55: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:57: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:57: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:57: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:69: undefined reference to `xmlpp::ContentNode::get_content() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:69: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:69: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:74: undefined reference to `xmlpp::ContentNode::get_content() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:74: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:74: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:79: undefined reference to `xmlpp::ContentNode::get_content() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:79: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:79: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:87: undefined reference to `xmlpp::Node::get_line() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:90: undefined reference to `xmlpp::Element::get_attributes() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:96: undefined reference to `xmlpp::Node::get_namespace_prefix() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:97: undefined reference to `Glib::ustring::empty() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `xmlpp::Attribute::get_value() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `xmlpp::Attribute::get_name() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:98: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `xmlpp::Attribute::get_value() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `xmlpp::Attribute::get_name() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:100: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:101: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:103: undefined reference to `Glib::ustring::ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:103: undefined reference to `Glib::ustring::ustring(char const*)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:103: undefined reference to `xmlpp::Element::get_attribute(Glib::ustring const&, Glib::ustring const&) const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:103: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:103: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:106: undefined reference to `xmlpp::Attribute::get_value() const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:106: undefined reference to `Glib::operator<<(std::ostream&, Glib::ustring const&)'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:106: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:113: undefined reference to `Glib::ustring::ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:113: undefined reference to `xmlpp::Node::get_children(Glib::ustring const&) const'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:113: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:118: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:57: undefined reference to `Glib::ustring::~ustring()'
C:/Users/blah/Desktop/workspace/xmlpp/main.cpp:69: undefined reference to `Glib::ustring::~ustring()'
**UPDATED 02/11/2014 - at 10:45am **
Hi. Thanks for your suggestion. I ended up downloading the following ( http://ftp.gnome.org/pub/gnome/binaries/win32/gtkmm/2.22/ ) the entire gtkmm-win32-devel-2.22.0-2.exe and installed it onto my Windows PC in C:\gtkmm. Then, I modified my project by including the header files, library files, and bin files. Here are the screen shots:
After building, I am now seeing 0 errors and 0 warning messages. However, it appears to CRASH. I have no idea why. It seems that the gtk installation uses libxml++ version 2.6. This is fine. I downloaded the libxml++ 2.6 from the website to see the examples that they provided. I used the following source code in my main.cc. Do you know what is the problem?
// -*- C++ -*-
/* main.cc
*
* Copyright (C) 2002 The libxml++ development team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <libxml++/libxml++.h>
#include <iostream>
void print_indentation(unsigned int indentation)
{
for(unsigned int i = 0; i < indentation; ++i)
std::cout << " ";
}
void print_node(const xmlpp::Node* node, unsigned int indentation = 0)
{
std::cout << std::endl; //Separate nodes by an empty line.
const xmlpp::ContentNode* nodeContent = dynamic_cast<const xmlpp::ContentNode*>(node);
const xmlpp::TextNode* nodeText = dynamic_cast<const xmlpp::TextNode*>(node);
const xmlpp::CommentNode* nodeComment = dynamic_cast<const xmlpp::CommentNode*>(node);
if(nodeText && nodeText->is_white_space()) //Let's ignore the indenting - you don't always want to do this.
return;
Glib::ustring nodename = node->get_name();
if(!nodeText && !nodeComment && !nodename.empty()) //Let's not say "name: text".
{
print_indentation(indentation);
std::cout << "Node name = " << node->get_name() << std::endl;
std::cout << "Node name = " << nodename << std::endl;
}
else if(nodeText) //Let's say when it's text. - e.g. let's say what that white space is.
{
print_indentation(indentation);
std::cout << "Text Node" << std::endl;
}
//Treat the various node types differently:
if(nodeText)
{
print_indentation(indentation);
std::cout << "text = \"" << nodeText->get_content() << "\"" << std::endl;
}
else if(nodeComment)
{
print_indentation(indentation);
std::cout << "comment = " << nodeComment->get_content() << std::endl;
}
else if(nodeContent)
{
print_indentation(indentation);
std::cout << "content = " << nodeContent->get_content() << std::endl;
}
else if(const xmlpp::Element* nodeElement = dynamic_cast<const xmlpp::Element*>(node))
{
//A normal Element node:
//line() works only for ElementNodes.
print_indentation(indentation);
std::cout << " line = " << node->get_line() << std::endl;
//Print attributes:
const xmlpp::Element::AttributeList& attributes = nodeElement->get_attributes();
for(xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter)
{
const xmlpp::Attribute* attribute = *iter;
print_indentation(indentation);
std::cout << " Attribute " << attribute->get_name() << " = " << attribute->get_value() << std::endl;
}
const xmlpp::Attribute* attribute = nodeElement->get_attribute("title");
if(attribute)
{
std::cout << "title found: =" << attribute->get_value() << std::endl;
}
}
if(!nodeContent)
{
//Recurse through child nodes:
xmlpp::Node::NodeList list = node->get_children();
for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
{
print_node(*iter, indentation + 2); //recursive
}
}
}
int main(int argc, char* argv[])
{
Glib::ustring filepath;
if(argc > 1 )
filepath = argv[1]; //Allow the user to specify a different XML file to parse.
else
filepath = "example.xml";
try
{
xmlpp::DomParser parser;
parser.set_validate();
parser.set_substitute_entities(); //We just want the text to be resolved/unescaped automatically.
parser.parse_file(filepath);
if(parser)
{
//Walk the tree:
const xmlpp::Node* pNode = parser.get_document()->get_root_node(); //deleted by DomParser.
print_node(pNode);
}
}
catch(const std::exception& ex)
{
std::cout << "Exception caught: " << ex.what() << std::endl;
}
return 0;
}
Are libxml2 and glibmm-2.4 built?
You can find prebuilt windows binaries for libxml2 here. I can't find prebuilt windows binaries for glibmm, so you'll either have to download the entire gtkmm installer, or build it yourself.
After this process is done, you should have files such as
libxml2.lib
libxml2.a
libxml2.dll
Depending on you compiler (GCC or MSVC), and the desired linking method (static or dynamic), you should choose the required library files.
In Code::Blocks you do the linking via the "Linker settings" tab, accessible through Project -> Build options... -> Linker settings. Click add and select the previously compiled
library files (libxml2, glibmm-2.4 and libxml++) using the folder browser.
Update: I am able to successfully run the project on my Windows 8 64-bit PC.
I have a MinGW-64 installation from MinGW-builds (GCC 4.8.1). The only other thing I had to download was the gtkmm-win64 installer. I chose the "full installation".
The search directories in the project build settings were:
C:\gtkmm64\include
C:\gtkmm64\include\libxml++-2.6
C:\gtkmm64\include\glibmm-2.4
C:\gtkmm64\include\glib-2.0
C:\gtkmm64\lib\glibmm-2.4\include
C:\gtkmm64\lib\glib-2.0\include
C:\gtkmm64\lib\libxml++-2.6\include
The import libraries to link to were:
C:\gtkmm64\lib\libxml++-2.6.dll.a
C:\gtkmm64\lib\libglibmm-2.4.dll.a
C:\gtkmm64\lib\libglibmm_generate_extra_defs-2.4.dll.a
And the DLL's copied to the executable's location from the gtkmm64\bin folder were:
libglib-2.0-0.dll
libglibmm-2.4-1.dll
libglibmm_generate_extra_defs-2.4-1.dll
libxml++-2.6-2.dll
libxml2-2.dll
The executable ran successfully (excluding the fact that the program terminated due to some parsing exception).

Calling R function from C++ on Windows

I am trying to call R functions from C++ on Windows. I am using MinGW for compiling the program, but it throws error while compiling. Code (taken from Dirk) and compilation error are as follows:
#include <iostream>
using namespace std;
#include "RInside.h" // for the embedded R via RInside
Rcpp::NumericMatrix createMatrix(const int n) {
Rcpp::NumericMatrix M(n,n);
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
M(i,j) = i*10+j;
}
}
return(M);
}
int main(int argc, char *argv[]) {
const int mdim = 4; // let the matrices be 4 by 4
SEXP ans;
RInside R(argc, argv); // create an embedded R instance
Rcpp::NumericMatrix M = createMatrix(mdim); // create and fill a sample data Matrix
R["M"] = M; // assign C++ matrix M to R's 'M' var
std::string evalstr = "\
cat('Running ls()\n'); print(ls()); \
cat('Showing M\n'); print(M); \
cat('Showing colSums()\n'); Z <- colSums(M); print(Z); \
Z"; // returns Z
ans = R.parseEval(evalstr); // eval the init string -- Z is now in ans
Rcpp::NumericVector v(ans); // convert SEXP ans to a vector of doubles
for (int i=0; i< v.size(); i++) { // show the result
std::cout << "In C++ element " << i << " is " << v[i] << std::endl;
}
return 0;
}
Compile:
g++ -I "C:\ProgramFiles\R\R-2.14.0\library\RInside\include" -I "C:\Progra
mFiles\R\R-2.14.0\library\Rcpp\include" -I "C:\ProgramFiles\R\R-2.14.0\include"
RFunctions.cpp -o sh1.exe
Error:
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text+0x19a): und
efined reference to `RInside::RInside(int, char const* const*, bool)'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text+0x1ee): und
efined reference to `RInside::operator[](std::string const&)'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text+0x26d): und
efined reference to `RInside::parseEval(std::string const&)'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text+0x35b): und
efined reference to `RInside::~RInside()'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text+0x3e1): und
efined reference to `RInside::~RInside()'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp7RO
bjectC2Ev[Rcpp::RObject::RObject()]+0x8): undefined reference to `vtable for Rcp
p::RObject'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp7RO
bjectC2Ev[Rcpp::RObject::RObject()]+0xd): undefined reference to `_imp__R_NilVal
ue'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN7RInside
5ProxyD1Ev[RInside::Proxy::~Proxy()]+0xd): undefined reference to `Rcpp::RObject
::~RObject()'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EED2Ev[Rcpp::Vector<14>::~Vector()]+0x16): undefined reference to `Rcpp
::RObject::~RObject()'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EED1Ev[Rcpp::Vector<14>::~Vector()]+0x16): undefined reference to `Rcpp
::RObject::~RObject()'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EEC1EP7SEXPREC[Rcpp::Vector<14>::Vector(SEXPREC*)]+0x57): undefined ref
erence to `Rcpp::RObject::setSEXP(SEXPREC*)'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EEC1EP7SEXPREC[Rcpp::Vector<14>::Vector(SEXPREC*)]+0x66): undefined ref
erence to `Rcpp::RObject::~RObject()'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ma
trixILi14EEC1ERKiS3_[Rcpp::Matrix<14>::Matrix(int const&, int const&)]+0x2c): un
defined reference to `Rcpp::Dimension::Dimension(unsigned int const&, unsigned i
nt const&)'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZNK4Rcpp6V
ectorILi14EE4sizeEv[Rcpp::Vector<14>::size() const]+0x10): undefined reference t
o `Rf_length'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6r_
castILi14EEEP7SEXPRECS2_[SEXPREC* Rcpp::r_cast<14>(SEXPREC*)]+0xd): undefined re
ference to `TYPEOF'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6r_
castILi14EEEP7SEXPRECS2_[SEXPREC* Rcpp::r_cast<14>(SEXPREC*)]+0x1d): undefined r
eference to `SEXPREC* Rcpp::internal::r_true_cast<14>(SEXPREC*)'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EEC2ERKNS_9DimensionE[Rcpp::Vector<14>::Vector(Rcpp::Dimension const&)]
+0x46): undefined reference to `Rcpp::Dimension::prod() const'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EEC2ERKNS_9DimensionE[Rcpp::Vector<14>::Vector(Rcpp::Dimension const&)]
+0x56): undefined reference to `Rf_allocVector'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EEC2ERKNS_9DimensionE[Rcpp::Vector<14>::Vector(Rcpp::Dimension const&)]
+0x67): undefined reference to `Rcpp::RObject::setSEXP(SEXPREC*)'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EEC2ERKNS_9DimensionE[Rcpp::Vector<14>::Vector(Rcpp::Dimension const&)]
+0x7d): undefined reference to `Rcpp::Dimension::size() const'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EEC2ERKNS_9DimensionE[Rcpp::Vector<14>::Vector(Rcpp::Dimension const&)]
+0xc9): undefined reference to `Rcpp::RObject::attr(std::string const&) const'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6Ve
ctorILi14EEC2ERKNS_9DimensionE[Rcpp::Vector<14>::Vector(Rcpp::Dimension const&)]
+0x13b): undefined reference to `Rcpp::RObject::~RObject()'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZNK4Rcpp11
Environment6assignINS_6MatrixILi14EEEEEbRKSsRKT_[bool Rcpp::Environment::assign<
Rcpp::Matrix<14> >(std::basic_string<char, std::char_traits<char>, std::allocato
r<char> > const&, Rcpp::Matrix<14> const&) const]+0x23): undefined reference to
`Rcpp::Environment::assign(std::string const&, SEXPREC*) const'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp7RO
bject14AttributeProxyaSINS_9DimensionEEERS1_RKT_[Rcpp::RObject::AttributeProxy&
Rcpp::RObject::AttributeProxy::operator=<Rcpp::Dimension>(Rcpp::Dimension const&
)]+0x1c): undefined reference to `Rcpp::RObject::AttributeProxy::set(SEXPREC*) c
onst'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp8in
ternal13r_init_vectorILi14EEEvP7SEXPREC[void Rcpp::internal::r_init_vector<14>(S
EXPREC*)]+0xd): undefined reference to `double* Rcpp::internal::r_vector_start<1
4, double>(SEXPREC*)'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp8in
ternal13r_init_vectorILi14EEEvP7SEXPREC[void Rcpp::internal::r_init_vector<14>(S
EXPREC*)]+0x23): undefined reference to `Rf_length'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp8in
ternal21wrap_dispatch_unknownINS_9DimensionEEEP7SEXPRECRKT_NS_6traits17integral_
constantIbLb1EEE[SEXPREC* Rcpp::internal::wrap_dispatch_unknown<Rcpp::Dimension>
(Rcpp::Dimension const&, Rcpp::traits::integral_constant<bool, true>)]+0xd): und
efined reference to `Rcpp::Dimension::operator SEXPREC*() const'
C:\Users\ksharma\AppData\Local\Temp\ccgMgFPS.o:RFunctions.cpp:(.text$_ZN4Rcpp6tr
aits14r_vector_cacheILi14EE6updateERKNS_6VectorILi14EEE[Rcpp::traits::r_vector_c
ache<14>::update(Rcpp::Vector<14> const&)]+0x15): undefined reference to `double
* Rcpp::internal::r_vector_start<14, double>(SEXPREC*)'
collect2: ld returned 1 exit status
Any ideas what I am missing?
Jim is correct in his earlier answer, but there is more.
When using RInside , you also need to
include and link with Rcpp (which RInside depends upon) a
include and link with R (which both depends upon) as well as of course
RInside's own library
The easiest way of doing this is to simply use the Makefile from the examples/standard directory --- given that you copied the code of one of the examples, you should also copy the build instructions.
Lastly, and that is your biggest issue: RInside applications do not currently work on Windows, which is clearly documented on the RInside page. It will build, but segfault on startup. Debugging help would be appreciated, this works on OS X and Linux.
You're not actually linking in the R library (whatever that is).